summaryrefslogtreecommitdiff
path: root/template/database/migrate.go
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-05 16:39:13 -0800
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-05 16:39:13 -0800
commitd25ec27fb1c3df175e1b98af1fdc26881d68a1ab (patch)
treea79c729b92c0d0a52b19b37c3a506b988f1e0b80 /template/database/migrate.go
downloadwhois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.tar.gz
whois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.zip
initial commit by simponic-infra
Diffstat (limited to 'template/database/migrate.go')
-rw-r--r--template/database/migrate.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/template/database/migrate.go b/template/database/migrate.go
new file mode 100644
index 0000000..64457bc
--- /dev/null
+++ b/template/database/migrate.go
@@ -0,0 +1,39 @@
+package database
+
+import (
+ "log"
+
+ "database/sql"
+
+ _ "github.com/mattn/go-sqlite3"
+)
+
+type Migrator func(*sql.DB) (*sql.DB, error)
+
+func DoNothing(dbConn *sql.DB) (*sql.DB, error) {
+ log.Println("doing nothing")
+
+ _, err := dbConn.Exec(`SELECT 0;`)
+ if err != nil {
+ return dbConn, err
+ }
+
+ return dbConn, nil
+}
+
+func Migrate(dbConn *sql.DB) (*sql.DB, error) {
+ log.Println("migrating database")
+
+ migrations := []Migrator{
+ DoNothing,
+ }
+
+ for _, migration := range migrations {
+ dbConn, err := migration(dbConn)
+ if err != nil {
+ return dbConn, err
+ }
+ }
+
+ return dbConn, nil
+}