49 lines
945 B
Go
49 lines
945 B
Go
package ismdb
|
|
|
|
import (
|
|
_ "embed"
|
|
"errors"
|
|
|
|
"zombiezen.com/go/sqlite"
|
|
"zombiezen.com/go/sqlite/sqlitemigration"
|
|
)
|
|
|
|
const appID int32 = 0x157db
|
|
|
|
//go:embed schema-00.sql
|
|
var schema0 string
|
|
|
|
//go:embed schema-01.sql
|
|
var schema1 string
|
|
|
|
//go:embed schema-02.sql
|
|
var schema2 string
|
|
|
|
//go:embed schema-final.sql
|
|
var schemaFinal string
|
|
|
|
func Open(uri string) *sqlitemigration.Pool {
|
|
schema := sqlitemigration.Schema{
|
|
Migrations: []string{
|
|
schema0,
|
|
schema1,
|
|
schema2,
|
|
},
|
|
AppID: appID,
|
|
RepeatableMigration: schemaFinal,
|
|
}
|
|
opts := sqlitemigration.Options{
|
|
Flags: sqlite.OpenReadWrite | sqlite.OpenCreate | sqlite.OpenURI,
|
|
PrepareConn: func(conn *sqlite.Conn) error {
|
|
stmt, _, err := conn.PrepareTransient(`PRAGMA journal_mode=WAL`)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = stmt.Step()
|
|
return errors.Join(err, stmt.Finalize())
|
|
},
|
|
}
|
|
db := sqlitemigration.NewPool(uri, schema, opts)
|
|
return db
|
|
}
|