hamsql-0.9.0.0: Interpreter for SQL-structure definitions in YAML (YamSql)

Safe HaskellNone
LanguageHaskell2010

Database.HamSql.Internal.PostgresCon

Description

Implementation of Upgrades

Upgrades are tricky.

  • DELETE statements must come first

Tables

TODO: Delete tables and columns if the user excplicitly agrees to data loss.

CREATE TABLE IF NOT EXISTS without any columns.

CREATE columns with their type on demand.

Always apply all ALTER COLUMN statments

  • SET DATA TYPE
  • DROP DEFAULT
  • SET DEFAULT
  • SET/DROP NOT NULL

TODO: Maybe bundle DROP/SET DEFAULT, such that they can't be reordered.

Constrs are completly dropped an recreated. Would be cool to create PKs first, to fix FK requirements right away.

Functions

Many things can depend on functions (column defaults, table and domain constraints). Therefore, they should all be deleted before deleting a function.

Usually CREATE OR REPLACE FUNCTION is used, such that no deletions occure.

However, some function properties cannot be changed via CREATE OR REPLACE. A known example this the change of the return type. In this case the sqlErrInvalidFunctionDefinition will be catched and the function is deleted and created again.

Domains

Constrs are always deleted an recreated.

Defaults are always set explicitly.

Domains are deleted on demand.

The data type of a domain cannot be changed (at least in PostgreSQL).

TODO: Issue error if domain type differs.

Roles

Difficult since not schema qualified, but be have prefixes.

TODO: LOGIN and PASSWORD are not implemented via ALTER ROLE

TODO: Are role memberships revoked?

Sequences

CREATE only defines name on demand.

Properties all via ALTER SEQUENCE.

Documentation

pgsqlExecStmtList Source #

Arguments

:: OptCommonDb 
-> Status 
-> [SqlStmt]

Statements that still need to be executed

-> [SqlStmt]

Statements that have failed during execution

-> Connection 
-> IO () 

addSqlStmtType Source #

Arguments

:: ToSqlId a 
=> SqlStmtType

statment

-> [a]

SQL ids that should become a SqlStmtId type to use

-> [SqlStmtId] 

filterStmtsMatchingIds Source #

Arguments

:: [SqlStmtId]

Statement ids to remove

-> [SqlStmt] 
-> [SqlStmt] 

filterSqlIdBySqlStmts Source #

Arguments

:: ToSqlId a 
=> SqlStmtType

stmts to be considered by stmt type

-> [SqlStmt]

stmts that have the forbidden ids

-> [a] 
-> [a] 

correctStatements Source #

Arguments

:: ToSqlId a 
=> SqlStmtType

install statements and the stmt type of interest

-> IO [a]

deployed (existing) elements

-> (a -> [Maybe SqlStmt])

drop statment generator

-> [SqlStmt]

install statements, representing desired state

-> IO [SqlStmt] 

addDropResidual :: ToSqlId a => SqlStmtType -> IO [a] -> (a -> [Maybe SqlStmt]) -> [SqlStmt] -> IO [SqlStmt] Source #