spacebarchat / spacebarchat/server

[Database] "security_keys" already exists

Open
#1,468 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs more information
Dominant language
TypeScript
Stars
2.2k
Forks
323
Avg merge
14h 48m
Merged PRs (30d)
4

Description

Describe the bug
When running "npm run start" I get a database error what seems to be related to but not the same issue ER_TABLE_EXISTS #1211 and migration table duplicate security key bug. But the data I have looks nothing like that and has lots more columns and have remove the db and restarted to no avail.

To Reproduce
Steps to reproduce the behavior:

  1. As spacebar user, I run "npm run start"
  2. Then it throws errors while connected to postgresql database.
  3. See error

Expected behavior
This should start the service on port 3001

Console Logs

[System] linux 5.14.0-611.20.1.el9_7.x86_64 x64
[System] AlmaLinux 9.7 (Moss Jungle Cat) (No build ID)
[Process] Running with PID: 291958
[Process] Starting with 1 threads
[Database] Connecting to postgres db
[Database] Applying missing migrations, if any.
Migration "webauthn1675044825710" failed, error: relation "security_keys" already exists
QueryFailedError: relation "security_keys" already exists
at PostgresQueryRunner.query (/var/www/spacebar.userspace.org/server/node_modules/typeorm/driver/src/driver/postgres/PostgresQueryRunner.ts:325:19)
at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
at async webauthn1675044825710.up (/var/www/spacebar.userspace.org/server/src/util/migration/postgres/1675044825710-webauthn.ts:25:9)
at async MigrationExecutor.executePendingMigrations (/var/www/spacebar.userspace.org/server/node_modules/typeorm/migration/src/migration/MigrationExecutor.ts:336:17)
at async DataSource.runMigrations (/var/www/spacebar.userspace.org/server/node_modules/typeorm/data-source/src/data-source/DataSource.ts:404:13)
at async initDatabase (/var/www/spacebar.userspace.org/server/src/util/util/Database.ts:136:5)
at async main (/var/www/spacebar.userspace.org/server/src/bundle/Server.ts:61:5) {
query: 'CREATE TABLE "security_keys" ("id" character varying NOT NULL, "user_id" character varying, "key_id" character varying NOT NULL, "public_key" character varying NOT NULL, "counter" integer NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_6e95cdd91779e7cca06d1fff89c" PRIMARY KEY ("id"))',
parameters: undefined,
driverError: error: relation "security_keys" already exists
at /var/www/spacebar.userspace.org/server/node_modules/pg/lib/client.js:545:17
at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
at async PostgresQueryRunner.query (/var/www/spacebar.userspace.org/server/node_modules/typeorm/driver/src/driver/postgres/PostgresQueryRunner.ts:254:25)
at async webauthn1675044825710.up (/var/www/spacebar.userspace.org/server/src/util/migration/postgres/1675044825710-webauthn.ts:25:9)
at async MigrationExecutor.executePendingMigrations (/var/www/spacebar.userspace.org/server/node_modules/typeorm/migration/src/migration/MigrationExecutor.ts:336:17)
at async DataSource.runMigrations (/var/www/spacebar.userspace.org/server/node_modules/typeorm/data-source/src/data-source/DataSource.ts:404:13)
at async initDatabase (/var/www/spacebar.userspace.org/server/src/util/util/Database.ts:136:5)
at async main (/var/www/spacebar.userspace.org/server/src/bundle/Server.ts:61:5) {
length: 107,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'heap.c',
line: '1150',
routine: 'heap_create_with_catalog'
},
length: 107,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'heap.c',
line: '1150',
routine: 'heap_create_with_catalog'
}

System Information:

  • OS: Alma Linux
  • Version 9.7
    • Node Version: [e.g Node v18.7.0]
  • Python 3 Version: [e.g Python 3.10.6]

Env and Software info

The number of threads to run Spacebar on.

THREADS=1

The port the server will listen on.

PORT=3001

The database connection string. Defaults to SQLite3 at project root (database.db).

DATABASE="postgres://spacebar_access:PASSWORD@localhost:5432/spacebar"

  • Database: Postgresql 16
  • Thread Count: 1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/util/migration/postgres/1675044825710-webauthn.ts and inspect how it is invoked from src/util/util/Database.ts during startup. Reproduce the PostgreSQL migration failure, then verify the migration handles the existing security_keys relation and that src/util/bundle/Server.ts can start the service on port 3001.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, postgresql, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.