Skip to content

Commit

Permalink
Add support for the int8 type on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
alco committed Nov 12, 2023
1 parent 0ad1867 commit 95bee12
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 37 deletions.
2 changes: 1 addition & 1 deletion components/electric/lib/electric/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ defmodule Electric.Postgres do
bool
date
float8
int2 int4
int2 int4 int8
text
time
timestamp timestamptz
Expand Down
6 changes: 2 additions & 4 deletions components/electric/test/electric/postgres/extension_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ defmodule Electric.Postgres.ExtensionTest do
num4a INT4,
num4b INT,
num4c INTEGER,
num8a INT8,
num8b BIGINT,
real8a FLOAT8,
real8b DOUBLE PRECISION,
ts TIMESTAMP,
Expand All @@ -457,8 +459,6 @@ defmodule Electric.Postgres.ExtensionTest do
c1 CHARACTER,
c2 CHARACTER(11),
"C3" VARCHAR(11),
num8a INT8,
num8b BIGINT,
real4a FLOAT4,
"Real4b" REAL,
created_at TIMETZ
Expand All @@ -472,8 +472,6 @@ defmodule Electric.Postgres.ExtensionTest do
c1 character(1)
c2 character(11)
"C3" character varying(11)
num8a bigint
num8b bigint
real4a real
"Real4b" real
created_at time with time zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ defmodule Electric.Satellite.WsValidationsTest do
migrate(
ctx.db,
vsn,
"CREATE TABLE public.foo (id TEXT PRIMARY KEY, i2_1 SMALLINT, i2_2 INT2, i4_1 INTEGER, i4_2 INT4)",
# "CREATE TABLE public.foo (id TEXT PRIMARY KEY, i2_1 SMALLINT, i2_2 INT2, i4_1 INTEGER, i4_2 INT4, i8_1 BIGINT, i8_2 INT8)"
"CREATE TABLE public.foo (id TEXT PRIMARY KEY, i2_1 SMALLINT, i2_2 INT2, i4_1 INTEGER, i4_2 INT4, i8_1 BIGINT, i8_2 INT8)",
electrify: "public.foo"
)

valid_records = [
%{"id" => "1", "i2_1" => "1", "i2_2" => "-1"},
%{"id" => "2", "i2_1" => "32767", "i2_2" => "-32768"},
%{"id" => "2", "i2_1" => "-32768", "i2_2" => "32767"},
%{"id" => "3", "i4_1" => "+0", "i4_2" => "-0"},
%{"id" => "4", "i4_1" => "2147483647", "i4_2" => "-2147483648"}
# %{"id" => "5", "i8_1" => "-9223372036854775808", "i8_2" => "+9223372036854775807"}
%{"id" => "4", "i4_1" => "-2147483648", "i4_2" => "2147483647"},
%{"id" => "5", "i8_1" => "-30000000000", "i8_2" => "30000000000"},
%{"id" => "6", "i8_1" => "-9223372036854775808", "i8_2" => "+9223372036854775807"}
]

within_replication_context(ctx, vsn, fn conn ->
Expand All @@ -164,13 +164,19 @@ defmodule Electric.Satellite.WsValidationsTest do
%{"id" => "11", "i2_2" => "five"},
%{"id" => "12", "i4_1" => "."},
%{"id" => "13", "i4_2" => "-"},
# %{"id" => "14", "i8_1" => "+"},
# %{"id" => "15", "i8_2" => "0.0"},
# %{"id" => "16", "i8_1" => "1_000"},
%{"id" => "14", "i8_1" => "+"},
%{"id" => "15", "i8_2" => "0.0"},
%{"id" => "16", "i8_1" => "1_000"},
%{"id" => "17", "i4_2" => "-1+5"},
%{"id" => "18", "i4_1" => "0x33"},
%{"id" => "19", "i2_2" => "0b101011"},
%{"id" => "20", "i2_1" => "0o373"}
%{"id" => "20", "i2_1" => "0o373"},
%{"id" => "21", "i2_1" => "-32769"},
%{"id" => "22", "i2_2" => "32768"},
%{"id" => "23", "i4_1" => "-2147483649"},
%{"id" => "24", "i4_2" => "2147483648"},
%{"id" => "25", "i8_1" => "-9223372036854775809"},
%{"id" => "26", "i8_2" => "9223372036854775808"}
]

