fix: normalize drizzle migration timestamp
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
This commit is contained in:
parent
d3be8e7a42
commit
c04219cbf7
1 changed files with 16 additions and 0 deletions
|
|
@ -19,6 +19,20 @@ export const db = drizzle({ client: sqlite, relations, schema });
|
||||||
|
|
||||||
let migrationsPromise: Promise<void> | undefined;
|
let migrationsPromise: Promise<void> | undefined;
|
||||||
|
|
||||||
|
const normalizeLegacyMigrationTimestamps = () => {
|
||||||
|
const drizzleMigrationsTableExists = sqlite
|
||||||
|
.query("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = '__drizzle_migrations' LIMIT 1")
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (!drizzleMigrationsTableExists) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite.run(
|
||||||
|
"UPDATE __drizzle_migrations SET created_at = CAST(created_at / 1000 AS INTEGER) * 1000 WHERE created_at % 1000 != 0",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const runMigrations = async () => {
|
const runMigrations = async () => {
|
||||||
let migrationsFolder: string;
|
let migrationsFolder: string;
|
||||||
|
|
||||||
|
|
@ -30,6 +44,8 @@ const runMigrations = async () => {
|
||||||
migrationsFolder = path.join(process.cwd(), "app", "drizzle");
|
migrationsFolder = path.join(process.cwd(), "app", "drizzle");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalizeLegacyMigrationTimestamps();
|
||||||
|
|
||||||
migrate(db, { migrationsFolder });
|
migrate(db, { migrationsFolder });
|
||||||
|
|
||||||
sqlite.run("PRAGMA foreign_keys = ON;");
|
sqlite.run("PRAGMA foreign_keys = ON;");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue