Knowing when drizzle finished Migration/Pushed.

Hi, I'm new to DrizzleORM and backend development as a whole. I'm using Drizzle BetterSQLite3 with SvelteKit. I'm trying to execute raw SQL commands to create some triggers for backups. Currently, I'm doing it like this
await db.transaction(async (tx) => {
tx.run(sql`
CREATE TRIGGER IF NOT EXISTS TRG_CT_INSERT_BACKUP
AFTER INSERT ON CauThu
BEGIN
INSERT INTO CauThuBackup(modifiedDate, maCT, tenCT, ngaySinh, loaiCT, ghiChu, nuocNgoai)
VALUES(datetime('now'), NEW.maCT, NEW.tenCT, NEW.ngaySinh, NEW.loaiCT, NEW.ghiChu, NEW.nuocNgoai);
END
`);
});
await db.transaction(async (tx) => {
tx.run(sql`
CREATE TRIGGER IF NOT EXISTS TRG_CT_INSERT_BACKUP
AFTER INSERT ON CauThu
BEGIN
INSERT INTO CauThuBackup(modifiedDate, maCT, tenCT, ngaySinh, loaiCT, ghiChu, nuocNgoai)
VALUES(datetime('now'), NEW.maCT, NEW.tenCT, NEW.ngaySinh, NEW.loaiCT, NEW.ghiChu, NEW.nuocNgoai);
END
`);
});
This is the triggers to create backup for the data where it just copy every fields. When i run drizzle-kit push it will catch error saying the CauThu table doesn't exists. But when i run dev for SvelteKit, it doesn't log any error. I think i'm running it before Drizzle has even create any table, but i don't know how to wait until drizzle create the database or after Drizzle has finished migrated. Can someone help me? I'm sorry for my bad English
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?