···
func Make(dbPath string) (*DB, error) {
-
db, err := sql.Open("sqlite3", dbPath+"?_foreign_keys=1")
-
pragma journal_mode = WAL;
-
pragma synchronous = normal;
-
pragma temp_store = memory;
-
pragma mmap_size = 30000000000;
-
pragma page_size = 32768;
-
pragma auto_vacuum = incremental;
-
pragma busy_timeout = 5000;
create table if not exists registrations (
id integer primary key autoincrement,
domain text not null unique,
···
-
runMigration(db, "add-description-to-repos", func(tx *sql.Tx) error {
alter table repos add column description text check (length(description) <= 200);
-
runMigration(db, "add-rkey-to-pubkeys", func(tx *sql.Tx) error {
// add unconstrained column
···
-
runMigration(db, "add-rkey-to-comments", func(tx *sql.Tx) error {
alter table comments drop column comment_at;
alter table comments add column rkey text;
···
-
runMigration(db, "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
···
-
runMigration(db, "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;
···
-
runMigration(db, "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
-
db.Exec("pragma foreign_keys = off;")
-
runMigration(db, "recreate-pulls-column-for-stacking-support", func(tx *sql.Tx) error {
···
-
db.Exec("pragma foreign_keys = on;")
-
runMigration(db, "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
-
runMigration(db, "rework-collaborators-table", func(tx *sql.Tx) error {
// - repo_at instead of repo integer
···
type migrationFn = func(*sql.Tx) error
-
func runMigration(d *sql.DB, name string, migrationFn migrationFn) error {
···
func Make(dbPath string) (*DB, error) {
+
// https://github.com/mattn/go-sqlite3#connection-string
+
"_auto_vacuum=incremental",
+
db, err := sql.Open("sqlite3", dbPath+"?"+strings.Join(opts, "&"))
+
ctx := context.Background()
+
conn, err := db.Conn(ctx)
+
_, err = conn.ExecContext(ctx, `
create table if not exists registrations (
id integer primary key autoincrement,
domain text not null unique,
···
+
runMigration(conn, "add-description-to-repos", func(tx *sql.Tx) error {
alter table repos add column description text check (length(description) <= 200);
+
runMigration(conn, "add-rkey-to-pubkeys", func(tx *sql.Tx) error {
// add unconstrained column
···
+
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;
···
+
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
···
+
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;
···
+
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
+
conn.ExecContext(ctx, "pragma foreign_keys = off;")
+
runMigration(conn, "recreate-pulls-column-for-stacking-support", func(tx *sql.Tx) error {
···
+
conn.ExecContext(ctx, "pragma foreign_keys = on;")
+
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
+
runMigration(conn, "rework-collaborators-table", func(tx *sql.Tx) error {
// - repo_at instead of repo integer
···
type migrationFn = func(*sql.Tx) error
+
func runMigration(c *sql.Conn, name string, migrationFn migrationFn) error {
+
tx, err := c.BeginTx(context.Background(), nil)