SkillDevs / electric_dart

A Dart implementation for Electric (electric-sql.com).
Apache License 2.0
104 stars 9 forks source link

Switch to non alpine node docker image to support prisma on amd64 #12

Closed opsb closed 8 months ago

opsb commented 8 months ago

Running

dart run electricsql_cli generate

failed with the following error on my M1 mac machine.

generate command failed: Exception: Database introspection failed
Exit code: 1
Stderr: [introspection-engine] error: Error: spawn /usr/local/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-linux-arm64-openssl-3.0.x ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /usr/local/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-linux-arm64-openssl-3.0.x',
  path: '/usr/local/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-linux-arm64-openssl-3.0.x',
  spawnargs: []
}
Error: spawn /usr/local/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-linux-arm64-openssl-3.0.x ENOENT

Stdout: Prisma schema loaded from schema.prisma
Datasource "db": PostgreSQL database "todos_electrified", schema "public" at "localhost:65432"

- Introspecting based on datasource defined in schema.prisma
✖ Introspecting based on datasource defined in schema.prisma

Switching to the non-alpine image was enough to get it working.

davidmartos96 commented 8 months ago

@opsb Nice catch, thank you! I believe this could be the culprit https://github.com/prisma/prisma/issues/8478#issuecomment-1415834970 , but we are using version 4.8.x of Prisma, which is the same one Electric Javascript client is using for the Prisma introspection. I guess we could use the non Alpine version, although it's much heavier.

Before merging, could you try with prisma version 4.10 and Node Alpine and see if it works? Maybe it's safe to use 4.10 for Prisma, we can double check with the Electric team if there would be any problem running the introspection with that version.

opsb commented 8 months ago

I gave 4.10.0 a try with alpine and I don't see the original error but there's a different one

electric-1  | 16:21:36.839 pid=<0.3659.0> proxy_session_id=115 [error] Received unknown prisma introspection query: "SELECT tbl.relname AS table_name, namespace.nspname as namespace, tbl.relhassubclass\nFROM pg_class AS tbl\nINNER JOIN pg_namespace AS namespace ON namespace.oid = tbl.relnamespace\nWHERE\n  ( -- grab tables when\n    -- it's an oRdinary table ('r') and is not a partition;\n    -- NOTE: CockroachDB puts NULLs in 'relispartition'\n    (tbl.relkind = 'r' AND ((tbl.relispartition is NULL) OR tbl.relispartition = 'f'))\n      OR -- when it's a partition\n    tbl.relkind = 'p'\n  )\n  AND namespace.nspname = ANY ( $1 )\nORDER BY namespace, table_name;\n" with columns ["table_name", "namespace", "tbl.relhassubclass"]

Looks like prisma has made a change which the sync engine doesn't accommodate yet (at least in the latest version of the docker build anyway).

davidmartos96 commented 8 months ago

Ok, that was my worry. The Electric Migrations Proxy is designed around a particular behavior of the Prisma introspection, which doesn't seem to be compatible with version 4.10. Let's merge the non Alpine version then. Thank you!