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

Postgres Issue: duplicate key value violates unique constraint "migration_unique_version" [closed] #852

Closed
SukiTUK opened this issue Apr 23, 2024 · 1 comment

Comments

@SukiTUK
Copy link

SukiTUK commented Apr 23, 2024

I am trying to create below tables but unfortunately it is saying I violate unique constraint. Could someone please help? Note: rowmap and colmap has id as primary key. contentmap references rowmap and colmap for their id and I created content as primary key in contentmap table since it was showing another issue of not having primary key

`CREATE TABLE IF NOT EXISTS rowmap (
"id" uuid PRIMARY KEY NOT NULL,
"pos" integer
);

CREATE TABLE IF NOT EXISTS colmap (
"id" uuid PRIMARY KEY NOT NULL,
"pos" integer
);

CREATE TABLE IF NOT EXISTS contentmap (
"rowIndex" uuid NOT NULL REFERENCES rowmap("id") ON DELETE CASCADE,
"colIndex" uuid NOT NULL REFERENCES colmap("id") ON DELETE CASCADE,
"content" TEXT NOT NULL PRIMARY KEY
);

-- ⚡
-- Electrify the items table
ALTER TABLE items ENABLE ELECTRIC;
ALTER TABLE rowmap ENABLE ELECTRIC;
ALTER TABLE colmap ENABLE ELECTRIC;
ALTER TABLE contentmap ENABLE ELECTRIC;
`

Message I expect: DB has been created successfully

Regarding reproducing the error: I am creating the tables for the first time and there is no data as I am just initiating the creation of tables

I am using the command npm run db:migrate to create the tables on postgres via ElectricSQL

Log from the terminal is:

spreadsheet-postgres-1 | 2024-04-22 10:35:36.947 GMT [194] ERROR: duplicate key value violates unique constraint "migration_unique_version" spreadsheet-postgres-1 | 2024-04-22 10:35:36.947 GMT [194] DETAIL: Key (version)=(1) already exists. spreadsheet-postgres-1 | 2024-04-22 10:35:36.947 GMT [194] CONTEXT: SQL statement "INSERT INTO "electric"."migration_versions" AS v (version, priority) VALUES (_version, _priority::int2) spreadsheet-postgres-1 | ON CONFLICT (txid, txts) DO spreadsheet-postgres-1 | UPDATE SET version = EXCLUDED.version, priority = EXCLUDED.priority spreadsheet-postgres-1 | WHERE EXCLUDED.priority > v.priority" spreadsheet-postgres-1 | PL/pgSQL function electric.assign_migration_version(text,integer) line 5 at SQL statement spreadsheet-postgres-1 | 2024-04-22 10:35:36.947 GMT [194] STATEMENT: CALL electric.assign_migration_version($4b8bcbcee498$1$4b8bcbcee498$, 4)

@porsager
Copy link
Owner

Doesn't seem like an issue related to Postgres.js?

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

No branches or pull requests

2 participants