Skip to content

Commit f58b51b

Browse files
committed
fix: Improve multi-column constraint name generation logic
1 parent f35a728 commit f58b51b

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

lib/ecto/adapters/libsql/connection.ex

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,16 @@ defmodule Ecto.Adapters.LibSql.Connection do
142142

143143
if String.contains?(constraint, ", ") do
144144
# Multi-column constraint: "table.col1, table.col2" -> "table_col1_col2_index"
145-
constraint
146-
|> String.split(", ")
147-
|> Enum.with_index()
148-
|> Enum.map(fn
149-
{table_col, 0} ->
150-
# First column includes table name
151-
table_col |> clean.() |> String.replace(".", "_")
152-
153-
{table_col, _} ->
154-
# Subsequent columns: only take the column name
155-
table_col
156-
|> clean.()
157-
|> String.split(".")
158-
|> List.last()
159-
|> clean.()
160-
end)
161-
|> Enum.concat(["index"])
162-
|> Enum.join("_")
145+
[first | rest] = String.split(constraint, ", ")
146+
147+
table_col = first |> clean.() |> String.replace(".", "_")
148+
149+
cols =
150+
Enum.map(rest, fn col ->
151+
col |> clean.() |> String.split(".") |> List.last() |> clean.()
152+
end)
153+
154+
[table_col | cols] |> Enum.concat(["index"]) |> Enum.join("_")
163155
else
164156
if String.contains?(constraint, ".") do
165157
# Single column: "table.column" -> "table_column_index"

0 commit comments

Comments
 (0)