IHP Api Reference
Copyright(c) digitally induced GmbH 2021
Safe HaskellNone





type Schema = [Statement] Source #

A Schema.sql basically is just a list of sql DDL statements

addTable :: Text -> Schema -> Schema Source #

Creates a new tables with a id columns as the primary key

addEnum :: Text -> Schema -> Schema Source #

An enum is added after all existing enum statements, but right before CREATE TABLE statements

data UpdatePolicyOptions 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:

                           posts_meta_infos ────────────────►  posts
                                                                │ user_id
                                         users  ◄───────────────┘

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"]] }]