spacebarchat / server

Spacebar server - A reimplementation of the Discord.com backend, built with Typescript and love
https://spacebar.chat
GNU Affero General Public License v3.0
1.49k stars 250 forks source link

ER_TABLE_EXISTS #1211

Closed itsarts1 closed 2 months ago

itsarts1 commented 2 months ago

Describe the bug When attempting to start spacebar-server a database error appears pertaining to an already existing table. I check the DB and I can confirm that the table exists. My question is why is it attempting to recreate the table when it already exists.

To Reproduce Steps to reproduce the behavior:

  1. Run Command 'npm run start'
  2. See error

Expected behavior Server starts without issue.

Console Logs [Database] Applying missing migrations, if any. Migration "webauthn1675045120206" failed, error: ER_TABLE_EXISTS_ERROR: Table 'security_keys' already exists QueryFailedError: ER_TABLE_EXISTS_ERROR: Table 'security_keys' already exists at Query. (/home/arts/server/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:165:37) at Query. (/home/arts/server/node_modules/mysql/lib/Connection.js:526:10) at Query._callback (/home/arts/server/node_modules/mysql/lib/Connection.js:488:16) at Sequence.end (/home/arts/server/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24) at Query.ErrorPacket (/home/arts/server/node_modules/mysql/lib/protocol/sequences/Query.js:92:8) at Protocol._parsePacket (/home/arts/server/node_modules/mysql/lib/protocol/Protocol.js:291:23) at Parser._parsePacket (/home/arts/server/node_modules/mysql/lib/protocol/Parser.js:433:10) at Parser.write (/home/arts/server/node_modules/mysql/lib/protocol/Parser.js:43:10) at Protocol.write (/home/arts/server/node_modules/mysql/lib/protocol/Protocol.js:38:16) at Socket. (/home/arts/server/node_modules/mysql/lib/Connection.js:88:28) { query: 'CREATE TABLE security_keys (id varchar(255) NOT NULL, user_id varchar(255) NULL, key_id varchar(255) NOT NULL, public_key varchar(255) NOT NULL, counter int NOT NULL, name varchar(255) NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB', parameters: undefined, driverError: Error: ER_TABLE_EXISTS_ERROR: Table 'security_keys' already exists at Sequence._packetToError (/home/arts/server/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14) at Query.ErrorPacket (/home/arts/server/node_modules/mysql/lib/protocol/sequences/Query.js:79:18) at Protocol._parsePacket (/home/arts/server/node_modules/mysql/lib/protocol/Protocol.js:291:23) at Parser._parsePacket (/home/arts/server/node_modules/mysql/lib/protocol/Parser.js:433:10) at Parser.write (/home/arts/server/node_modules/mysql/lib/protocol/Parser.js:43:10) at Protocol.write (/home/arts/server/node_modules/mysql/lib/protocol/Protocol.js:38:16) at Socket. (/home/arts/server/node_modules/mysql/lib/Connection.js:88:28) at Socket. (/home/arts/server/node_modules/mysql/lib/Connection.js:526:10) at Socket.emit (node:events:519:28) at Socket.emit (node:domain:488:12)

  at Protocol._enqueue (/home/arts/server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
  at PoolConnection.query (/home/arts/server/node_modules/mysql/lib/Connection.js:198:25)
  at /home/arts/server/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:154:36
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_TABLE_EXISTS_ERROR',
errno: 1050,
sqlMessage: "Table 'security_keys' already exists",
sqlState: '42S01',
index: 0,
sql: 'CREATE TABLE `security_keys` (`id` varchar(255) NOT NULL, `user_id` varchar(255) NULL, `key_id` varchar(255) NOT NULL, `public_key` varchar(255) NOT NULL, `counter` int NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB'

}, code: 'ER_TABLE_EXISTS_ERROR', errno: 1050, sqlMessage: "Table 'security_keys' already exists", sqlState: '42S01', index: 0, sql: 'CREATE TABLE security_keys (id varchar(255) NOT NULL, user_id varchar(255) NULL, key_id varchar(255) NOT NULL, public_key varchar(255) NOT NULL, counter int NOT NULL, name varchar(255) NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB' }

System Information (please complete the following information):

Env and Software info

Additional context None. Wishing to see help

Puyodead1 commented 2 months ago

Most likely because there is no record of the migrations that have already been applied, there should be a migrations table that holds a list of what migrations have already been applied so the server knows what needs to be applies still and what doesn't.

itsarts1 commented 2 months ago

Most likely because there is no record of the migrations that have already been applied, there should be a migrations table that holds a list of what migrations have already been applied so the server knows what needs to be applies still and what doesn't.

SQL Information on table "migrations"

{
    "table": "migrations",
    "rows":
    [
        {
            "id": 1,
            "timestamp": 1673609465036,
            "name": "templateDeleteCascade1673609465036"
        }
    ]
}

formated as JSON

Puyodead1 commented 2 months ago

Most likely because there is no record of the migrations that have already been applied, there should be a migrations table that holds a list of what migrations have already been applied so the server knows what needs to be applies still and what doesn't.

SQL Information on table "migrations"

{
  "table": "migrations",
  "rows":
  [
      {
          "id": 1,
          "timestamp": 1673609465036,
          "name": "templateDeleteCascade1673609465036"
      }
  ]
}

formated as JSON

yeah this is missing any record that the webauthn1675045120206 was applied. Try deleting the database and recreating it