-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0000_sample_migration.mjs
27 lines (23 loc) · 1.11 KB
/
0000_sample_migration.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Automatically created by 'sqlite auto migrator (SAM)' on 2021-08-15 20:00:00
import { Database } from 'sqlite-auto-migrator';
// Pragmas can't be changed in transactions, so they are tracked separately.
// Note that most pragmas are not persisted in the database file and will have to be set on each new connection.
export const PRAGMAS = { foreign_keys: 0, journal_mode: 'delete' };
/**
* Runs the necessary SQL commands to migrate the database up to this version from the previous version.
* Automatically runs in a transaction with deferred foreign keys.
* @param {Database} db database instance to run SQL commands on
*/
export async function up(db) {
await db.run(
'CREATE TABLE IF NOT EXISTS sample_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)',
);
}
/**
* Runs the necessary SQL commands to migrate the database down to the previous version from this version.
* Automatically runs in a transaction with deferred foreign keys.
* @param {Database} db database instance to run SQL commands on
*/
export async function down(db) {
await db.run('DROP TABLE IF EXISTS sample_table');
}