joist-migration-utils 2.3.0-next.8 → 2.3.0-next.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/_virtual/_rolldown/runtime.js +5 -0
- package/build/index.cjs +44 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.cts +7 -0
- package/build/index.d.cts.map +1 -0
- package/build/index.d.mts +7 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.js +22 -39
- package/build/index.js.map +1 -1
- package/build/migrate.cjs +20 -0
- package/build/migrate.cjs.map +1 -0
- package/build/migrate.d.cts +6 -0
- package/build/migrate.d.cts.map +1 -0
- package/build/migrate.d.mts +6 -0
- package/build/migrate.d.mts.map +1 -0
- package/build/migrate.js +15 -17
- package/build/migrate.js.map +1 -1
- package/build/utils.cjs +272 -0
- package/build/utils.cjs.map +1 -0
- package/build/utils.d.cts +97 -0
- package/build/utils.d.cts.map +1 -0
- package/build/utils.d.mts +97 -0
- package/build/utils.d.mts.map +1 -0
- package/build/utils.js +192 -175
- package/build/utils.js.map +1 -1
- package/package.json +30 -13
- package/build/index.d.ts +0 -4
- package/build/index.d.ts.map +0 -1
- package/build/migrate.d.ts +0 -3
- package/build/migrate.d.ts.map +0 -1
- package/build/utils.d.ts +0 -95
- package/build/utils.d.ts.map +0 -1
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAgBA,8CAiBC;AAQD,wCAwBC;AAED,0CAQC;AACD,oCAIC;AAED,0CASC;AASD,wCAaC;AAED,0DAOC;AAgDD,gEAEC;AAED,0DAOC;AAOD,gCAQC;AAGD,wCAEC;AAED,kCAEC;AAgBD,0CAWC;AAiED,sDAqBC;AAGD,gCAOC;AAED,oBAEC;AA5UD,qDAOyB;AACzB,yCAAqC;AAErC;;;;;GAKG;AACH,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AAC;QACtG,UAAU,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;KAC7E,EACD,OAAO,CACR,CAAC;IACF,CAAC,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IAClG,CAAC,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,yDAAyD;AAChG,CAAC;AAED,oDAAoD;AACpD,SAAgB,UAAU,CAAC,CAAmB,EAAE,SAAiB,EAAE,OAA0B;IAC3F,CAAC,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACjC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE;QAC9C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;YAC9C,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,IAAI,CAAC,OAAgB;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAC;AACvC,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import {\n type ColumnDefinition,\n type ColumnDefinitions,\n type DropOptions,\n type MigrationBuilder,\n PgLiteral,\n type TableOptions,\n} from \"node-pg-migrate\";\nimport pluralize from \"pluralize\";\n\nconst { singular } = pluralize;\n\n/**\n * Creates an entity table with our conventions.\n *\n * Specifically an `id` auto-increment column (via a sequence) and `created_at` and `updated_at`\n * columns.\n */\nexport function createEntityTable(b: MigrationBuilder, tableName: string, columns: ColumnDefinitions): void {\n b.createTable(tableName, {\n id: \"id\",\n ...columns,\n created_at: { type: \"timestamptz\", notNull: true },\n updated_at: { type: \"timestamptz\", notNull: true },\n });\n\n // Postgres doesn't automatically index foreign keys, so any column def points at\n // another table, assume we'll be doing a lot of lookups on this column and should fk it.\n Object.entries(columns).forEach(([name, def]) => {\n if (typeof def === \"object\" && def.references) {\n b.addIndex(tableName, [name], { method: \"btree\" });\n }\n });\n\n createTriggers(b, tableName);\n}\n\n/**\n * Creates a subtype table using class-per-table inheritance.\n *\n * The subtable will use the base table's id as its identity, and when loading rows of the base\n * type, Joist will automatically stitch together rows across each table into a single instance.\n */\nexport function createSubTable(\n b: MigrationBuilder,\n baseTableName: string,\n subTableName: string,\n columns: ColumnDefinitions,\n): void {\n b.createTable(subTableName, {\n id: {\n type: \"int\",\n references: `${baseTableName}`,\n primaryKey: true,\n deferrable: true,\n deferred: true,\n onDelete: \"CASCADE\",\n },\n ...columns,\n });\n // Postgres doesn't automatically index foreign keys, so any column def points at\n // another table, assume we'll be doing a lot of lookups on this column and should fk it.\n Object.entries(columns).forEach(([name, def]) => {\n if (typeof def === \"object\" && def.references) {\n b.addIndex(subTableName, [name], { method: \"btree\" });\n }\n });\n}\n\nexport function createEnumTable(b: MigrationBuilder, tableName: string, values: Array<[string, string]>): void {\n b.createTable(tableName, {\n id: \"id\",\n code: { type: \"text\", notNull: true },\n name: { type: \"text\", notNull: true },\n });\n b.addConstraint(tableName, `${tableName}_unique_enum_code_constraint`, \"UNIQUE (code)\");\n values.forEach((value) => addEnumValue(b, tableName, value));\n}\nexport function addEnumValue(b: MigrationBuilder, tableName: string, value: [string, string]): void {\n const [code, name] = value;\n validateEnumCode(code);\n b.sql(`INSERT INTO ${tableName} (code, name) VALUES ('${code}', '${name.replace(\"'\", \"''\")}');`);\n}\n\nexport function updateEnumValue(\n b: MigrationBuilder,\n tableName: string,\n previousCode: string,\n value: [string, string],\n): void {\n const [code, name] = value;\n validateEnumCode(code);\n b.sql(`UPDATE ${tableName} SET code ='${code}', name = '${name.replace(\"'\", \"''\")}' WHERE code = '${previousCode}';`);\n}\n\nfunction validateEnumCode(code: string): void {\n const codeRegex = /^[A-Z0-9_]+$/;\n if (!codeRegex.test(code))\n throw `ERROR: Invalid enum code specified: ${code}. Codes must match the regex: ${codeRegex}`;\n}\n\n/** Makes a trigger to update the `updated_at` column. */\nexport function createTriggers(b: MigrationBuilder, tableName: string): void {\n b.createTrigger(tableName, `${tableName}_created_at`, {\n when: \"BEFORE\",\n operation: \"INSERT\",\n level: \"ROW\",\n function: \"trigger_maybe_set_created_at\",\n });\n b.createTrigger(tableName, `${tableName}_updated_at`, {\n when: \"BEFORE\",\n operation: \"UPDATE\",\n level: \"ROW\",\n function: \"trigger_maybe_set_updated_at\",\n });\n}\n\nexport function createUpdatedAtFunction(b: MigrationBuilder): void {\n b.createFunction(\n \"trigger_maybe_set_updated_at\",\n [],\n { replace: true, language: \"plpgsql\", returns: \"TRIGGER\" },\n \"BEGIN IF NEW.updated_at = OLD.updated_at THEN NEW.updated_at = NOW(); END IF; RETURN NEW; END;\",\n );\n}\n\n/**\n * Unnests a 2d array like `[[a, b], [c, d]]` into two rows of `[a, b]` and `[c, d]`.\n *\n * This custom function is a key part of Joist's bulk INSERT/UPDATE that sends \"all firstNames as\n * a single param\", because it lets us support array columns as a single parameter (i.e. an array\n * of arrays).\n *\n * Postgres's built-in `unnest` is too aggressive when flattening, and will unnest the 2d array\n * of `[[a, b], [c, d]]` into four rows of `a`, `b`, `c`, and `d`, which is not what we want.\n *\n * Additionally, Postgres does not support \"jagged arrays\", i.e. 2D arrays where some\n * sub-arrays are longer than others, e.g. `[[a, b], [c, d, e]]`. Instead, it treats arrays\n * more as the mathematical concept of a matrix, than \"a list of lists\".\n *\n * To work around this, our PostgresDriver auto-pads all 2D arrays to the same length, by\n * appending `NULL`, and then `unnest_arrays` prunes all `NULL`s from the resulting 1D arrays.\n * See `fillArrayWithNulls`.\n *\n *\n * This means we purposefully do not/cannot support `NULL` values _within_ array columns,\n * i.e. `nick_names=[a, NULL, b]` (without some additional heuristics).\n *\n * That said, we do need to support nullable array columns, i.e. `nick_names=NULL`, which we\n * detect by prefixing an additional marker element to each sub-array that indicates whether the\n * array column is null or not, and then conditionally enabling this with the `nullable=true`\n * param to `unnest_arrays`.\n */\nexport 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`;\n\nexport function createUnnestArraysFunction(b: MigrationBuilder): void {\n b.sql(unnest_arrays);\n}\n\nexport function createCreatedAtFunction(b: MigrationBuilder): void {\n b.createFunction(\n \"trigger_maybe_set_created_at\",\n [],\n { replace: true, language: \"plpgsql\", returns: \"TRIGGER\" },\n \"BEGIN IF NEW.created_at IS NULL THEN NEW.created_at = NOW(); END IF; IF NEW.updated_at IS NULL THEN NEW.updated_at = NOW(); END IF; RETURN NEW; END;\",\n );\n}\n\nexport type FieldNameOverrides = {\n fieldName?: string;\n otherFieldName?: string;\n};\ntype ForeignKeyOpts = Partial<ColumnDefinition> & Required<Pick<ColumnDefinition, \"notNull\">> & FieldNameOverrides;\nexport function foreignKey(otherTable: string, opts: ForeignKeyOpts): ColumnDefinition {\n return {\n type: \"integer\",\n references: otherTable,\n deferrable: true,\n deferred: true,\n ...foreignKeyOptsWithMaybeComment(opts),\n };\n}\n\nexport type RenameRelationOpts = FieldNameOverrides & Pick<ColumnDefinition, \"comment\">;\nexport function renameRelation(b: MigrationBuilder, tableName: string, columnName: string, opts: RenameRelationOpts) {\n b.alterColumn(tableName, columnName, foreignKeyOptsWithMaybeComment(opts));\n}\n\nexport function commentData(data: any, comment?: string | null): string {\n return `${comment ?? \"\"}[pg-structure]${JSON.stringify(data)}[/pg-structure]`;\n}\n\nfunction foreignKeyOptsWithMaybeComment<T extends RenameRelationOpts, R extends Omit<T, keyof FieldNameOverrides>>(\n opts: T,\n): R {\n let { comment, fieldName, otherFieldName, ...rest } = opts;\n if (fieldName || otherFieldName) {\n const overrides = { fieldName, otherFieldName };\n return { ...(rest as R), comment: commentData(overrides, comment) };\n } else if (comment) {\n return { ...(rest as R), comment };\n } else {\n return rest as R;\n }\n}\n\nexport function enumArrayColumn(enumTable: string, opts?: Pick<ColumnDefinition, \"notNull\">): ColumnDefinition {\n // We use `notNull: false` to facilitate adding to tables with existing rows,\n // but note that we coalesce null to `[]` anyway in the serde logic, so it\n // doesn't really matter to application logic whether it's notNull or not.\n return {\n type: \"integer[]\",\n comment: `enum=${enumTable}`,\n notNull: false,\n default: PgLiteral.create(\"array[]::integer[]\"),\n ...opts,\n };\n}\n\ntype ManyToManyColumn = {\n /** The target table for this m2m table, i.e. for a `books_to_tags`, this might be `books`. */\n table: string;\n /** The column name within the m2m table, i.e. for a `books_to_tags`, this might be `book_id`. */\n column?: string;\n /**\n * The name of the collection that *points to* these rows, i.e. for `books_to_tags` and the `book_id`\n * column, `collectionName=taggedBooks` b/c `t1.taggedBooks` does a `SELECT book_id WHERE tag_id=t:1`.\n *\n * For self-referential m2m tables, i.e. `author_to_mentors`, these names can be confusing, i.e.:\n *\n * ```\n * createManyToManyTable(\n * b,\n * \"author_to_mentors\",\n * // column=mentor_id, collectionName=mentors ==> `a.mentors` does `select mentor_id WHERE mentee_id=a:1`\n * { table: \"authors\", column: \"mentor_id\", collectionName: \"mentors\" },\n * // column=mentee_id, collectionName=mentees ==> `a.mentees` does `select mentee_id WHERE mentor_id=a:1`\n * { table: \"authors\", column: \"mentee_id\", collectionName: \"mentees\" },\n * );\n * ````\n */\n collectionName?: string;\n};\n\nfunction maybeTableOrColumn(maybeTableOrColumn: string | ManyToManyColumn): [string, string, string | undefined] {\n if (typeof maybeTableOrColumn === \"string\") {\n return [maybeTableOrColumn, `${singular(maybeTableOrColumn)}_id`, undefined];\n } else {\n const { table, column, collectionName } = maybeTableOrColumn;\n return [table, column ?? `${singular(table)}_id`, collectionName];\n }\n}\n\n/** Creates a many-to-many table between `table1` and `table2` with our conventions. */\nexport function createManyToManyTable(\n b: MigrationBuilder,\n tableName: string,\n table1: string,\n table2: string,\n options?: TableOptions & DropOptions,\n): void;\nexport function createManyToManyTable(\n b: MigrationBuilder,\n tableName: string,\n column1: ManyToManyColumn,\n column2: ManyToManyColumn,\n options?: TableOptions & DropOptions,\n): void;\nexport function createManyToManyTable(\n b: MigrationBuilder,\n tableName: string,\n table1: string,\n column2: ManyToManyColumn,\n options?: TableOptions & DropOptions,\n): void;\nexport function createManyToManyTable(\n b: MigrationBuilder,\n tableName: string,\n column1: ManyToManyColumn,\n table2: string,\n options?: TableOptions & DropOptions,\n): void;\nexport function createManyToManyTable(\n b: MigrationBuilder,\n tableName: string,\n tableOrColumn1: string | ManyToManyColumn,\n tableOrColumn2: string | ManyToManyColumn,\n options?: TableOptions & DropOptions,\n) {\n const [table1, column1, otherFieldName1] = maybeTableOrColumn(tableOrColumn1);\n const [table2, column2, otherFieldName2] = maybeTableOrColumn(tableOrColumn2);\n b.createTable(\n tableName,\n {\n id: \"id\",\n [column1]: foreignKey(table1, { notNull: true, onDelete: \"CASCADE\", otherFieldName: otherFieldName1 }),\n [column2]: foreignKey(table2, { notNull: true, onDelete: \"CASCADE\", otherFieldName: otherFieldName2 }),\n created_at: { type: \"timestamptz\", notNull: true, default: b.func(\"NOW()\") },\n },\n options,\n );\n b.createIndex(tableName, [column1, column2], { unique: true, ifNotExists: options?.ifNotExists });\n b.createIndex(tableName, [column2]); // Improves lookup performance when querying just column2\n}\n\n/** Adds columns + auto-indexes any foreign keys. */\nexport function addColumns(b: MigrationBuilder, tableName: string, columns: ColumnDefinitions): void {\n b.addColumns(tableName, columns);\n Object.entries(columns).forEach(([name, def]) => {\n if (typeof def === \"object\" && def.references) {\n b.addIndex(tableName, [name], { method: \"btree\" });\n }\n });\n}\n\nexport function fail(message?: string): never {\n throw new Error(message || \"Failed\");\n}\n"],"mappings":";;;AAUA,MAAM,EAAE,aAAa;;;;;;;AAQrB,SAAgB,kBAAkB,GAAqB,WAAmB,SAAkC;CAC1G,EAAE,YAAY,WAAW;EACvB,IAAI;EACJ,GAAG;EACH,YAAY;GAAE,MAAM;GAAe,SAAS;EAAK;EACjD,YAAY;GAAE,MAAM;GAAe,SAAS;EAAK;CACnD,CAAC;CAID,OAAO,QAAQ,OAAO,CAAC,CAAC,SAAS,CAAC,MAAM,SAAS;EAC/C,IAAI,OAAO,QAAQ,YAAY,IAAI,YACjC,EAAE,SAAS,WAAW,CAAC,IAAI,GAAG,EAAE,QAAQ,QAAQ,CAAC;CAErD,CAAC;CAED,eAAe,GAAG,SAAS;AAC7B;;;;;;;AAQA,SAAgB,eACd,GACA,eACA,cACA,SACM;CACN,EAAE,YAAY,cAAc;EAC1B,IAAI;GACF,MAAM;GACN,YAAY,GAAG;GACf,YAAY;GACZ,YAAY;GACZ,UAAU;GACV,UAAU;EACZ;EACA,GAAG;CACL,CAAC;CAGD,OAAO,QAAQ,OAAO,CAAC,CAAC,SAAS,CAAC,MAAM,SAAS;EAC/C,IAAI,OAAO,QAAQ,YAAY,IAAI,YACjC,EAAE,SAAS,cAAc,CAAC,IAAI,GAAG,EAAE,QAAQ,QAAQ,CAAC;CAExD,CAAC;AACH;AAEA,SAAgB,gBAAgB,GAAqB,WAAmB,QAAuC;CAC7G,EAAE,YAAY,WAAW;EACvB,IAAI;EACJ,MAAM;GAAE,MAAM;GAAQ,SAAS;EAAK;EACpC,MAAM;GAAE,MAAM;GAAQ,SAAS;EAAK;CACtC,CAAC;C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AU;GAAW,gBAAgB;EAAgB,CAAC;GACpG,UAAU,WAAW,QAAQ;GAAE,SAAS;GAAM,UAAU;GAAW,gBAAgB;EAAgB,CAAC;EACrG,YAAY;GAAE,MAAM;GAAe,SAAS;GAAM,SAAS,EAAE,KAAK,OAAO;EAAE;CAC7E,GACA,OACF;CACA,EAAE,YAAY,WAAW,CAAC,SAAS,OAAO,GAAG;EAAE,QAAQ;EAAM,aAAa,SAAS;CAAY,CAAC;CAChG,EAAE,YAAY,WAAW,CAAC,OAAO,CAAC;AACpC;;AAGA,SAAgB,WAAW,GAAqB,WAAmB,SAAkC;CACnG,EAAE,WAAW,WAAW,OAAO;CAC/B,OAAO,QAAQ,OAAO,CAAC,CAAC,SAAS,CAAC,MAAM,SAAS;EAC/C,IAAI,OAAO,QAAQ,YAAY,IAAI,YACjC,EAAE,SAAS,WAAW,CAAC,IAAI,GAAG,EAAE,QAAQ,QAAQ,CAAC;CAErD,CAAC;AACH;AAEA,SAAgB,KAAK,SAAyB;CAC5C,MAAM,IAAI,MAAM,WAAW,QAAQ;AACrC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joist-migration-utils",
|
|
3
|
-
"version": "2.3.0-next.
|
|
3
|
+
"version": "2.3.0-next.80",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/joist-orm/joist-orm.git",
|
|
8
9
|
"directory": "packages/migration-utils"
|
|
9
10
|
},
|
|
10
|
-
"main": "build/index.
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
11
|
+
"main": "build/index.cjs",
|
|
12
|
+
"module": "build/index.js",
|
|
13
|
+
"types": "build/index.d.mts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"bun": {
|
|
17
|
+
"types": "./build/index.d.mts",
|
|
18
|
+
"default": "./build/index.js"
|
|
19
|
+
},
|
|
20
|
+
"module-sync": {
|
|
21
|
+
"types": "./build/index.d.mts",
|
|
22
|
+
"default": "./build/index.js"
|
|
23
|
+
},
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./build/index.d.mts",
|
|
26
|
+
"default": "./build/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./build/index.d.cts",
|
|
30
|
+
"default": "./build/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"default": "./build/index.js"
|
|
33
|
+
}
|
|
14
34
|
},
|
|
15
35
|
"files": [
|
|
16
36
|
"build"
|
|
17
37
|
],
|
|
18
38
|
"peerDependencies": {
|
|
19
|
-
"joist-utils": "2.3.0-next.
|
|
20
|
-
"pg": "^8.
|
|
39
|
+
"joist-utils": "2.3.0-next.80",
|
|
40
|
+
"pg": "^8.23.0"
|
|
21
41
|
},
|
|
22
42
|
"dependencies": {
|
|
23
43
|
"@types/pluralize": "^0.0.33",
|
|
@@ -26,15 +46,12 @@
|
|
|
26
46
|
"pluralize": "^8.0.0"
|
|
27
47
|
},
|
|
28
48
|
"devDependencies": {
|
|
29
|
-
"@swc/core": "^1.
|
|
49
|
+
"@swc/core": "^1.16.1",
|
|
30
50
|
"@swc/jest": "^0.2.39",
|
|
31
51
|
"@types/jest": "^30.0.0",
|
|
32
|
-
"@types/node": "^26.0
|
|
52
|
+
"@types/node": "^26.2.0",
|
|
33
53
|
"jest": "30.4.2",
|
|
34
|
-
"prettier": "^3.8.4",
|
|
35
|
-
"prettier-plugin-organize-imports": "^4.3.0",
|
|
36
|
-
"ts-node-dev": "^2.0.0",
|
|
37
54
|
"tsconfig-paths": "^4.2.0",
|
|
38
|
-
"typescript": "
|
|
55
|
+
"typescript": "7.0.2"
|
|
39
56
|
}
|
|
40
57
|
}
|
package/build/index.d.ts
DELETED
package/build/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AAExB,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAQlD"}
|
package/build/migrate.d.ts
DELETED
package/build/migrate.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAI5B,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,MAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAc5G"}
|
package/build/utils.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { ColumnDefinition, ColumnDefinitions, DropOptions, MigrationBuilder, TableOptions } from "node-pg-migrate";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an entity table with our conventions.
|
|
4
|
-
*
|
|
5
|
-
* Specifically an `id` auto-increment column (via a sequence) and `created_at` and `updated_at`
|
|
6
|
-
* columns.
|
|
7
|
-
*/
|
|
8
|
-
export declare function createEntityTable(b: MigrationBuilder, tableName: string, columns: ColumnDefinitions): void;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a subtype table using class-per-table inheritance.
|
|
11
|
-
*
|
|
12
|
-
* The subtable will use the base table's id as its identity, and when loading rows of the base
|
|
13
|
-
* type, Joist will automatically stitch together rows across each table into a single instance.
|
|
14
|
-
*/
|
|
15
|
-
export declare function createSubTable(b: MigrationBuilder, baseTableName: string, subTableName: string, columns: ColumnDefinitions): void;
|
|
16
|
-
export declare function createEnumTable(b: MigrationBuilder, tableName: string, values: Array<[string, string]>): void;
|
|
17
|
-
export declare function addEnumValue(b: MigrationBuilder, tableName: string, value: [string, string]): void;
|
|
18
|
-
export declare function updateEnumValue(b: MigrationBuilder, tableName: string, previousCode: string, value: [string, string]): void;
|
|
19
|
-
/** Makes a trigger to update the `updated_at` column. */
|
|
20
|
-
export declare function createTriggers(b: MigrationBuilder, tableName: string): void;
|
|
21
|
-
export declare function createUpdatedAtFunction(b: MigrationBuilder): void;
|
|
22
|
-
/**
|
|
23
|
-
* Unnests a 2d array like `[[a, b], [c, d]]` into two rows of `[a, b]` and `[c, d]`.
|
|
24
|
-
*
|
|
25
|
-
* This custom function is a key part of Joist's bulk INSERT/UPDATE that sends "all firstNames as
|
|
26
|
-
* a single param", because it lets us support array columns as a single parameter (i.e. an array
|
|
27
|
-
* of arrays).
|
|
28
|
-
*
|
|
29
|
-
* Postgres's built-in `unnest` is too aggressive when flattening, and will unnest the 2d array
|
|
30
|
-
* of `[[a, b], [c, d]]` into four rows of `a`, `b`, `c`, and `d`, which is not what we want.
|
|
31
|
-
*
|
|
32
|
-
* Additionally, Postgres does not support "jagged arrays", i.e. 2D arrays where some
|
|
33
|
-
* sub-arrays are longer than others, e.g. `[[a, b], [c, d, e]]`. Instead, it treats arrays
|
|
34
|
-
* more as the mathematical concept of a matrix, than "a list of lists".
|
|
35
|
-
*
|
|
36
|
-
* To work around this, our PostgresDriver auto-pads all 2D arrays to the same length, by
|
|
37
|
-
* appending `NULL`, and then `unnest_arrays` prunes all `NULL`s from the resulting 1D arrays.
|
|
38
|
-
* See `fillArrayWithNulls`.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* This means we purposefully do not/cannot support `NULL` values _within_ array columns,
|
|
42
|
-
* i.e. `nick_names=[a, NULL, b]` (without some additional heuristics).
|
|
43
|
-
*
|
|
44
|
-
* That said, we do need to support nullable array columns, i.e. `nick_names=NULL`, which we
|
|
45
|
-
* detect by prefixing an additional marker element to each sub-array that indicates whether the
|
|
46
|
-
* array column is null or not, and then conditionally enabling this with the `nullable=true`
|
|
47
|
-
* param to `unnest_arrays`.
|
|
48
|
-
*/
|
|
49
|
-
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";
|
|
50
|
-
export declare function createUnnestArraysFunction(b: MigrationBuilder): void;
|
|
51
|
-
export declare function createCreatedAtFunction(b: MigrationBuilder): void;
|
|
52
|
-
export type FieldNameOverrides = {
|
|
53
|
-
fieldName?: string;
|
|
54
|
-
otherFieldName?: string;
|
|
55
|
-
};
|
|
56
|
-
type ForeignKeyOpts = Partial<ColumnDefinition> & Required<Pick<ColumnDefinition, "notNull">> & FieldNameOverrides;
|
|
57
|
-
export declare function foreignKey(otherTable: string, opts: ForeignKeyOpts): ColumnDefinition;
|
|
58
|
-
export type RenameRelationOpts = FieldNameOverrides & Pick<ColumnDefinition, "comment">;
|
|
59
|
-
export declare function renameRelation(b: MigrationBuilder, tableName: string, columnName: string, opts: RenameRelationOpts): void;
|
|
60
|
-
export declare function commentData(data: any, comment?: string | null): string;
|
|
61
|
-
export declare function enumArrayColumn(enumTable: string, opts?: Pick<ColumnDefinition, "notNull">): ColumnDefinition;
|
|
62
|
-
type ManyToManyColumn = {
|
|
63
|
-
/** The target table for this m2m table, i.e. for a `books_to_tags`, this might be `books`. */
|
|
64
|
-
table: string;
|
|
65
|
-
/** The column name within the m2m table, i.e. for a `books_to_tags`, this might be `book_id`. */
|
|
66
|
-
column?: string;
|
|
67
|
-
/**
|
|
68
|
-
* The name of the collection that *points to* these rows, i.e. for `books_to_tags` and the `book_id`
|
|
69
|
-
* column, `collectionName=taggedBooks` b/c `t1.taggedBooks` does a `SELECT book_id WHERE tag_id=t:1`.
|
|
70
|
-
*
|
|
71
|
-
* For self-referential m2m tables, i.e. `author_to_mentors`, these names can be confusing, i.e.:
|
|
72
|
-
*
|
|
73
|
-
* ```
|
|
74
|
-
* createManyToManyTable(
|
|
75
|
-
* b,
|
|
76
|
-
* "author_to_mentors",
|
|
77
|
-
* // column=mentor_id, collectionName=mentors ==> `a.mentors` does `select mentor_id WHERE mentee_id=a:1`
|
|
78
|
-
* { table: "authors", column: "mentor_id", collectionName: "mentors" },
|
|
79
|
-
* // column=mentee_id, collectionName=mentees ==> `a.mentees` does `select mentee_id WHERE mentor_id=a:1`
|
|
80
|
-
* { table: "authors", column: "mentee_id", collectionName: "mentees" },
|
|
81
|
-
* );
|
|
82
|
-
* ````
|
|
83
|
-
*/
|
|
84
|
-
collectionName?: string;
|
|
85
|
-
};
|
|
86
|
-
/** Creates a many-to-many table between `table1` and `table2` with our conventions. */
|
|
87
|
-
export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, table1: string, table2: string, options?: TableOptions & DropOptions): void;
|
|
88
|
-
export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, column1: ManyToManyColumn, column2: ManyToManyColumn, options?: TableOptions & DropOptions): void;
|
|
89
|
-
export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, table1: string, column2: ManyToManyColumn, options?: TableOptions & DropOptions): void;
|
|
90
|
-
export declare function createManyToManyTable(b: MigrationBuilder, tableName: string, column1: ManyToManyColumn, table2: string, options?: TableOptions & DropOptions): void;
|
|
91
|
-
/** Adds columns + auto-indexes any foreign keys. */
|
|
92
|
-
export declare function addColumns(b: MigrationBuilder, tableName: string, columns: ColumnDefinitions): void;
|
|
93
|
-
export declare function fail(message?: string): never;
|
|
94
|
-
export {};
|
|
95
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/build/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,YA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