From c85a59d2adde757bd906e518847e4e34c56fbf69 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Mon, 26 Oct 2026 15:27:46 -0600 Subject: [PATCH] Added announcement support and list migrations. --- internal/app/migration.go | 14 ++++++++++++++ internal/commands/birthdays.go | 9 ++++++++- internal/commands/install.go | 19 +++++++++++++++++++ internal/models/birthdays.go | 19 +++++++++++-------- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/internal/app/migration.go b/internal/app/migration.go index d2beec0..877da5d 100644 --- a/internal/app/migration.go +++ b/internal/app/migration.go @@ -18,3 +18,17 @@ func DoMigration(conf *settings.Settings) error { return migrator.Up() } + +func ListMigrations(conf *settings.Settings) ([]string, error) { + mg, err := migratory.New(conf.System.DSN) + if err != nil { + return []string{}, err + } + mg.UsingVFS(conf.FS) + migrator, err := mg.Migrate("migrations/sqlite") + if err != nil { + return []string{}, err + } + + return migrator.Migrations(), nil +} diff --git a/internal/commands/birthdays.go b/internal/commands/birthdays.go index e1efa6c..e62f378 100644 --- a/internal/commands/birthdays.go +++ b/internal/commands/birthdays.go @@ -135,6 +135,7 @@ func (b *birthday) ListBirthdays(ctx context.Context, cmd *cli.Command) error { logger.SetLevel(logging.Info) chatid := cmd.Int64("chatid") + annunciate := cmd.Bool("annunciate") mdb := models.OpenDatabase(ctx, b.settings) if err := mdb.Open(); err != nil { @@ -165,7 +166,13 @@ func (b *birthday) ListBirthdays(ctx context.Context, cmd *cli.Command) error { logger.Error("cannot parse date:", bday.Birthdate) continue } - logger.Infof(" • %s (%s)", bday.Name, d.Format("January 2")) + if annunciate { + logger.Infof(" • %s (%s) (announce: %v)", bday.Name, + d.Format("January 2"), bday.Announce) + } else { + logger.Infof(" • %s (%s)", bday.Name, + d.Format("January 2")) + } } return nil } diff --git a/internal/commands/install.go b/internal/commands/install.go index 08d03da..b886988 100644 --- a/internal/commands/install.go +++ b/internal/commands/install.go @@ -11,6 +11,7 @@ import ( "go.destrealm.net/embedder" "go.destrealm.net/errors" "go.destrealm.net/logging/v3" + "go.destrealm.net/migratory" "go.destrealm.net/vfs" ) @@ -52,3 +53,21 @@ 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) } + +func (inst *installer) ListMigrations(ctx context.Context, cmd *cli.Command) error { + mg, err := migratory.New(inst.settings.System.DSN) + if err != nil { + return err + } + mg.UsingVFS(inst.fs) + migrator, err := mg.Migrate("migrations/sqlite") + if err != nil { + return err + } + + for _, m := range migrator.Migrations() { + fmt.Println(m) + } + + return nil +} diff --git a/internal/models/birthdays.go b/internal/models/birthdays.go index 47dd27c..b1b77a2 100644 --- a/internal/models/birthdays.go +++ b/internal/models/birthdays.go @@ -9,13 +9,14 @@ import ( ) type Birthday struct { - ID int `db:"id"` - UserID *int `db:"userid"` - ChatID int64 `db:"chatid"` - Name string `db:"name"` - Month int `db:"month"` - Day int `db:"day"` - Delta int `db:"leap_delta"` + ID int `db:"id"` + UserID *int `db:"userid"` + ChatID int64 `db:"chatid"` + Name string `db:"name"` + Month int `db:"month"` + Day int `db:"day"` + Delta int `db:"leap_delta"` + Announce bool `db:"announce"` // Birthdate; computed field. Birthdate string `db:"birthdate"` @@ -61,6 +62,7 @@ func (bm *BirthdayModel) BirthdaysThisWeek(chatid int64) ([]*Birthday, error) { format('%02d', month), '-', format('%02d', day))) as birthdate from birthdays where + announce = true and chatid = ? and birthdate != date('now', 'localtime') and (birthdate >= date('now', 'localtime', 'weekday 0') and @@ -89,6 +91,7 @@ func (bm *BirthdayModel) BirthdaysToday(chatid int64) ([]*Birthday, error) { format('%02d', month), '-', format('%02d', day))) as birthdate from birthdays where + announce = true and chatid = ? and birthdate == date('now', 'localtime') order by name;` @@ -111,7 +114,7 @@ func (bm *BirthdayModel) BirthdaysToday(chatid int64) ([]*Birthday, error) { func (bm *BirthdayModel) ListBirthdays(chatid int64) ([]*Birthday, error) { var bdays []*Birthday q := `select - id, userid, chatid, name, leap_delta, + id, userid, chatid, name, announce, leap_delta, date(concat(strftime('%Y', date('now', 'localtime')), '-', format('%02d', month), '-',