Public
Script
Forked from saolsen/sqlite_migrations_example
December 21, 2023
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
28
29
30
31
32
33
34
35
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { migrate, Migrations, undo } from "https://esm.town/v/saolsen/sqlite_migrations";
const { name } = extractValInfo(import.meta.url);
const MIGRATIONS: Migrations = {
name,
migrations: [
{
name: `example_user table`,
up: `create table example_user (
id integer primary key autoincrement,
username text not null
) strict`,
down: `drop table example_user`,
},
{
name: `example_user username index`,
up: `create unique index idx_example_user_username on example_user (username)`,
down: `drop index idx_example_user_username`,
},
// Try running once to see the above created.
// Then try running again to see that they don't run again since they were already run.
// Then uncomment the below migration and run again to see that only the last one is run.
// {
// name: `another table`,
// up: `create table another_table (
// id integer primary key autoincrement
// ) strict`,
// down: `drop table another_table`,
// },
],
};
await migrate(MIGRATIONS);
// await undo(MIGRATIONS);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 21, 2023