import { ColumnDefinition, ColumnDefinitions, DropOptions, MigrationBuilder, TableOptions } from "node-pg-migrate"; /** * Creates an entity table with our conventions. * * Specifically an `id` auto-increment column (via a sequence) and `created_at` and `updated_at` * columns. */ export declare function createEntityTable(b: MigrationBuilder, tableName: string, columns: ColumnDefinitions): void; /** * Creates a subtype table using class-per-table inheritance. * * The subtable will use the base table's id as its identity, and when loading rows of the base * type, Joist will automatically stitch together rows across each table into a single instance. */ export declare function createSubTable(b: MigrationBuilder, baseTableName: string, subTableName: string, columns: ColumnDefinitions): void; export declare function createEnumTable(b: MigrationBuilder, tableName: string, values: Array<[string, string]>): void; export declare function addEnumValue(b: MigrationBuilder, tableName: string, value: [string, string]): void; export declare function updateEnumValue(b: MigrationBuilder, tableName: string, previousCode: string, value: [string, string]): void; /** Makes a trigger to update the `updated_at` column. */ export declare function createTriggers(b: MigrationBuilder, tableName: string): void; export declare function createUpdatedAtFunction(b: MigrationBuilder): void; /** * Unnests a 2d array like `[[a, b], [c, d]]` into two rows of `[a, b]` and `[c, d]`. * * This custom function is a key part of Joist's bulk INSERT/UPDATE that sends "all firstNames as * a single param", because it lets us support array columns as a single parameter (i.e. an array * of arrays). * * Postgres's built-in `unnest` is too aggressive when flattening, and will unnest the 2d array * of `[[a, b], [c, d]]` into four rows of `a`, `b`, `c`, and `d`, which is not what we want. * * Additionally, Postgres does not support "jagged arrays", i.e. 2D arrays where some * sub-arrays are longer than others, e.g. `[[a, b], [c, d, e]]`. Instead, it treats arrays * more as the mathematical concept of a matrix, than "a list of lists". * * To work around this, our PostgresDriver auto-pads all 2D arrays to the same length, by * appending `NULL`, and then `unnest_arrays` prunes all `NULL`s from the resulting 1D arrays. * See `fillArrayWithNulls`. * * * This means we purposefully do not/cannot support `NULL` values _within_ array columns, * i.e. `nick_names=[a, NULL, b]` (without some additional heuristics). * * That said, we do need to support nullable array columns, i.e. `nick_names=NULL`, which we * detect by prefixing an additional marker element to each sub-array that indicates whether the * array column is null or not, and then conditionally enabling this with the `nullable=true` * param to `unnest_arrays`. */ export declare const unnest_arrays = "\nCREATE OR REPLACE FUNCTION unnest_arrays(arr ANYARRAY, nullable BOOLEAN = false, OUT a ANYARRAY)\n RETURNS SETOF ANYARRAY\n LANGUAGE plpgsql IMMUTABLE STRICT AS\n$func$\nBEGIN\n FOREACH a SLICE 1 IN ARRAY arr LOOP\n IF nullable THEN\n IF a[1] IS NULL THEN a := NULL;\n ELSE a := a[2:array_length(a, 1)];\n END IF;\n END IF;\n a := array_remove(a, NULL);\n RETURN NEXT;\n END LOOP;\nEND\n$func$;\n"; export declare function createUnnestArraysFunction(b: MigrationBuilder): void; export declare function createCreatedAtFunction(b: MigrationBuilder): void; export type FieldNameOverrides = { fieldName?: string; otherFieldName?: string; }; type ForeignKeyOpts = Partial & Required> & FieldNameOverrides; export declare function foreignKey(otherTable: string, opts: ForeignKeyOpts): ColumnDefinition; export type RenameRelationOpts = FieldNameOverrides & Pick; export declare function renameRelation(b: MigrationBuilder, tableName: string, columnName: string, opts: RenameRelationOpts): void; export declare function commentData(data: any, comment?: string | null): string; export declare function enumArrayColumn(enumTable: string, opts?: Pick): ColumnDefinition; type ManyToManyColumn = { /** The target table for this m2m table, i.e. for a `books_to_tags`, this might be `books`. */ table: string; /** The column name within the m2m table, i.e. for a `books_to_tags`, this might be `book_id`. */ column?: string; /** * The name of the collection that *points to* these rows, i.e. for `books_to_tags` and the `book_id` * column, `collectionName=taggedBooks` b/c `t1.taggedBooks` does a `SELECT book_id WHERE tag_id=t:1`. * * For self-referential m2m tables, i.e. `author_to_mentors`, these names can be confusing, i.e.: * * ``` * createManyToManyTable( * b, * "author_to_mentors", * // column=mentor_id, collectionName=mentors ==> `a.mentors` does `select mentor_id WHERE mentee_id=a:1` * { table: "authors", column: "mentor_id", collectionName: "mentors" }, * // column=mentee_id, collectionName=mentees ==> `a.mentees` does `select mentee_id WHERE mentor_id=a:1` * { table: "authors", column: "mentee_id", collectionName: "mentees" }, * ); * ```` */ collectionName?: string; }; /** Creates a many-to-many table between `table1` and `table2` with our conventions. */ export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, table1: string, table2: string, options?: TableOptions & DropOptions): void; export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, column1: ManyToManyColumn, column2: ManyToManyColumn, options?: TableOptions & DropOptions): void; export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, table1: string, column2: ManyToManyColumn, options?: TableOptions & DropOptions): void; export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, column1: ManyToManyColumn, table2: string, options?: TableOptions & DropOptions): void; /** Adds columns + auto-indexes any foreign keys. */ export declare function addColumns(b: MigrationBuilder, tableName: string, columns: ColumnDefinitions): void; export declare function fail(message?: string): never; export {}; //# sourceMappingURL=utils.d.ts.map