oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.89k stars 94 forks source link

Deleting and re-creating table with primary key fails #358

Open zookatron opened 10 months ago

zookatron commented 10 months ago

Describe the bug

QueryError: create table "devices" ("id" serial primary key) - relation "devices_pkey" already exists

šŸœ This seems to be an execution error, which means that your request syntax seems okay,
    but the resulting statement cannot be executed ā†’ Probably not a pg-mem error.

*ļøāƒ£ Failed SQL statement: create table "devices" ("id" serial primary key);

šŸ‘‰ You can file an issue at https://github.com/oguimbal/pg-mem along with a way to reproduce this error (if you can), and  the stacktrace:

    at MemoryTable.determineIndexRelName (/node_modules/pg-mem/index.js:8387:23)
    at MemoryTable.createIndex (/node_modules/pg-mem/index.js:8354:32)
    at ColRef.addConstraints (/node_modules/pg-mem/index.js:9880:32)
    at MemoryTable.addColumn (/node_modules/pg-mem/index.js:8007:22)
    at new MemoryTable (/node_modules/pg-mem/index.js:7918:18)
    at DbSchema.declareTable (/node_modules/pg-mem/index.js:6701:21)
    at /node_modules/pg-mem/index.js:10982:25
    at checkExistence (/node_modules/pg-mem/index.js:2179:5)
    at ExecuteCreateTable.execute (/node_modules/pg-mem/index.js:10981:41)
    at /node_modules/pg-mem/index.js:5975:42 {
  data: { error: 'relation "devices_pkey" already exists', code: undefined },
  code: undefined,
  location: { start: 0, end: 0 },
  [Symbol(errorDetailsIncluded)]: true
}

To Reproduce

package.json:

{
  "type": "module",
  "dependencies": {
    "knex": "2.5.1",
    "pg-mem": "2.6.13"
  }
}

index.js:

import { newDb } from "pg-mem";

const database = newDb();
const knex = database.adapters.createKnex();

await knex.schema.createTable('devices', (table) => table.uuid('id').primary());
await knex.schema.dropTable('devices');
await knex.schema.createTable('devices', (table) => table.increments('id').primary());

knex.destroy();

pg-mem version

2.6.13