Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 9a25a30

Browse files
Merge pull request #98 from fanshaohua-fan/bugfix/sequence_not_reset_on_not_public_schema
bugfix: the sequence is not reset when using other schema(not public)
2 parents ce1f694 + 00ee8c9 commit 9a25a30

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

v3-sql-v4-sql/migrate/helpers/migrate.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ async function migrate(source, destination, itemMapper = undefined) {
9999
console.log(`Migrating ${count} items from ${source} to ${destination}`);
100100
await dbV4(resolveDestTableName(destination)).del();
101101

102-
let tableColumnsInfo = await dbV4(destination).withSchema(process.env.DATABASE_V4_SCHEMA).columnInfo();
102+
let tableColumnsInfo = await dbV4(destination)
103+
.withSchema(process.env.DATABASE_V4_SCHEMA)
104+
.columnInfo();
103105

104106
if (isPGSQL) {
105107
// https://github.com/knex/knex/issues/1490
@@ -161,10 +163,13 @@ async function migrate(source, destination, itemMapper = undefined) {
161163

162164
async function resetTableSequence(destination) {
163165
if (isPGSQL) {
164-
const hasId = await dbV4.schema.hasColumn(destination, 'id');
166+
const schema = process.env.DATABASE_V4_SCHEMA ?? 'public';
167+
const hasId = await dbV4.schema.withSchema(schema).hasColumn(destination, 'id');
165168
if (hasId) {
166169
const seq = `${destination.slice(0, 56)}_id_seq`;
167-
await dbV4.raw(`SELECT SETVAL ('${seq}', (SELECT MAX(id) + 1 FROM "${destination}"))`);
170+
await dbV4.raw(
171+
`SELECT SETVAL ('${schema}.${seq}', (SELECT MAX(id) + 1 FROM ${schema}."${destination}"))`
172+
);
168173
}
169174
}
170175
}

0 commit comments

Comments
 (0)