Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
fix: migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
piraces committed Mar 30, 2023
1 parent 0a9c153 commit fc369eb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cmd/rsslay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,17 @@ func InitDatabase(r *Relay) *sql.DB {

log.Printf("[INFO] database opened at %s", *finalConnection)

// Run migration.
// Run migrations
if _, err := sqlDb.Exec(scripts.SchemaSQL); err != nil {
log.Fatalf("[FATAL] cannot migrate schema: %v", err)
}

if _, err := sqlDb.Exec(scripts.CheckNitterColumnSQL); err != nil {
_, err := sqlDb.Exec(scripts.CreateNitterColumnSQL)
if err != nil {
log.Fatalf("[FATAL] cannot migrate schema from previous versions: %v", err)
}
}

return sqlDb
}
1 change: 1 addition & 0 deletions scripts/check_nitter_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT nitter from feeds
1 change: 1 addition & 0 deletions scripts/create_nitter_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE feeds ADD COLUMN nitter INTEGER DEFAULT 0
4 changes: 2 additions & 2 deletions scripts/schema.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS feeds (
publickey VARCHAR(64) PRIMARY KEY,
privatekey VARCHAR(64) NOT NULL,
url TEXT NOT NULL
url TEXT NOT NULL,
nitter INTEGER DEFAULT 0
);

ALTER TABLE feeds ADD COLUMN nitter INTEGER DEFAULT 0;
6 changes: 6 additions & 0 deletions scripts/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ import _ "embed"

//go:embed schema.sql
var SchemaSQL string

//go:embed check_nitter_column.sql
var CheckNitterColumnSQL string

//go:embed create_nitter_column.sql
var CreateNitterColumnSQL string

0 comments on commit fc369eb

Please sign in to comment.