blob: e977960de477282f8a82b3edbebf2955542af6f1 (
plain)
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
36
37
|
package database
import "database/sql"
// allMigrations is the list of migrations to perform to get an up to date database
// Order is important. Add new migrations at the end of the list.
var allMigrations = []func(tx *sql.Tx) error{
func(tx *sql.Tx) (err error) {
sql := `
CREATE TABLE schema_version (
version INTEGER NOT NULL
);
CREATE TABLE users (
id INTEGER PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
hash TEXT,
email TEXT,
created_at DATE DEFAULT (datetime('now')),
last_login_at DATE DEFAULT NULL
);
CREATE TABLE sessions (
token TEXT PRIMARY KEY,
user_id INTEGER NOT NULL,
created_at DATE DEFAULT (datetime('now')),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE train_stops (
id TEXT PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);`
_, err = tx.Exec(sql)
return err
},
}
// This variable exists so that tests can override it
var migrations = allMigrations
|