helpbuttons / hb-back

backend for helpbuttons
GNU Affero General Public License v3.0
4 stars 2 forks source link

move seeding the database from a migration to a sole command #114

Closed albjeremias closed 2 years ago

albjeremias commented 2 years ago

Can be using typeorm-seed https://github.com/w3tecch/typeorm-seeding

or using nestjs-console: https://stackoverflow.com/questions/51198817/typeorm-how-to-seed-database

here is the harmful code: https://github.com/helpbuttons/hb-back/blob/develop/src/migrations/1658150010023-SEED_DATA.ts

albjeremias commented 2 years ago

migrations not running properly?

ELECT "User"."created_at" AS "User_created_at", "User"."updated_at" AS "User_updated_at", "User"."id" AS "User_id", "User"."realm" AS "User_realm", "User"."username" AS "User_username", "User"."email_verified" AS "User_email_verified", "User"."verification_token" AS "User_verification_token", "User"."roles" AS "User_roles" FROM "user" "User" WHERE "User"."id" IN ($1) -- PARAMETERS: ["3Oybp4tJgu_yDeyhHFAFxxfaCwxV5Dv9vJ9e"]
query failed: SELECT "User"."created_at" AS "User_created_at", "User"."updated_at" AS "User_updated_at", "User"."id" AS "User_id", "User"."realm" AS "User_realm", "User"."username" AS "User_username", "User"."email_verified" AS "User_email_verified", "User"."verification_token" AS "User_verification_token", "User"."roles" AS "User_roles" FROM "user" "User" WHERE "User"."id" IN ($1) -- PARAMETERS: ["3Oybp4tJgu_yDeyhHFAFxxfaCwxV5Dv9vJ9e"]
error: error: relation "user" does not exist
    at Parser.parseErrorMessage (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/parser.ts:369:69)
    at Parser.handlePacket (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/parser.ts:188:21)
    at Parser.parse (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/parser.ts:103:30)
    at Socket.<anonymous> (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (node:events:527: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: 104,
  severity: 'ERROR',
  code: '42P01',
  detail: undefined,
  hint: undefined,
  position: '332',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_relation.c',
  line: '1373',
  routine: 'parserOpenTable'
}
Migration "SEEDDATA1658150010023" failed, error: relation "user" does not exist
query: ROLLBACK
Error during migration run:
QueryFailedError: relation "user" does not exist
    at QueryFailedError.TypeORMError [as constructor] (/home/ajeremias/devel/hb/hb-back/node_modules/src/error/TypeORMError.ts:7:9)
    at new QueryFailedError (/home/ajeremias/devel/hb/hb-back/node_modules/src/error/QueryFailedError.ts:9:9)
    at PostgresQueryRunner.<anonymous> (/home/ajeremias/devel/hb/hb-back/node_modules/typeorm/src/driver/postgres/PostgresQueryRunner.ts:263:19)
    at step (/home/ajeremias/devel/hb/hb-back/node_modules/tslib/tslib.js:144:27)
    at Object.throw (/home/ajeremias/devel/hb/hb-back/node_modules/tslib/tslib.js:125:57)
    at rejected (/home/ajeremias/devel/hb/hb-back/node_modules/tslib/tslib.js:116:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  query: 'SELECT "User"."created_at" AS "User_created_at", "User"."updated_at" AS "User_updated_at", "User"."id" AS "User_id", "User"."realm" AS "User_realm", "User"."username" AS "User_username", "User"."email_verified" AS "User_email_verified", "User"."verification_token" AS "User_verification_token", "User"."roles" AS "User_roles" FROM "user" "User" WHERE "User"."id" IN ($1)',
  parameters: [ '3Oybp4tJgu_yDeyhHFAFxxfaCwxV5Dv9vJ9e' ],
  driverError: error: relation "user" does not exist
      at Parser.parseErrorMessage (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/parser.ts:369:69)
      at Parser.handlePacket (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/parser.ts:188:21)
      at Parser.parse (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/parser.ts:103:30)
      at Socket.<anonymous> (/home/ajeremias/devel/hb/hb-back/node_modules/pg-protocol/src/index.ts:7:48)
      at Socket.emit (node:events:527: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: 104,
    severity: 'ERROR',
    code: '42P01',
    detail: undefined,
    hint: undefined,
    position: '332',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '1373',
    routine: 'parserOpenTable'
  },
  length: 104,
  severity: 'ERROR',
  code: '42P01',