Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(electric): Enable introspection of electrified enum types in the proxy #670

Merged
merged 7 commits into from
Jan 9, 2024

Conversation

alco
Copy link
Member

@alco alco commented Nov 15, 2023

Fixes VAX-1042.

@alco alco requested a review from magnetised November 15, 2023 23:59
@alco alco force-pushed the alco/vax-1040-fetch-enum-type-info branch 8 times, most recently from e7faa6d to 495ff8b Compare November 20, 2023 15:31
@alco alco force-pushed the alco/prisma-introspection-types branch from cd13b02 to 6ee853f Compare November 20, 2023 22:07
Copy link

linear bot commented Nov 20, 2023

@alco alco force-pushed the alco/vax-1040-fetch-enum-type-info branch from 1e735cf to ae7d07d Compare November 20, 2023 22:51
@alco alco force-pushed the alco/prisma-introspection-types branch from 6ee853f to e1d7021 Compare November 20, 2023 22:52
@alco alco force-pushed the alco/prisma-introspection-types branch 2 times, most recently from ff79b4f to 89f59d4 Compare January 8, 2024 12:42
@alco alco changed the base branch from alco/vax-1040-fetch-enum-type-info to alco/vax-1040-enum-support January 8, 2024 12:42
@alco alco marked this pull request as ready for review January 8, 2024 13:10
Base automatically changed from alco/vax-1040-enum-support to main January 8, 2024 13:12
alco and others added 3 commits January 8, 2024 15:20
This PR adds support for enumerations by:
- modifying the generator to store enumeration types as "TEXT" type in
the generated client
- modifying satellite to serialise/deserialise enumerations as text
- since enumeration types are unknown to Satellite it
serialises/deserialises them as text
@alco alco force-pushed the alco/prisma-introspection-types branch from 89f59d4 to d44cb3a Compare January 8, 2024 13:20
@davidmartos96
Copy link
Contributor

@alco I'm trying out the PR with the an enum migration but the introspection fails with the following error.
Am I doing something wrong? I'm running the Electric service built in latest commit from this branch.

...

CREATE TYPE color AS ENUM ('RED', 'GREEN', 'BLUE');
CREATE TABLE enums (
    id TEXT PRIMARY KEY,
    c color
);
ALTER TABLE enums ENABLE ELECTRIC;
16:03:44.955 pid=<0.3106.0> pg_producer=postgres_1 [info] Migrating version <nil> -> 1
16:03:44.955 pid=<0.3106.0> pg_producer=postgres_1 [info] Applying migration 1: "CREATE TABLE items (\n    value text NOT NULL,\n    CONSTRAINT items_pkey PRIMARY KEY (value)\n);\n\n\n"
16:03:44.955 pid=<0.3106.0> pg_producer=postgres_1 [info] CREATE TABLE items (...)
16:03:44.956 pid=<0.3106.0> pg_producer=postgres_1 [info] Applying migration 1: "CREATE TYPE color AS ENUM (\n 'RED',\n 'GREEN',\n 'BLUE'\n);\n\n\nCREATE TABLE enums (\n    id text NOT NULL,\n    c color,\n    CONSTRAINT enums_pkey PRIMARY KEY (id)\n);\n\n\n"
16:03:44.956 pid=<0.3106.0> pg_producer=postgres_1 [info] CREATE ENUM "public"."color" WITH VALUES ["RED", "GREEN", "BLUE"]
16:03:44.956 pid=<0.3106.0> pg_producer=postgres_1 [info] CREATE TABLE enums (...)
16:03:44.957 pid=<0.3106.0> pg_producer=postgres_1 [info] Saving schema version 1 /{Electric.Postgres.Extension.SchemaCache, "postgres_1"}/
16:03:44.961 pid=<0.3100.0> pg_producer=postgres_1 [info] Saved schema version 1
16:03:44.962 pid=<0.3106.0> pg_producer=postgres_1 [info] Electric.Replication.Postgres.Client.with_conn(%{database: ~c"web_wa_sqlite", host: ~c"postgres", ip_addr: ~c"172.29.0.2", ipv6: true, nulls: [nil, :null, :undefined], password: ~c"******", port: 5432, ssl: true, timeout: 5000, username: ~c"postgres"})
16:17:23.781 pid=<0.3435.0> [info] GET /api/migrations
16:17:23.801 pid=<0.3435.0> [info] Sent 200 in 19ms
16:17:24.347 pid=<0.3437.0> proxy_session_id=6 [warning] Not validating user "prisma"
16:17:24.347 pid=<0.3437.0> proxy_session_id=6 [info] Initialising injector in capture mode %Electric.Postgres.Proxy.Injector.Prisma{config: %Electric.Postgres.Proxy.Prisma{server_version: {"14.9", 140009}}, prepared_statements: %{}, active_statement: nil, portals: %{}}
16:17:24.350 pid=<0.3437.0> proxy_session_id=6 [info] Upstream connection is ready to accept queries
16:17:24.352 pid=<0.3437.0> proxy_session_id=6 [info] Matched prisma introspection query to Elixir.Electric.Postgres.Proxy.Prisma.Query.NamespaceV5_2
16:17:24.352 pid=<0.3437.0> proxy_session_id=6 [info] Matched prisma introspection query to Elixir.Electric.Postgres.Proxy.Prisma.Query.TableListV4_8
16:17:24.353 pid=<0.3437.0> proxy_session_id=6 [info] Matched prisma introspection query to Elixir.Electric.Postgres.Proxy.Prisma.Query.TypeV4_8
16:17:24.353 pid=<0.3437.0> proxy_session_id=6 [error] GenServer #PID<0.3437.0> terminating
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a bitstring

    :erlang.byte_size(["RED", "GREEN", "BLUE"])
    (pg_protocol 0.1.0) lib/pg_protocol/message.ex:483: anonymous fn/1 in PgProtocol.Encoder.PgProtocol.Message.DataRow.encode/1
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (pg_protocol 0.1.0) lib/pg_protocol/message.ex:481: PgProtocol.Encoder.PgProtocol.Message.DataRow.encode/1
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (pg_protocol 0.1.0) lib/pg_protocol/encoder.ex:9: PgProtocol.Encoder.List.encode/1
Last message: {:tcp, #Port<0.29>, <<66, 0, 0, 0, 52, 0, 115, 51, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 30, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 6, 112, 117, 98, 108, ...>>}

@alco
Copy link
Member Author

alco commented Jan 8, 2024

@davidmartos96 I haven't tested it after the redesign of internal representation of enums done in #804

Thanks for sharing your log! I'll run some tests tomorrow and will get back to you.

@alco
Copy link
Member Author

alco commented Jan 9, 2024

@davidmartos96 There was a bug in the implementation. Please try again using the latest commit here.

Copy link
Contributor

@magnetised magnetised left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@alco alco merged commit 4fe5c7f into main Jan 9, 2024
15 checks passed
@alco alco deleted the alco/prisma-introspection-types branch January 9, 2024 15:21
msfstef pushed a commit that referenced this pull request Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants