Skip to content

Commit

Permalink
Exported DatabaseSchema type.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Oct 7, 2024
1 parent eed016c commit 5a29df2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions beam-migrate/Database/Beam/Migrate/SQL/Tables.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Database.Beam.Migrate.SQL.Tables
, addColumn, dropColumn

-- * Schema manipulation
, createDatabaseSchema, dropDatabaseSchema, existingDatabaseSchema
, DatabaseSchema(..), createDatabaseSchema, dropDatabaseSchema, existingDatabaseSchema

-- * Field specification
, DefaultValue, Constraint(..), NotNullConstraint
Expand Down Expand Up @@ -82,9 +82,10 @@ createTable = createTableWithSchema Nothing

-- * Schema manipulation

-- | Represents a database schema. To create one, see 'createDatabaseSchema'.
-- | Represents a database schema. To create one, see 'createDatabaseSchema';
-- to materialize one, see 'existingDatabaseSchema'.
newtype DatabaseSchema
= MkDatabaseSchema Text
= DatabaseSchema Text
deriving (Eq, Show, IsString)

-- | Add a @CREATE SCHEMA@ statement to this migration
Expand All @@ -97,7 +98,7 @@ createDatabaseSchema :: BeamMigrateSchemaSqlBackend be
-> Migration be DatabaseSchema
createDatabaseSchema nm = do
upDown (createSchemaCmd (createSchemaSyntax (schemaName nm))) Nothing
pure $ MkDatabaseSchema nm
pure $ DatabaseSchema nm

-- | Add a @DROP SCHEMA@ statement to this migration.
--
Expand All @@ -108,7 +109,7 @@ createDatabaseSchema nm = do
dropDatabaseSchema :: BeamMigrateSchemaSqlBackend be
=> DatabaseSchema
-> Migration be ()
dropDatabaseSchema (MkDatabaseSchema nm)
dropDatabaseSchema (DatabaseSchema nm)
= upDown (dropSchemaCmd (dropSchemaSyntax (schemaName nm))) Nothing

-- | Materialize a schema for use during a migration.
Expand All @@ -124,7 +125,7 @@ dropDatabaseSchema (MkDatabaseSchema nm)
-- <*> 'createTableWithSchema' (Just schema) "my_table"
-- @
existingDatabaseSchema :: Text -> Migration be DatabaseSchema
existingDatabaseSchema = pure . MkDatabaseSchema
existingDatabaseSchema = pure . DatabaseSchema

-- | Add a @CREATE TABLE@ statement to this migration, with an explicit schema
--
Expand Down Expand Up @@ -166,7 +167,7 @@ createTableWithSchema maybeSchemaName newTblName tblSettings =
schemaCheck =
case maybeSchemaName of
Nothing -> []
Just (MkDatabaseSchema sn) -> [ SomeDatabasePredicate (SchemaExistsPredicate sn) ]
Just (DatabaseSchema sn) -> [ SomeDatabasePredicate (SchemaExistsPredicate sn) ]

upDown command Nothing
pure (CheckedDatabaseEntity
Expand Down

0 comments on commit 5a29df2

Please sign in to comment.