pg-mem
pg-mem copied to clipboard
Deleting and re-creating table with primary key fails
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