Closed krumft closed 11 months ago
I will look into providing a fix for that.
Problem reproduced with this simpler test:
it('can drop constraint after dropping an index on the same column', () => {
none(`create table test (col text);
alter table test add constraint uq unique (col);
create index idx on test(col);
drop index idx;
alter table test drop constraint uq;
`);
});
which gives
Error: Cannot drop index that does not belong to this table: uq
🐜 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.
*️⃣ Reconsituted failed SQL statement: ALTER TABLE test DROP CONSTRAINT uq
👉 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.dropIndex (src/table.ts:667:19)
at IndexConstraint.uninstall (src/constraints/index-cst.ts:9:20)
at Alter.execute (src/execution/schema-amends/alter.ts:67:25)
It seems that this is due to a limitation in the internal model, which treats unique constraints as indexes, and allows at most one index over a given column. When that index is dropped the constraint cannot be dropped, as we already have no indexes for that same column. Hence the error.
Raised https://github.com/oguimbal/pg-mem/pull/333 to fix this.
Our application is using
typeorm
version0.3.16
against a Postgres database, and we maintain our DB schema in TypeScript migrations. These are getting executed successfully by the ORM framework against the 'real' Postgres db.We are using
pg-mem
version2.6.12
to create some unit and integration tests for our application.Following scenario is failing for us, it is taken from a real-world migration that succeeds against Postgres:
fails with:
If we comment the last line that drops
"UQ_constraint"
the migration succeeds.