Added announcement support and list migrations.

This commit is contained in:
Benjamin A. Shelton 2026-10-26 15:27:46 -06:00
commit c85a59d2ad
Signed by: zancarius
GPG key ID: 8BD42DBD6C337E01
4 changed files with 52 additions and 9 deletions

View file

@ -18,3 +18,17 @@ func DoMigration(conf *settings.Settings) error {
return migrator.Up() 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
}

View file

@ -135,6 +135,7 @@ func (b *birthday) ListBirthdays(ctx context.Context, cmd *cli.Command) error {
logger.SetLevel(logging.Info) logger.SetLevel(logging.Info)
chatid := cmd.Int64("chatid") chatid := cmd.Int64("chatid")
annunciate := cmd.Bool("annunciate")
mdb := models.OpenDatabase(ctx, b.settings) mdb := models.OpenDatabase(ctx, b.settings)
if err := mdb.Open(); err != nil { 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) logger.Error("cannot parse date:", bday.Birthdate)
continue 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 return nil
} }

View file

@ -11,6 +11,7 @@ import (
"go.destrealm.net/embedder" "go.destrealm.net/embedder"
"go.destrealm.net/errors" "go.destrealm.net/errors"
"go.destrealm.net/logging/v3" "go.destrealm.net/logging/v3"
"go.destrealm.net/migratory"
"go.destrealm.net/vfs" "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 { func (inst *installer) DoUp(ctx context.Context, cmd *cli.Command) error {
return inst.DoInstall(ctx, cmd) 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
}

View file

@ -9,13 +9,14 @@ import (
) )
type Birthday struct { type Birthday struct {
ID int `db:"id"` ID int `db:"id"`
UserID *int `db:"userid"` UserID *int `db:"userid"`
ChatID int64 `db:"chatid"` ChatID int64 `db:"chatid"`
Name string `db:"name"` Name string `db:"name"`
Month int `db:"month"` Month int `db:"month"`
Day int `db:"day"` Day int `db:"day"`
Delta int `db:"leap_delta"` Delta int `db:"leap_delta"`
Announce bool `db:"announce"`
// Birthdate; computed field. // Birthdate; computed field.
Birthdate string `db:"birthdate"` Birthdate string `db:"birthdate"`
@ -61,6 +62,7 @@ func (bm *BirthdayModel) BirthdaysThisWeek(chatid int64) ([]*Birthday, error) {
format('%02d', month), '-', format('%02d', month), '-',
format('%02d', day))) as birthdate format('%02d', day))) as birthdate
from birthdays where from birthdays where
announce = true and
chatid = ? and chatid = ? and
birthdate != date('now', 'localtime') and birthdate != date('now', 'localtime') and
(birthdate >= date('now', 'localtime', 'weekday 0') 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', month), '-',
format('%02d', day))) as birthdate format('%02d', day))) as birthdate
from birthdays where from birthdays where
announce = true and
chatid = ? and chatid = ? and
birthdate == date('now', 'localtime') birthdate == date('now', 'localtime')
order by name;` order by name;`
@ -111,7 +114,7 @@ func (bm *BirthdayModel) BirthdaysToday(chatid int64) ([]*Birthday, error) {
func (bm *BirthdayModel) ListBirthdays(chatid int64) ([]*Birthday, error) { func (bm *BirthdayModel) ListBirthdays(chatid int64) ([]*Birthday, error) {
var bdays []*Birthday var bdays []*Birthday
q := `select q := `select
id, userid, chatid, name, leap_delta, id, userid, chatid, name, announce, leap_delta,
date(concat(strftime('%Y', date(concat(strftime('%Y',
date('now', 'localtime')), '-', date('now', 'localtime')), '-',
format('%02d', month), '-', format('%02d', month), '-',