diff --git a/internal/commands/install.go b/internal/commands/install.go index b886988..a74a616 100644 --- a/internal/commands/install.go +++ b/internal/commands/install.go @@ -4,11 +4,9 @@ import ( "context" "fmt" - "code.destrealm.net/zancarius/justusbot/internal/app" "code.destrealm.net/zancarius/justusbot/internal/models" "code.destrealm.net/zancarius/justusbot/internal/settings" "github.com/urfave/cli/v3" - "go.destrealm.net/embedder" "go.destrealm.net/errors" "go.destrealm.net/logging/v3" "go.destrealm.net/migratory" @@ -35,11 +33,13 @@ func (inst *installer) DoInstall(ctx context.Context, cmd *cli.Command) error { // // This code is being added here to support embedded migrations in the // future. - efs := embedder.NewEmbedderVFS(app.LoadBucket("migrations")) + /*efs := embedder.NewEmbedderVFS(app.LoadBucket("migrations")) lfs := vfs.NewLayeredFS() lfs.AddFS(efs) - lfs.AddFS(inst.fs) + lfs.AddFS(inst.fs)*/ + lfs := inst.fs.Clone() + _ = lfs.Chdir("migrations/base/sqlite") db := models.OpenDatabase(ctx, inst.settings) fmt.Println("migrated database:", inst.settings.System.DSN) @@ -51,7 +51,16 @@ func (inst *installer) DoInstall(ctx context.Context, cmd *cli.Command) error { } func (inst *installer) DoUp(ctx context.Context, cmd *cli.Command) error { - return inst.DoInstall(ctx, cmd) + lfs := inst.fs.Clone() + _ = lfs.Chdir("migrations/sqlite") + + db := models.OpenDatabase(ctx, inst.settings) + fmt.Println("migrated database:", inst.settings.System.DSN) + err := db.Migrate(lfs) + if err != nil { + inst.logger.Error(errors.Unfurl(err)) + } + return nil } func (inst *installer) ListMigrations(ctx context.Context, cmd *cli.Command) error { diff --git a/migrations/base/sqlite/0003_table_updates.sql b/migrations/base/sqlite/0003_table_updates.sql new file mode 100644 index 0000000..1124f39 --- /dev/null +++ b/migrations/base/sqlite/0003_table_updates.sql @@ -0,0 +1,10 @@ +-- @up + +alter table birthdays add column announce boolean default true not null; + +-- Anniversaries will be re-added in the future, either as a base table for +-- wedding anniversaries + birthdays or as a single purpose table. If the +-- former, anniversary types will be implemented as views, and the INSTEAD OF +-- trigger will be used for inserts and updates: +-- www.sqlite.org/lang_createtrigger.html#instead_of_trigger +drop table anniversaries; \ No newline at end of file diff --git a/migrations/base/sqlite/base_initial-layout.sql b/migrations/base/sqlite/base_initial-layout.sql index be30349..c36f06c 100644 --- a/migrations/base/sqlite/base_initial-layout.sql +++ b/migrations/base/sqlite/base_initial-layout.sql @@ -1,4 +1,5 @@ -- @up +-- @version=0002 -- Members and member metadata. @@ -193,7 +194,7 @@ create table verse_rotation ( verseid integer primary key, foreign key (verseid) references verses(id) ); -create unique index verse_rotation_verseid_chatid_idx on verse_rotation (verseid, chatid); +create unique index verse_rotation_verseid_chatid_idx on verse_rotation (verseid); create table verses_submitter ( verseid integer not null,