Skip to content

Commit

Permalink
Allow using postgres as database
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed May 20, 2023
1 parent e159c54 commit cdb355e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"maunium.net/go/mautrix/synapseadmin"
"maunium.net/go/mautrix/util"
"maunium.net/go/mautrix/util/dbutil"
_ "maunium.net/go/mautrix/util/dbutil/litestream"

"github.com/beeper/botbot/upgrades"
)
Expand All @@ -36,6 +37,7 @@ type Config struct {
Username string `env:"USERNAME,notEmpty"`
Password string `env:"PASSWORD,notEmpty"`
DatabasePath string `env:"DATABASE_PATH" envDefault:"botbot.db"`
DatabaseType string `env:"DATABASE_TYPE" envDefault:"sqlite3-fk-wal"`
PickleKey string `env:"PICKLE_KEY" envDefault:"meow"`

BeeperAPIURL string `env:"BEEPER_API_URL"`
Expand Down Expand Up @@ -87,11 +89,11 @@ func main() {
synadm = &synapseadmin.Client{Client: cli}

log.Debug().Msg("Initializing database")
rawDB, err := dbutil.NewWithDialect(cfg.DatabasePath, "sqlite3")
rawDB, err := dbutil.NewWithDialect(cfg.DatabasePath, cfg.DatabaseType)
if err != nil {
log.Fatal().Err(err).Msg("Failed to initialize database")
}
rawDB.Log = dbutil.ZeroLogger(log)
rawDB.Log = dbutil.ZeroLogger(log.With().Str("db_section", "main").Logger())
rawDB.Owner = "botbot"
rawDB.UpgradeTable = upgrades.Table
err = rawDB.Upgrade()
Expand Down
10 changes: 5 additions & 5 deletions upgrades/00-latest-revision.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-- v0 -> v1: Latest revision

CREATE TABLE bots (
mxid TEXT PRIMARY KEY,
mxid TEXT NOT NULL PRIMARY KEY,
owner_mxid TEXT NOT NULL
) STRICT;
);

CREATE TABLE self_destructing_events (
event_id TEXT PRIMARY KEY,
room_id TEXT NOT NULL,
event_id TEXT NOT NULL PRIMARY KEY,
room_id TEXT NOT NULL,
delete_at BIGINT NOT NULL
) STRICT;
);

0 comments on commit cdb355e

Please sign in to comment.