Copyright | (c) digitally induced GmbH 2021 |
---|---|
Safe Haskell | Safe-Inferred |
IHP.IDE.SchemaDesigner.SchemaOperations
Description
Synopsis
- type Schema = [Statement]
- addTable :: Text -> Schema -> Schema
- data AddColumnOptions = AddColumnOptions {
- tableName :: !Text
- columnName :: !Text
- columnType :: !PostgresType
- defaultValue :: !(Maybe Expression)
- isArray :: !Bool
- allowNull :: !Bool
- isUnique :: !Bool
- isReference :: !Bool
- referenceTable :: !(Maybe Text)
- primaryKey :: !Bool
- withIndex :: !Bool
- autoPolicy :: !Bool
- addColumn :: AddColumnOptions -> Schema -> Schema
- data UpdateColumnOptions = UpdateColumnOptions {
- tableName :: !Text
- columnName :: !Text
- columnType :: !PostgresType
- defaultValue :: !(Maybe Expression)
- isArray :: !Bool
- allowNull :: !Bool
- isUnique :: !Bool
- primaryKey :: !Bool
- columnId :: !Int
- updateColumn :: UpdateColumnOptions -> Schema -> Schema
- newColumn :: AddColumnOptions -> Column
- newForeignKeyConstraint :: Text -> Text -> Text -> Statement
- newColumnIndex :: Text -> Text -> Statement
- data AddIndexOptions = AddIndexOptions {
- tableName :: !Text
- columnName :: !Text
- addIndex :: AddIndexOptions -> Schema -> Schema
- appendStatement :: Statement -> [Statement] -> [Statement]
- arrayifytype :: Bool -> PostgresType -> PostgresType
- addForeignKeyConstraint :: Text -> Text -> Text -> Text -> OnDelete -> [Statement] -> [Statement]
- addTableIndex :: Text -> Bool -> Text -> [Text] -> [Statement] -> [Statement]
- addEnum :: Text -> Schema -> Schema
- addValueToEnum :: Text -> Text -> Schema -> Schema
- data UpdatePolicyOptions = UpdatePolicyOptions {
- currentName :: !Text
- tableName :: !Text
- name :: !Text
- using :: !(Maybe Expression)
- check :: !(Maybe Expression)
- updatePolicy :: UpdatePolicyOptions -> Schema -> Schema
- data AddPolicyOptions = AddPolicyOptions {
- tableName :: !Text
- name :: !Text
- using :: !(Maybe Expression)
- check :: !(Maybe Expression)
- addPolicy :: AddPolicyOptions -> Schema -> Schema
- data DeletePolicyOptions = DeletePolicyOptions {
- tableName :: !Text
- policyName :: !Text
- deletePolicy :: DeletePolicyOptions -> Schema -> Schema
- enableRowLevelSecurity :: Text -> Schema -> Schema
- disableRowLevelSecurity :: Text -> Schema -> Schema
- disableRowLevelSecurityIfNoPolicies :: Text -> Schema -> Schema
- suggestPolicy :: Schema -> Statement -> Statement
- isUserIdColumn :: Column -> Bool
- deleteTable :: Text -> Schema -> Schema
- updateTable :: Int -> Text -> Schema -> Schema
- updatedAtTriggerName :: Text -> Text
- addUpdatedAtTrigger :: Text -> [Statement] -> [Statement]
- deleteTriggerIfExists :: Text -> [Statement] -> [Statement]
- data DeleteColumnOptions = DeleteColumnOptions {}
- deleteColumn :: DeleteColumnOptions -> Schema -> Schema
- isIndexStatementReferencingTableColumn :: Statement -> Text -> Text -> Bool
- doesHaveExistingPolicies :: [Statement] -> Text -> Bool
- deleteIndex :: Text -> Schema -> Schema
- data UpdateIndexOptions = UpdateIndexOptions {
- indexName :: !Text
- newIndexName :: !Text
- indexColumns :: ![IndexColumn]
- updateIndex :: UpdateIndexOptions -> Schema -> Schema
Documentation
addTable :: Text -> Schema -> Schema Source #
Creates a new tables with a id
columns as the primary key
data AddColumnOptions Source #
Constructors
AddColumnOptions | |
Fields
|
data UpdateColumnOptions Source #
Constructors
UpdateColumnOptions | |
Fields
|
updateColumn :: UpdateColumnOptions -> Schema -> Schema Source #
newColumn :: AddColumnOptions -> Column Source #
data AddIndexOptions Source #
Constructors
AddIndexOptions | |
Fields
|
arrayifytype :: Bool -> PostgresType -> PostgresType Source #
addForeignKeyConstraint :: Text -> Text -> Text -> Text -> OnDelete -> [Statement] -> [Statement] Source #
addEnum :: Text -> Schema -> Schema Source #
An enum is added after all existing enum statements, but right before CREATE TABLE
statements
data UpdatePolicyOptions Source #
Constructors
UpdatePolicyOptions | |
Fields
|
updatePolicy :: UpdatePolicyOptions -> Schema -> Schema Source #
data AddPolicyOptions Source #
Constructors
AddPolicyOptions | |
Fields
|
data DeletePolicyOptions Source #
Constructors
DeletePolicyOptions | |
Fields
|
deletePolicy :: DeletePolicyOptions -> Schema -> Schema Source #
suggestPolicy :: Schema -> Statement -> Statement Source #
Checks if there exists a user_id
column, and returns a policy based on that.
If there's no user_id
field on the table it will return an empty policy
This function also follows foreign keys to find the shortest path to a user_id. E.g. when having a schema post_meta_tags (no user_id column) - posts (has a user_id) - users:
post_id posts_meta_infos ────────────────► posts │ │ │ │ │ │ user_id │ │ │ │ users ◄───────────────┘
isUserIdColumn :: Column -> Bool Source #
updatedAtTriggerName :: Text -> Text Source #
data DeleteColumnOptions Source #
Constructors
DeleteColumnOptions | |
deleteColumn :: DeleteColumnOptions -> Schema -> Schema Source #
isIndexStatementReferencingTableColumn :: Statement -> Text -> Text -> Bool Source #
Returns True if a CreateIndex statement references a specific column
E.g. given a schema like this: > CREATE TABLE users ( > email TEXT NOT NULL > ); > > CREATE UNIQUE INDEX users_email_index ON users (LOWER(email)); >
You can find all indices to the email column of the users table like this:
>>>
filter (isIndexStatementReferencingTableColumn "users" "email") database
[CreateIndex { indexName = "users_email", unique = True, tableName = "users", expressions = [CallExpression "LOWER" [VarEpression "email"]] }]
data UpdateIndexOptions Source #
Constructors
UpdateIndexOptions | |
Fields
|
updateIndex :: UpdateIndexOptions -> Schema -> Schema Source #