Skip to content

Commit

Permalink
feat(electric): Add support for UUID data type in electrified tables (#…
Browse files Browse the repository at this point in the history
…342)

Closes VAX-822.
  • Loading branch information
alco authored Sep 14, 2023
1 parent 3c47193 commit 76b15a6
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-items-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@core/electric": patch
---

Implement support for the UUID column type in electrified tables.
7 changes: 1 addition & 6 deletions components/electric/lib/electric/postgres/dialect/sqlite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,8 @@ defmodule Electric.Postgres.Dialect.SQLite do
@types[:integer] <> sized(size)
end

# UUID
# binary or string? no right answer unless db filesize is your only metric,
# in which case binary wins hands down
# https://stackoverflow.com/questions/11337324/how-to-efficient-insert-and-fetch-uuid-in-core-data/11337522#11337522
# TODO: allow for some override map pg_type => choice of sqlite type
def do_map_type(t, size) when t in @uuid_types do
@types[:blob] <> sized(size)
@types[:text] <> sized(size)
end

defp sized([]), do: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Electric.Satellite.Serialization do
float8
text
timestamp timestamptz
uuid
varchar
]a
end
Expand Down
28 changes: 14 additions & 14 deletions components/electric/test/electric/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ defmodule Electric.PlugTest do

assert file_list == [
{~c"0001/migration.sql",
"CREATE TABLE \"a\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"a_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nCREATE TABLE \"b\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"b_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nCREATE INDEX \"a_idx\" ON \"a\" (\"value\" ASC);\n"},
"CREATE TABLE \"a\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"a_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nCREATE TABLE \"b\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"b_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nCREATE INDEX \"a_idx\" ON \"a\" (\"value\" ASC);\n"},
{
~c"0001/metadata.json",
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWESEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwMRJ+EnxDUkVBVEUgVEFCTEUgImEiICgKICAiaWQiIEJMT0IgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImFfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\",\"GjIKAWISEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwMRJ+EnxDUkVBVEUgVEFCTEUgImIiICgKICAiaWQiIEJMT0IgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImJfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\",\"CgQwMDAxEi8IARIrQ1JFQVRFIElOREVYICJhX2lkeCIgT04gImEiICgidmFsdWUiIEFTQyk7Cg==\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0001\"}"
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWESEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwMRJ+EnxDUkVBVEUgVEFCTEUgImEiICgKICAiaWQiIFRFWFQgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImFfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\",\"GjIKAWISEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwMRJ+EnxDUkVBVEUgVEFCTEUgImIiICgKICAiaWQiIFRFWFQgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImJfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\",\"CgQwMDAxEi8IARIrQ1JFQVRFIElOREVYICJhX2lkeCIgT04gImEiICgidmFsdWUiIEFTQyk7Cg==\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0001\"}"
},
{~c"0002/migration.sql",
"CREATE TABLE \"c\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"c_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"},
"CREATE TABLE \"c\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"c_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"},
{
~c"0002/metadata.json",
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWMSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwMhJ+EnxDUkVBVEUgVEFCTEUgImMiICgKICAiaWQiIEJMT0IgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImNfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0002\"}"
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWMSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwMhJ+EnxDUkVBVEUgVEFCTEUgImMiICgKICAiaWQiIFRFWFQgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImNfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0002\"}"
},
{~c"0003/migration.sql",
"CREATE TABLE \"d\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"d_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nALTER TABLE \"d\" ADD COLUMN \"is_valid\" INTEGER;\n"},
"CREATE TABLE \"d\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"d_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nALTER TABLE \"d\" ADD COLUMN \"is_valid\" INTEGER;\n"},
{
~c"0003/metadata.json",
"{\"format\":\"SatOpMigrate\",\"ops\":[\"Gk8KAWQSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEn4SfENSRUFURSBUQUJMRSAiZCIgKAogICJpZCIgQkxPQiBOT1QgTlVMTCwKICAidmFsdWUiIFRFWFQgTk9UIE5VTEwsCiAgQ09OU1RSQUlOVCAiZF9wa2V5IiBQUklNQVJZIEtFWSAoImlkIikKKSBXSVRIT1VUIFJPV0lEOwo=\",\"Gk8KAWQSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEjMIBhIvQUxURVIgVEFCTEUgImQiIEFERCBDT0xVTU4gImlzX3ZhbGlkIiBJTlRFR0VSOwo=\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0003\"}"
"{\"format\":\"SatOpMigrate\",\"ops\":[\"Gk8KAWQSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEn4SfENSRUFURSBUQUJMRSAiZCIgKAogICJpZCIgVEVYVCBOT1QgTlVMTCwKICAidmFsdWUiIFRFWFQgTk9UIE5VTEwsCiAgQ09OU1RSQUlOVCAiZF9wa2V5IiBQUklNQVJZIEtFWSAoImlkIikKKSBXSVRIT1VUIFJPV0lEOwo=\",\"Gk8KAWQSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEjMIBhIvQUxURVIgVEFCTEUgImQiIEFERCBDT0xVTU4gImlzX3ZhbGlkIiBJTlRFR0VSOwo=\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0003\"}"
},
{~c"0004/migration.sql",
"CREATE TABLE \"e\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"e_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"},
"CREATE TABLE \"e\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"e_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"},
{
~c"0004/metadata.json",
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWUSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwNBJ+EnxDUkVBVEUgVEFCTEUgImUiICgKICAiaWQiIEJMT0IgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImVfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0004\"}"
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWUSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwNBJ+EnxDUkVBVEUgVEFCTEUgImUiICgKICAiaWQiIFRFWFQgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImVfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0004\"}"
}
]

Expand All @@ -113,15 +113,15 @@ defmodule Electric.PlugTest do
%SatOpMigrate.Stmt{
type: :CREATE_TABLE,
sql:
"CREATE TABLE \"a\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"a_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"
"CREATE TABLE \"a\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"a_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"
}
],
table: %SatOpMigrate.Table{
name: "a",
columns: [
%SatOpMigrate.Column{
name: "id",
sqlite_type: "BLOB",
sqlite_type: "TEXT",
pg_type: %SatOpMigrate.PgColumnType{name: "uuid"}
},
%SatOpMigrate.Column{
Expand Down Expand Up @@ -165,16 +165,16 @@ defmodule Electric.PlugTest do

assert file_list == [
{~c"0003/migration.sql",
"CREATE TABLE \"d\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"d_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nALTER TABLE \"d\" ADD COLUMN \"is_valid\" INTEGER;\n"},
"CREATE TABLE \"d\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"d_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n\n\nALTER TABLE \"d\" ADD COLUMN \"is_valid\" INTEGER;\n"},
{
~c"0003/metadata.json",
"{\"format\":\"SatOpMigrate\",\"ops\":[\"Gk8KAWQSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEn4SfENSRUFURSBUQUJMRSAiZCIgKAogICJpZCIgQkxPQiBOT1QgTlVMTCwKICAidmFsdWUiIFRFWFQgTk9UIE5VTEwsCiAgQ09OU1RSQUlOVCAiZF9wa2V5IiBQUklNQVJZIEtFWSAoImlkIikKKSBXSVRIT1VUIFJPV0lEOwo=\",\"Gk8KAWQSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEjMIBhIvQUxURVIgVEFCTEUgImQiIEFERCBDT0xVTU4gImlzX3ZhbGlkIiBJTlRFR0VSOwo=\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0003\"}"
"{\"format\":\"SatOpMigrate\",\"ops\":[\"Gk8KAWQSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEn4SfENSRUFURSBUQUJMRSAiZCIgKAogICJpZCIgVEVYVCBOT1QgTlVMTCwKICAidmFsdWUiIFRFWFQgTk9UIE5VTEwsCiAgQ09OU1RSQUlOVCAiZF9wa2V5IiBQUklNQVJZIEtFWSAoImlkIikKKSBXSVRIT1VUIFJPV0lEOwo=\",\"Gk8KAWQSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0EhsKCGlzX3ZhbGlkEgdJTlRFR0VSGgYKBGJvb2wiAmlkCgQwMDAzEjMIBhIvQUxURVIgVEFCTEUgImQiIEFERCBDT0xVTU4gImlzX3ZhbGlkIiBJTlRFR0VSOwo=\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0003\"}"
},
{~c"0004/migration.sql",
"CREATE TABLE \"e\" (\n \"id\" BLOB NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"e_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"},
"CREATE TABLE \"e\" (\n \"id\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n CONSTRAINT \"e_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n"},
{
~c"0004/metadata.json",
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWUSEgoCaWQSBEJMT0IaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwNBJ+EnxDUkVBVEUgVEFCTEUgImUiICgKICAiaWQiIEJMT0IgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImVfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0004\"}"
"{\"format\":\"SatOpMigrate\",\"ops\":[\"GjIKAWUSEgoCaWQSBFRFWFQaBgoEdXVpZBIVCgV2YWx1ZRIEVEVYVBoGCgR0ZXh0IgJpZAoEMDAwNBJ+EnxDUkVBVEUgVEFCTEUgImUiICgKICAiaWQiIFRFWFQgTk9UIE5VTEwsCiAgInZhbHVlIiBURVhUIE5PVCBOVUxMLAogIENPTlNUUkFJTlQgImVfcGtleSIgUFJJTUFSWSBLRVkgKCJpZCIpCikgV0lUSE9VVCBST1dJRDsK\"],\"protocol_version\":\"Electric.Satellite\",\"version\":\"0004\"}"
}
]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Electric.Postgres.Dialect.SqliteTest do
{map_type.(Postgres.bool_types()), "INTEGER"},
{map_array_type.(Postgres.bool_types()), "TEXT_JSON"},
# UUID
{map_type.(Postgres.uuid_types()), "BLOB"},
{map_type.(Postgres.uuid_types()), "TEXT"},
{map_array_type.(Postgres.bool_types()), "TEXT_JSON"},
# JSON
{map_type.(Postgres.json_types()), "TEXT_JSON"}
Expand Down Expand Up @@ -116,7 +116,7 @@ defmodule Electric.Postgres.Dialect.SqliteTest do
"id" INTEGER NOT NULL,
"i1" INTEGER,
"i2" TEXT_JSON,
"i3" BLOB,
"i3" TEXT,
"i4" TEXT,
"i5" TEXT_JSON,
"i6" INTEGER,
Expand Down Expand Up @@ -148,7 +148,7 @@ defmodule Electric.Postgres.Dialect.SqliteTest do
~s["id" INTEGER NOT NULL,],
~s["i1" INTEGER,],
~s["i2" TEXT_JSON,],
~s["i3" BLOB,],
~s["i3" TEXT,],
~s["i4" TEXT,],
~s["i5" TEXT_JSON,],
~s["i6" INTEGER,],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do
end

test_tx "inserts a row into the electrified table", fn conn ->
sql = "CREATE TABLE buttercup (id text PRIMARY KEY DEFAULT uuid_generate_v4());"
sql = "CREATE TABLE buttercup (id uuid PRIMARY KEY DEFAULT uuid_generate_v4());"
{:ok, _cols, _rows} = :epgsql.squery(conn, sql)

sql = "CALL electric.electrify('buttercup');"
Expand All @@ -32,7 +32,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do
test_tx "inserts the DDL for the table into the migration table", fn conn ->
sql = """
CREATE TABLE buttercup (
id text PRIMARY KEY DEFAULT uuid_generate_v4(),
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
value text,
secret integer
);
Expand All @@ -56,7 +56,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do
test_tx "duplicate call raises", fn conn ->
sql = """
CREATE TABLE buttercup (
id text PRIMARY KEY DEFAULT uuid_generate_v4(),
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
value text,
secret integer
);
Expand All @@ -75,10 +75,10 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do
end

test_tx "handles quoted table names", fn conn ->
sql = "CREATE TABLE \"la la daisy\" (id text PRIMARY KEY DEFAULT uuid_generate_v4());"
sql = "CREATE TABLE \"la la daisy\" (id uuid PRIMARY KEY DEFAULT uuid_generate_v4());"
{:ok, _cols, _rows} = :epgsql.squery(conn, sql)

sql = "CREATE TABLE \"la la buttercup\" (id text PRIMARY KEY DEFAULT uuid_generate_v4());"
sql = "CREATE TABLE \"la la buttercup\" (id uuid PRIMARY KEY DEFAULT uuid_generate_v4());"
{:ok, _cols, _rows} = :epgsql.squery(conn, sql)

sql = "CALL electric.electrify('public', 'la la daisy');"
Expand All @@ -96,7 +96,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do
end

test_tx "allows for namespaced table names", fn conn ->
sql = "CREATE TABLE daisy (id text PRIMARY KEY DEFAULT uuid_generate_v4());"
sql = "CREATE TABLE daisy (id uuid PRIMARY KEY DEFAULT uuid_generate_v4());"
{:ok, _cols, _rows} = :epgsql.squery(conn, sql)

sql = "CALL electric.electrify('public.daisy');"
Expand All @@ -123,7 +123,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do

sql = """
CREATE TABLE balloons.buttercup (
id text PRIMARY KEY DEFAULT uuid_generate_v4(),
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
value text,
secret integer
);
Expand Down Expand Up @@ -167,7 +167,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do
test_tx "adds the electrified table to the publication", fn conn ->
assert published_tables(conn) == []

sql = "CREATE TABLE buttercup (id text PRIMARY KEY DEFAULT uuid_generate_v4(), value text);"
sql = "CREATE TABLE buttercup (id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), value text);"

{:ok, _cols, _rows} = :epgsql.squery(conn, sql)

Expand All @@ -185,7 +185,7 @@ defmodule Electric.Postgres.Extension.ElectrifyTest do

sql = """
CREATE TABLE buttercup (
id text PRIMARY KEY DEFAULT uuid_generate_v4(),
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
value text,
secret integer
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Electric.Postgres.Extension.SchemaCacheTest do
Transaction
}

@create_a "CREATE TABLE a (aid text NOT NULL PRIMARY KEY, avalue text);"
@create_a "CREATE TABLE a (aid uuid NOT NULL PRIMARY KEY, avalue text);"
@create_b "CREATE TABLE b.b (bid1 int4, bid2 int4, bvalue text, PRIMARY KEY (bid1, bid2));"
@sqls [
@create_a,
Expand Down Expand Up @@ -188,7 +188,7 @@ defmodule Electric.Postgres.Extension.SchemaCacheTest do
columns: [
%Column{
name: "aid",
type: :text,
type: :uuid,
nullable?: false,
type_modifier: -1,
part_of_identity?: true
Expand Down Expand Up @@ -220,7 +220,7 @@ defmodule Electric.Postgres.Extension.SchemaCacheTest do
columns: [
%Column{
name: "aid",
type: :text,
type: :uuid,
nullable?: false,
type_modifier: -1,
part_of_identity?: true
Expand Down Expand Up @@ -254,7 +254,7 @@ defmodule Electric.Postgres.Extension.SchemaCacheTest do
assert table_info.columns == [
%Column{
name: "aid",
type: :text,
type: :uuid,
nullable?: false,
type_modifier: -1,
part_of_identity?: true
Expand Down Expand Up @@ -304,7 +304,7 @@ defmodule Electric.Postgres.Extension.SchemaCacheTest do
assert table_info.columns == [
%Column{
name: "aid",
type: :text,
type: :uuid,
nullable?: false,
type_modifier: -1,
part_of_identity?: true
Expand Down Expand Up @@ -338,7 +338,7 @@ defmodule Electric.Postgres.Extension.SchemaCacheTest do
assert table_info.columns == [
%Column{
name: "aid",
type: :text,
type: :uuid,
nullable?: false,
type_modifier: -1,
part_of_identity?: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ defmodule Electric.Postgres.ExtensionTest do
assert [{:ok, [], []}, {:ok, [], []}] ==
:epgsql.squery(conn, """
CREATE TABLE public.t1 (
id TEXT PRIMARY KEY,
id UUID PRIMARY KEY,
content TEXT NOT NULL,
words VARCHAR,
num2a INT2,
Expand Down Expand Up @@ -464,7 +464,6 @@ defmodule Electric.Postgres.ExtensionTest do
assert error_msg ==
"""
Cannot electrify "public.t1" because some of its columns have types not supported by Electric:
"id" uuid
"c1" character(1)
"c2" character(11)
"c3" character varying(11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ defmodule Electric.Replication.InitialSyncTest do
{:ok, [], []} =
:epgsql.squery(conn, """
CREATE TABLE public.users (
id TEXT PRIMARY KEY,
id UUID PRIMARY KEY,
name TEXT NOT NULL
)
""")
Expand All @@ -137,9 +137,9 @@ defmodule Electric.Replication.InitialSyncTest do
{:ok, [], []} =
:epgsql.squery(conn, """
CREATE TABLE public.documents (
id TEXT PRIMARY KEY,
id UUID PRIMARY KEY,
title TEXT NOT NULL,
user_id TEXT REFERENCES users(id)
user_id UUID REFERENCES users(id)
)
""")

Expand Down
Loading

0 comments on commit 76b15a6

Please sign in to comment.