chore: remove db migration support — fold household_id into users table definition
- Added household_id column directly to users CREATE TABLE - Removed ALTER TABLE migration hack and Control.Exception/ScopedTypeVariables - Renamed runMigrations to createTables (now internal, unexported) - Tables created from scratch if database doesn't exist; no migration logic
This commit is contained in:
+4
-9
@@ -2,7 +2,6 @@
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
|
||||
@@ -12,7 +11,6 @@ module Sis.Database (
|
||||
DB (..),
|
||||
runDB,
|
||||
openDatabase,
|
||||
runMigrations,
|
||||
|
||||
-- * DB operations (convenience wrappers)
|
||||
findUserByEmail,
|
||||
@@ -37,7 +35,6 @@ module Sis.Database (
|
||||
seed,
|
||||
) where
|
||||
|
||||
import Control.Exception (IOException, catch)
|
||||
import Control.Monad (when)
|
||||
import Data.Maybe (fromMaybe, listToMaybe)
|
||||
import Data.Text (Text)
|
||||
@@ -398,12 +395,12 @@ openDatabase path = do
|
||||
conn <- SQL.open path
|
||||
SQL.execute_ conn "PRAGMA journal_mode=WAL"
|
||||
SQL.execute_ conn "PRAGMA foreign_keys=ON"
|
||||
runMigrations conn
|
||||
createTables conn
|
||||
pure conn
|
||||
|
||||
-- | Create all tables if they don't exist.
|
||||
runMigrations :: SQL.Connection -> IO ()
|
||||
runMigrations conn' = do
|
||||
createTables :: SQL.Connection -> IO ()
|
||||
createTables conn' = do
|
||||
mapM_
|
||||
(SQL.execute_ conn')
|
||||
[ "CREATE TABLE IF NOT EXISTS users (\
|
||||
@@ -411,6 +408,7 @@ runMigrations conn' = do
|
||||
\ display_name TEXT NOT NULL,\
|
||||
\ email TEXT NOT NULL UNIQUE,\
|
||||
\ password_hash TEXT NOT NULL,\
|
||||
\ household_id INTEGER REFERENCES households(id),\
|
||||
\ created_at TEXT NOT NULL DEFAULT (datetime('now')))"
|
||||
, "CREATE TABLE IF NOT EXISTS sessions (\
|
||||
\ id INTEGER PRIMARY KEY AUTOINCREMENT,\
|
||||
@@ -467,9 +465,6 @@ runMigrations conn' = do
|
||||
\ expires_at TEXT NOT NULL,\
|
||||
\ created_at TEXT NOT NULL DEFAULT (datetime('now')))"
|
||||
]
|
||||
-- Add household_id to users (safe to re-run, ignores "duplicate column" error)
|
||||
SQL.execute_ conn' "ALTER TABLE users ADD COLUMN household_id INTEGER REFERENCES households(id)"
|
||||
`catch` (\(_ :: IOException) -> pure ())
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Convenience wrappers (send through the DB effect)
|
||||
|
||||
Reference in New Issue
Block a user