This commit is contained in:
parent
c53942ac53
commit
d09b763aa7
24 changed files with 941 additions and 17 deletions
|
@ -9,6 +9,7 @@ func init() {
|
|||
// Register migrations
|
||||
Register(1, "Initial schema with bcrypt passwords", migrateInitialSchemaUp, migrateInitialSchemaDown)
|
||||
Register(2, "Add reminders table", migrateRemindersUp, migrateRemindersDown)
|
||||
Register(3, "Add cache table", migrateCacheUp, migrateCacheDown)
|
||||
}
|
||||
|
||||
// Initial schema creation with bcrypt passwords - version 1
|
||||
|
@ -126,3 +127,30 @@ func migrateRemindersDown(db *sql.DB) error {
|
|||
_, err := db.Exec(`DROP TABLE IF EXISTS reminders`)
|
||||
return err
|
||||
}
|
||||
|
||||
// Add cache table - version 3
|
||||
func migrateCacheUp(db *sql.DB) error {
|
||||
_, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS cache (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL,
|
||||
expires_at TIMESTAMP,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create index on expires_at for efficient cleanup
|
||||
_, err = db.Exec(`
|
||||
CREATE INDEX IF NOT EXISTS idx_cache_expires_at ON cache(expires_at)
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func migrateCacheDown(db *sql.DB) error {
|
||||
_, err := db.Exec(`DROP TABLE IF EXISTS cache`)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue