···
func Make(dbPath string) (*DB, error) {
30
-
db, err := sql.Open("sqlite3", dbPath+"?_foreign_keys=1")
30
+
// https://github.com/mattn/go-sqlite3#connection-string
33
+
"_journal_mode=WAL",
34
+
"_synchronous=NORMAL",
35
+
"_auto_vacuum=incremental",
38
+
db, err := sql.Open("sqlite3", dbPath+"?"+strings.Join(opts, "&"))
43
+
ctx := context.Background()
45
+
conn, err := db.Conn(ctx)
35
-
pragma journal_mode = WAL;
36
-
pragma synchronous = normal;
37
-
pragma temp_store = memory;
38
-
pragma mmap_size = 30000000000;
39
-
pragma page_size = 32768;
40
-
pragma auto_vacuum = incremental;
41
-
pragma busy_timeout = 5000;
51
+
_, err = conn.ExecContext(ctx, `
create table if not exists registrations (
id integer primary key autoincrement,
domain text not null unique,
···
470
-
runMigration(db, "add-description-to-repos", func(tx *sql.Tx) error {
479
+
runMigration(conn, "add-description-to-repos", func(tx *sql.Tx) error {
alter table repos add column description text check (length(description) <= 200);
477
-
runMigration(db, "add-rkey-to-pubkeys", func(tx *sql.Tx) error {
486
+
runMigration(conn, "add-rkey-to-pubkeys", func(tx *sql.Tx) error {
// add unconstrained column
···
500
-
runMigration(db, "add-rkey-to-comments", func(tx *sql.Tx) error {
509
+
runMigration(conn, "add-rkey-to-comments", func(tx *sql.Tx) error {
alter table comments drop column comment_at;
alter table comments add column rkey text;
···
508
-
runMigration(db, "add-deleted-and-edited-to-issue-comments", func(tx *sql.Tx) error {
517
+
runMigration(conn, "add-deleted-and-edited-to-issue-comments", func(tx *sql.Tx) error {
alter table comments add column deleted text; -- timestamp
alter table comments add column edited text; -- timestamp
···
516
-
runMigration(db, "add-source-info-to-pulls-and-submissions", func(tx *sql.Tx) error {
525
+
runMigration(conn, "add-source-info-to-pulls-and-submissions", func(tx *sql.Tx) error {
alter table pulls add column source_branch text;
alter table pulls add column source_repo_at text;
···
525
-
runMigration(db, "add-source-to-repos", func(tx *sql.Tx) error {
534
+
runMigration(conn, "add-source-to-repos", func(tx *sql.Tx) error {
alter table repos add column source text;
···
// NOTE: this cannot be done in a transaction, so it is run outside [0]
// [0]: https://sqlite.org/pragma.html#pragma_foreign_keys
536
-
db.Exec("pragma foreign_keys = off;")
537
-
runMigration(db, "recreate-pulls-column-for-stacking-support", func(tx *sql.Tx) error {
545
+
conn.ExecContext(ctx, "pragma foreign_keys = off;")
546
+
runMigration(conn, "recreate-pulls-column-for-stacking-support", func(tx *sql.Tx) error {
···
592
-
db.Exec("pragma foreign_keys = on;")
601
+
conn.ExecContext(ctx, "pragma foreign_keys = on;")
595
-
runMigration(db, "add-spindle-to-repos", func(tx *sql.Tx) error {
604
+
runMigration(conn, "add-spindle-to-repos", func(tx *sql.Tx) error {
alter table repos add column spindle text;
···
// recreate and add rkey + created columns with default constraint
603
-
runMigration(db, "rework-collaborators-table", func(tx *sql.Tx) error {
612
+
runMigration(conn, "rework-collaborators-table", func(tx *sql.Tx) error {
// - repo_at instead of repo integer
···
type migrationFn = func(*sql.Tx) error
662
-
func runMigration(d *sql.DB, name string, migrationFn migrationFn) error {
663
-
tx, err := d.Begin()
671
+
func runMigration(c *sql.Conn, name string, migrationFn migrationFn) error {
672
+
tx, err := c.BeginTx(context.Background(), nil)