migrate database

This commit is contained in:
ryan
2026-06-19 21:31:21 +08:00
parent b6c4181c70
commit 5bed2bae9f
7 changed files with 1062 additions and 10 deletions
+22 -2
View File
@@ -29,11 +29,31 @@ func dbType() string {
return "PostgreSQL"
}
const (
dialectSqlite = "sqlite3"
dialectPostgres = "postgres"
cascadeSuffix = " CASCADE"
)
func gooseDialect() string {
if !config.Config.Database.Enabled {
return "sqlite3"
return dialectSqlite
}
return "postgres"
return dialectPostgres
}
func tableExistsSQL(dialect string) string {
if dialect == dialectSqlite {
return "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?"
}
return "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_name = $1"
}
func tablesWithPrefixSQL(dialect string) string {
if dialect == dialectSqlite {
return "SELECT name FROM sqlite_master WHERE type='table' AND name LIKE ?"
}
return "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name LIKE $1"
}
func migrationDir() string {