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
import { migrate, Migrations, undo } from "https://esm.town/v/saolsen/sqlite_migrations";
const MIGRATIONS: Migrations = {
name: "test_migrations",
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);
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.