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.47k stars 252 forks source link

[PostgreSQL] Relation already exists error #651

Open Featyre opened 2 years ago

Featyre commented 2 years ago

This is an error that I have never seen before, before I was running PostgreSQL just fine, however upgrading to the latest git revision makes this error appear.

QueryFailedError: constraint "FK_05535bc695e9f7ee104616459d3" for relation "messages" already exists
    at QueryFailedError.TypeORMError [as constructor] (/root/fosscord-server/bundle/node_modules/typeorm/error/TypeORMError.js:9:28)
    at new QueryFailedError (/root/fosscord-server/bundle/node_modules/typeorm/error/QueryFailedError.js:13:28)
    at PostgresQueryRunner.<anonymous> (/root/fosscord-server/bundle/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:277:31)
    at step (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:143:27)
    at Object.throw (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:124:57)
    at rejected (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:115:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  query: 'ALTER TABLE "messages" ADD CONSTRAINT "FK_05535bc695e9f7ee104616459d3" FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION',
  parameters: undefined,
  driverError: error: constraint "FK_05535bc695e9f7ee104616459d3" for relation "messages" already exists
      at Parser.parseErrorMessage (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:287:98)
      at Parser.handlePacket (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:126:29)
      at Parser.parse (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:39:38)
      at Socket.<anonymous> (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/index.js:11:42)
      at Socket.emit (node:events:520:28)
      at Socket.emit (node:domain:475:12)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
    length: 150,
    severity: 'ERROR',
    code: '42710',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'tablecmds.c',
    line: '8227',
    routine: 'ATExecAddConstraint'
  },
  length: 150,
  severity: 'ERROR',
  code: '42710',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'tablecmds.c',
  line: '8227',
  routine: 'ATExecAddConstraint'
}
QueryFailedError: constraint "FK_05535bc695e9f7ee104616459d3" for relation "messages" already exists
    at QueryFailedError.TypeORMError [as constructor] (/root/fosscord-server/bundle/node_modules/typeorm/error/TypeORMError.js:9:28)
    at new QueryFailedError (/root/fosscord-server/bundle/node_modules/typeorm/error/QueryFailedError.js:13:28)
    at PostgresQueryRunner.<anonymous> (/root/fosscord-server/bundle/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:277:31)
    at step (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:143:27)
    at Object.throw (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:124:57)
    at rejected (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:115:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  query: 'ALTER TABLE "messages" ADD CONSTRAINT "FK_05535bc695e9f7ee104616459d3" FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION',
  parameters: undefined,
  driverError: error: constraint "FK_05535bc695e9f7ee104616459d3" for relation "messages" already exists
      at Parser.parseErrorMessage (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:287:98)
      at Parser.handlePacket (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:126:29)
      at Parser.parse (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:39:38)
      at Socket.<anonymous> (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/index.js:11:42)
      at Socket.emit (node:events:520:28)
      at Socket.emit (node:domain:475:12)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
    length: 150,
    severity: 'ERROR',
    code: '42710',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'tablecmds.c',
    line: '8227',
    routine: 'ATExecAddConstraint'
  },
  length: 150,
  severity: 'ERROR',
  code: '42710',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'tablecmds.c',
  line: '8227',
  routine: 'ATExecAddConstraint'
} Promise {
  <rejected> QueryFailedError: constraint "FK_05535bc695e9f7ee104616459d3" for relation "messages" already exists
      at QueryFailedError.TypeORMError [as constructor] (/root/fosscord-server/bundle/node_modules/typeorm/error/TypeORMError.js:9:28)
      at new QueryFailedError (/root/fosscord-server/bundle/node_modules/typeorm/error/QueryFailedError.js:13:28)
      at PostgresQueryRunner.<anonymous> (/root/fosscord-server/bundle/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:277:31)
      at step (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:143:27)
      at Object.throw (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:124:57)
      at rejected (/root/fosscord-server/bundle/node_modules/tslib/tslib.js:115:69)
      at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    query: 'ALTER TABLE "messages" ADD CONSTRAINT "FK_05535bc695e9f7ee104616459d3" FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION',
    parameters: undefined,
    driverError: error: constraint "FK_05535bc695e9f7ee104616459d3" for relation "messages" already exists
        at Parser.parseErrorMessage (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:287:98)
        at Parser.handlePacket (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:126:29)
        at Parser.parse (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/parser.js:39:38)
        at Socket.<anonymous> (/root/fosscord-server/bundle/node_modules/pg-protocol/dist/index.js:11:42)
        at Socket.emit (node:events:520:28)
        at Socket.emit (node:domain:475:12)
        at addChunk (node:internal/streams/readable:315:12)
        at readableAddChunk (node:internal/streams/readable:289:9)
        at Socket.Readable.push (node:internal/streams/readable:228:10)
        at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
      length: 150,
      severity: 'ERROR',
      code: '42710',
      detail: undefined,
      hint: undefined,
      position: undefined,
      internalPosition: undefined,
      internalQuery: undefined,
      where: undefined,
      schema: undefined,
      table: undefined,
      column: undefined,
      dataType: undefined,
      constraint: undefined,
      file: 'tablecmds.c',
      line: '8227',
      routine: 'ATExecAddConstraint'
    },
    length: 150,
    severity: 'ERROR',
    code: '42710',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'tablecmds.c',
    line: '8227',
    routine: 'ATExecAddConstraint'
  }
}
1itt1eB0y commented 2 years ago

I met this problem too. And I found out this was caused by a PR https://github.com/fosscord/fosscord-server/commit/49426b11472c8679168f84de0d5e4aca68e095af You should consider to rollback or modify the file util\src\entities\Message.ts yourself