Copyright | (c) digitally induced GmbH 2021 |
---|---|
Safe Haskell | Safe-Inferred |
IHP.IDE.CodeGen.MigrationGenerator
Description
Synopsis
- buildPlan :: Text -> Maybe Text -> IO (Int, [GeneratorAction])
- buildPlanWithoutIHPSchema :: Text -> Maybe Text -> IO (Int, [GeneratorAction])
- buildPlan' :: Bool -> Text -> Maybe Text -> IO (Int, [GeneratorAction])
- diffAppDatabase :: Bool -> Text -> IO [Statement]
- parseIHPSchema :: IO (Either ByteString [Statement])
- diffSchemas :: [Statement] -> [Statement] -> [Statement]
- removeNoise :: [Statement] -> [Statement]
- migrateTable :: Statement -> Statement -> [Statement]
- migrateEnum :: Statement -> Statement -> [Statement]
- getAppDBSchema :: Text -> IO [Statement]
- dumpAppDatabaseSchema :: Text -> IO Text
- parseDumpedSql :: Text -> Either ByteString [Statement]
- normalizeSchema :: [Statement] -> [Statement]
- normalizeStatement :: Statement -> [Statement]
- normalizePolicyAction :: Maybe PolicyAction -> Maybe PolicyAction
- normalizeTable :: CreateTable -> (CreateTable, [Statement])
- normalizeConstraint :: Text -> Constraint -> Constraint
- normalizeColumn :: CreateTable -> Column -> (Column, [Statement])
- normalizeColumnGenerator :: ColumnGenerator -> ColumnGenerator
- normalizeExpression :: Expression -> Expression
- unqualifyExpression :: Text -> Expression -> Expression
- resolveAlias :: Maybe Text -> Expression -> Expression -> Expression
- normalizeSqlType :: PostgresType -> PostgresType
- migrationPathFromPlan :: [GeneratorAction] -> Text
- normalizePrimaryKeys :: [Statement] -> [Statement]
- removeImplicitDeletions :: [Statement] -> [Statement] -> [Statement]
- disableTransactionWhileAddingEnumValues :: [Statement] -> [Statement]
- normalizeIndexType :: Maybe IndexType -> Maybe IndexType
- normalizeIndexColumn :: IndexColumn -> IndexColumn
- normalizeIndexColumnOrder :: [IndexColumnOrder] -> [IndexColumnOrder]
- normalizeNewLines :: Text -> Text
- removeIndentation :: Text -> Text
Documentation
buildPlanWithoutIHPSchema :: Text -> Maybe Text -> IO (Int, [GeneratorAction]) Source #
buildPlan' :: Bool -> Text -> Maybe Text -> IO (Int, [GeneratorAction]) Source #
parseIHPSchema :: IO (Either ByteString [Statement]) Source #
removeNoise :: [Statement] -> [Statement] Source #
dumpAppDatabaseSchema :: Text -> IO Text Source #
Returns the DDL statements of the locally running dev db
Basically does the same as make dumpdb
but returns the output as a string
parseDumpedSql :: Text -> Either ByteString [Statement] Source #
normalizeSchema :: [Statement] -> [Statement] Source #
normalizeStatement :: Statement -> [Statement] Source #
normalizeTable :: CreateTable -> (CreateTable, [Statement]) Source #
normalizeConstraint :: Text -> Constraint -> Constraint Source #
normalizeColumn :: CreateTable -> Column -> (Column, [Statement]) Source #
unqualifyExpression :: Text -> Expression -> Expression Source #
Replaces table.field
with just field
>>>
unqualifyExpression "servers" (sql "SELECT * FROM servers WHERE servers.is_public")
sql "SELECT * FROM servers WHERE is_public"
resolveAlias :: Maybe Text -> Expression -> Expression -> Expression Source #
migrationPathFromPlan :: [GeneratorAction] -> Text Source #
normalizePrimaryKeys :: [Statement] -> [Statement] Source #
Removes ALTER TABLE .. ADD CONSTRAINT .._pkey PRIMARY KEY (id);
and moves it into the CreateTable
field of the CreateTable
statement
pg_dump dumps a table like this:
CREATE TABLE a ( id uuid DEFAULT uuid_generate_v4() NOT NULL ); ALTER TABLE a ADD CONSTRAINT users_pkey PRIMARY KEY (id);
This function basically removes the ALTER TABLE
statements and moves the primary key directly into the CREATE TABLE
statement:
CREATE TABLE a ( id uuid DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL, );
removeImplicitDeletions :: [Statement] -> [Statement] -> [Statement] Source #
Removes DROP INDEX ..
statements and other that appear after a DROP TABLE
statement. The DROP TABLE ..
statement
itself already removes indexes and foreigns keys on that table. So an DROP INDEX ..
would then fail.
Shrinks a sequence like this:
DROP TABLE a; DROP INDEX some_index_on_table_a; ALTER TABLE a DROP CONSTRAINT some_constraint_on_table_a;
Into this:
DROP TABLE a;
disableTransactionWhileAddingEnumValues :: [Statement] -> [Statement] Source #
Moves statements that add enum values outside the database transaction
When IHP generates a migration that contains a statement like this:
ALTER TYPE my_enum ADD VALUE 'some_value';
the migration will fail with this error:
Query (89.238182ms): "BEGIN" () migrate: SqlError {sqlState = "25001", sqlExecStatus = FatalError, sqlErrorMsg = "ALTER TYPE ... ADD cannot run inside a transaction block", sqlErrorDetail = "", sqlErrorHint = ""}
This function moves the ADD VALUE
statement outside the main database transaction:
COMMIT; -- Commit the transaction previously started by IHP ALTER TYPE my_enum ADD VALUE 'some_value'; BEGIN; -- Restart the connection as IHP will also try to run it's own COMMIT
normalizeNewLines :: Text -> Text Source #
removeIndentation :: Text -> Text Source #