orville-postgresql-1.0.0.0: A Haskell library for PostgreSQL
CopyrightFlipstone Technology Partners 2023
LicenseMIT
StabilityStable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Orville.PostgreSQL.Schema.IndexDefinition

Description

Since: 1.0.0.0

Synopsis

Documentation

data IndexDefinition Source #

Defines an index that can be added to a TableDefinition. Use one of the constructor functions below (such as uniqueIndex) to construct the index definition you wish to have and then use addTableIndexes to add them to your table definition. Orville will then add the index next time you run auto-migrations.

Since: 1.0.0.0

indexCreationStrategy :: IndexDefinition -> IndexCreationStrategy Source #

Gets the IndexCreationStrategy to be used when creating the index described by the IndexDefinition. By default, all indexes are created using the Transactional strategy.

Since: 1.0.0.0

setIndexCreationStrategy :: IndexCreationStrategy -> IndexDefinition -> IndexDefinition Source #

Sets the IndexCreationStrategy to be used when creating the index described by the IndexDefinition. By default, all indexes are created using the Transactional strategy, but some tables are too large for this to be feasible. See the Concurrent creation strategy for how to work around this.

Since: 1.0.0.0

uniqueIndex :: NonEmpty FieldName -> IndexDefinition Source #

Constructs an IndexDefinition for a UNIQUE index on the given columns.

Since: 1.0.0.0

uniqueNamedIndex :: String -> IndexBodyExpr -> IndexDefinition Source #

Constructs an IndexDefinition for a UNIQUE index with given SQL and index name.

Since: 1.0.0.0

nonUniqueIndex :: NonEmpty FieldName -> IndexDefinition Source #

Constructs an IndexDefinition for a non-unique index on the given columns.

Since: 1.0.0.0

nonUniqueNamedIndex :: String -> IndexBodyExpr -> IndexDefinition Source #

Constructs an IndexDefinition for a non-unique index with given SQL and index name.

Since: 1.0.0.0

mkIndexDefinition :: IndexUniqueness -> NonEmpty FieldName -> IndexDefinition Source #

Constructs an IndexDefinition for an index on the given columns with the given uniqueness.

Since: 1.0.0.0

mkNamedIndexDefinition :: IndexUniqueness -> String -> IndexBodyExpr -> IndexDefinition Source #

Constructs an IndexDefinition for an index with the given uniqueness, given name, and given SQL.

Since: 1.0.0.0

indexCreateExpr :: IndexDefinition -> Qualified TableName -> CreateIndexExpr Source #

Gets the SQL expression that will be used to add the index to the specified table.

Since: 1.0.0.0

data IndexCreationStrategy Source #

Defines how an IndexDefinition will be executed to add an index to a table. By default, all indexes are created using the Transactional strategy.

Since: 1.0.0.0

Constructors

Transactional

The default strategy. The index will be added as part of a database transaction along with all the other DDL being executed to migrate the database schema. If any migration should fail, the index creation will be rolled back as part of the transaction. This is how schema migrations work in general in Orville.

Concurrent

Creates the index using the CONCURRENTLY keyword in PostgreSQL. Index creation will not lock the table during creation, allowing the application to access the table normally while the index is created. Concurrent index creation cannot be done in a transaction, so indexes created using CONCURRENTLY are created outside the normal schema transaction. Index creation may fail when using the Concurrent strategy. Orville has no special provision to detect or recover from this failure currently. You should manually check that index creation has succeeded. If necessary, you can manually drop the index to cause Orville to recreate it the next time migrations are run. Note that while the table will not be locked, index migration will still block application startup by default. See the information about schema migration options in Orville.PostgreSQL.AutoMigration for details about how to work around this if it is a problem for you. Also, it a good idea to read the PostgreSQL docs about creating indexes concurrently before you use this strategy. See https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY.