Skip to content

Commit f90c013

Browse files
jalcineConnorRigby
authored andcommitted
fix(table): Allow renaming column support. (#228)
* fix(table): Allow renaming column support. Support for renaming columns was added in 3.25.0 https://sqlite.org/releaselog/3_25_0.html
1 parent a311dc5 commit f90c013

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

lib/sqlite_ecto/connection.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ if Code.ensure_loaded?(Sqlitex.Server) do
632632
" RENAME TO ", quote_table(nil, new_table.name)]]
633633
end
634634

635-
def execute_ddl({:rename, %Table{}, _old_col, _new_col}) do
636-
raise ArgumentError, "RENAME COLUMN not supported by SQLite"
635+
def execute_ddl({:rename, %Table{} = current_table, old_col, new_col}) do
636+
[["ALTER TABLE ", quote_table(current_table.prefix, current_table.name),
637+
" RENAME COLUMN ", quote_name(old_col), " TO ", quote_name(new_col)]]
637638
end
638639

639640
def execute_ddl({command, %Constraint{}})

test/sqlite_ecto_test.exs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1265,16 +1265,12 @@ defmodule Sqlite.Ecto2.Test do
12651265

12661266
test "rename column" do
12671267
rename = {:rename, table(:posts), :given_name, :first_name}
1268-
assert_raise ArgumentError, "RENAME COLUMN not supported by SQLite", fn ->
1269-
execute_ddl(rename)
1270-
end
1268+
assert execute_ddl(rename) == [~s|ALTER TABLE "posts" RENAME COLUMN "given_name" TO "first_name"|]
12711269
end
12721270

12731271
test "rename column in prefixed table" do
12741272
rename = {:rename, table(:posts, prefix: :foo), :given_name, :first_name}
1275-
assert_raise ArgumentError, "RENAME COLUMN not supported by SQLite", fn ->
1276-
execute_ddl(rename)
1277-
end
1273+
assert execute_ddl(rename) == [~s|ALTER TABLE "foo"."posts" RENAME COLUMN "given_name" TO "first_name"|]
12781274
end
12791275

12801276
test "drop column errors" do

0 commit comments

Comments
 (0)