feat: move schema_migrations into 000_bootstrap.sql #95

Open
clawbot wants to merge 2 commits from feature/schema-migrations-000sql into main
2 changed files with 24 additions and 5 deletions
Showing only changes of commit a883d708a2 - Show all commits

View File

@@ -135,13 +135,21 @@ type migration struct {
func (database *Database) runMigrations( func (database *Database) runMigrations(
ctx context.Context, ctx context.Context,
) error { ) error {
_, err := database.conn.ExecContext(ctx, bootstrap, err := SchemaFiles.ReadFile(
`CREATE TABLE IF NOT EXISTS schema_migrations ( "schema/000_bootstrap.sql",
version INTEGER PRIMARY KEY, )
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP)`)
if err != nil { if err != nil {
return fmt.Errorf( return fmt.Errorf(
"create schema_migrations: %w", err, "read bootstrap migration: %w", err,
)
}
_, err = database.conn.ExecContext(
ctx, string(bootstrap),
)
if err != nil {
return fmt.Errorf(
"execute bootstrap migration: %w", err,
) )
} }
@@ -270,6 +278,11 @@ func (database *Database) loadMigrations() (
continue continue
} }
// Skip bootstrap migration; it is executed separately.
if version == 0 {
continue
}
content, readErr := SchemaFiles.ReadFile( content, readErr := SchemaFiles.ReadFile(
"schema/" + entry.Name(), "schema/" + entry.Name(),
) )

View File

@@ -0,0 +1,6 @@
-- Bootstrap: create the schema_migrations table itself.
CREATE TABLE IF NOT EXISTS schema_migrations (
version INTEGER PRIMARY KEY,
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO schema_migrations (version) VALUES (0);