Permalink
Browse files

Consider the root migration special

Ignore-this: c83c82c5344ea1be9e16b6224b5ad848

darcs-hash:20101109033019-e018d-60b1b64adbf2184806d138ad3fc4a548bb9f0321.gz
  • Loading branch information...
1 parent d2a5fbe commit cd926c0d72dfa9b34e45018d7cf5914df72a6da1 drcygnus committed Nov 9, 2010
Showing with 14 additions and 3 deletions.
  1. +7 −0 src/Database/Schema/Migrations/Backend.hs
  2. +4 −2 src/Database/Schema/Migrations/Backend/HDBC.hs
  3. +3 −1 src/Moo.hs
View
7 src/Database/Schema/Migrations/Backend.hs
@@ -1,12 +1,19 @@
{-# LANGUAGE MultiParamTypeClasses #-}
module Database.Schema.Migrations.Backend
( Backend(..)
+ , rootMigrationName
)
where
import Database.Schema.Migrations.Migration
( Migration(..) )
+-- |Backend instances should use this as the name of the migration
+-- returned by getBootstrapMigration; this migration is special
+-- because it cannot be reverted.
+rootMigrationName :: String
+rootMigrationName = "root"
+
-- |A Backend represents a database engine backend such as MySQL or
-- SQLite. A Backend supplies relatively low-level functions for
-- inspecting the backend's state, applying migrations, and reverting
View
6 src/Database/Schema/Migrations/Backend/HDBC.hs
@@ -7,7 +7,9 @@ where
import Database.HDBC ( quickQuery', fromSql, toSql, IConnection(getTables, run, runRaw) )
import Database.Schema.Migrations.Backend
- ( Backend(..) )
+ ( Backend(..)
+ , rootMigrationName
+ )
import Database.Schema.Migrations.Migration
( Migration(..)
, newMigration
@@ -33,7 +35,7 @@ instance (IConnection conn) => Backend conn IO where
getBootstrapMigration _ =
do
- m <- newMigration "root"
+ m <- newMigration rootMigrationName
return $ m { mApply = createSql
, mRevert = Just revertSql
, mDesc = Just "Migration table installation"
View
4 src/Moo.hs
@@ -26,6 +26,7 @@ import Database.Schema.Migrations.Filesystem
import Database.Schema.Migrations.Migration ( Migration(..) )
import Database.Schema.Migrations.Backend ( Backend, applyMigration
, revertMigration, getMigrations
+ , rootMigrationName
)
import Database.Schema.Migrations.Store ( loadMigrations
, fullMigrationName
@@ -450,7 +451,8 @@ listCommand _ = do
withConnection $ \(AnyIConnection conn) -> do
ensureBootstrappedBackend conn >> commit conn
ms <- getMigrations conn
- mapM_ putStrLn ms
+ forM_ ms $ \m ->
+ when (not $ m == rootMigrationName) $ putStrLn m
applyCommand :: CommandHandler
applyCommand storeData = do

0 comments on commit cd926c0

Please sign in to comment.