Enum.each(invalid_records, fn record ->
Expand Down
1 change: 1 addition & 0 deletions docs/usage/data-modelling/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You are responsible for ensuring the uniqueness of your primary keys. If you som

- `smallint` / `int2`
- `integer` / `int` / `int4`
- `bigint` / `int8`
- `double precision` / `float8`

**Strings**:
Expand Down
8 changes: 2 additions & 6 deletions e2e/satellite_client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,9 @@ export const get_int = (electric: Electric, id: string) => {
})
}

export const write_int = (electric: Electric, id: string, i2: number, i4: number) => {
export const write_int = (electric: Electric, id: string, i2: number, i4: number, i8: number) => {
return electric.db.ints.create({
data: {
id,
i2,
i4,
}
data: { id, i2, i4, i8 }
})
}

Expand Down
38 changes: 23 additions & 15 deletions e2e/tests/03.17_node_satellite_can_sync_ints.lux
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
CREATE TABLE public.ints (
id TEXT PRIMARY KEY,
i2 SMALLINT,
i4 INTEGER
i4 INTEGER,
i8 BIGINT
);
ALTER TABLE public.ints ENABLE ELECTRIC;
"""]
Expand All @@ -23,28 +24,32 @@
[invoke node_sync_table "ints"]

[shell proxy_1]
!INSERT INTO public.ints (id, i2, i4) VALUES ('row1', -32768, -2147483648), ('row2', 32767, 2147483647);
"""!
INSERT INTO public.ints (id, i2, i4, i8) VALUES
('row1', -32768, -2147483648, -30000000000),
('row2', 32767, 2147483647, 30000000000);
"""
??INSERT 0 2

[shell satellite_1]
# Wait for the rows to arrive
[invoke node_await_get_int "row2"]
[invoke node_get_int "row1" -32768 -2147483648]
[invoke node_get_int "row2" 32767 2147483647]

[invoke node_get_int "row1" -32768 -2147483648 -30000000000]
[invoke node_get_int "row2" 32767 2147483647 30000000000]

# Can write valid ints to the DB
!await client.write_int(db, 'row3', 0, 0)
??{ id: 'row3', i2: 0, i4: 0 }
!await client.write_int(db, 'row3', 0, 0, 0)
??{ id: 'row3', i2: 0, i4: 0, i8: 0 }
?$node

[shell proxy_1]
[invoke wait-for "SELECT * FROM public.ints;" "row3" 10 $psql]

!SELECT * FROM public.ints;
??row1 | -32768 | -2147483648
??row2 | 32767 | 2147483647
??row3 | 0 | 0
??row1 | -32768 | -2147483648 | -30000000000
??row2 | 32767 | 2147483647 | 30000000000
??row3 | 0 | 0 | 0

# Start a new Satellite client and verify that it receives all rows
[invoke setup_client 2 electric_1 5133]
Expand All @@ -56,18 +61,21 @@
# Wait for the rows to arrive
[invoke node_await_get_int "row3"]

[invoke node_get_int "row1" -32768 -2147483648]
[invoke node_get_int "row2" 32767 2147483647]
[invoke node_get_int "row3" 0 0]
[invoke node_get_int "row1" -32768 -2147483648 -30000000000]
[invoke node_get_int "row2" 32767 2147483647 30000000000]
[invoke node_get_int "row3" 0 0 0]

# Reset the failure pattern because we don't want it to match the errors below
-
# Can't write invalid ints to the DB
!await client.write_int(db, 'row4', 32768, 5)
!await client.write_int(db, 'row4', 32768, 5, 0)
??Number must be less than or equal to 32767

!await client.write_int(db, 'row4', 5, 2147483648)
!await client.write_int(db, 'row4', 5, 2147483648, 0)
??Number must be less than or equal to 2147483647

#!await client.write_int(db, 'row4', 5, 0, -9223372036854775809)
#??Number must be less than or equal to 9223372036854775808

[cleanup]
[invoke teardown]
4 changes: 2 additions & 2 deletions e2e/tests/_satellite_macros.luxinc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
??$node
[endmacro]

[macro node_get_int id expected_int2 expected_int4]
[macro node_get_int id expected_int2 expected_int4 expected_int8]
!await client.get_int(db, '${id}')
??{ id: '${id}', i2: ${expected_int2}, i4: ${expected_int4} }
??{ id: '${id}', i2: ${expected_int2}, i4: ${expected_int4}, i8: ${expected_int8} }
??$node
[endmacro]

Expand Down

0 comments on commit 95bee12

Please sign in to comment.