uid is required to be unique for the the Changed Events (with the new Data) to be inserted without creating new Rows.
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import db from "../src/sql";
|
|
|
|
const run_migration = db.transaction(() => {
|
|
// SQL 1: Insert a new user
|
|
db.run(`DELETE FROM events
|
|
WHERE rowid NOT IN (
|
|
SELECT MIN(rowid)
|
|
FROM events
|
|
GROUP BY uid
|
|
);`);
|
|
|
|
// SQL 2: Update product stock
|
|
db.run(`CREATE TABLE events_new (
|
|
"event_uid" INTEGER PRIMARY KEY,
|
|
"uid" TEXT NOT NULL UNIQUE,
|
|
"title" TEXT NOT NULL,
|
|
"date_at" DATETIME NOT NULL,
|
|
"time_start" TEXT NOT NULL,
|
|
"time_end" TEXT NOT NULL,
|
|
"posted_by" TEXT NOT NULL,
|
|
"location" TEXT NOT NULL,
|
|
"event_type" TEXT NOT NULL,
|
|
"link" TEXT NOT NULL,
|
|
"description" TEXT NOT NULL,
|
|
"timezone" TEXT NOT NULL,
|
|
"notification" TEXT NOT NULL,
|
|
"deleteDate" INTEGER NULL
|
|
);`);
|
|
|
|
// SQL 3: Log the transaction
|
|
db.run(`INSERT INTO events_new (event_uid, uid, title, date_at, time_start, time_end, posted_by, location, event_type, link, description, timezone, notification, deleteDate)
|
|
SELECT event_uid, uid, title, date_at, time_start, time_end, posted_by, location, event_type, link, description, timezone, notification, deleteDate FROM events;
|
|
`);
|
|
db.run(`DROP TABLE events;
|
|
ALTER TABLE events_new RENAME TO events;`);
|
|
});
|
|
|
|
// Run the transaction
|
|
run_migration(); |