drizzle-kit 0.25.0-d1da3b8 → 0.25.0-f5f3e49
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +474 -0
- package/api.d.ts +474 -0
- package/api.js +1126 -80
- package/api.mjs +1126 -80
- package/bin.cjs +1168 -89
- package/package.json +1 -1
- package/utils.js +51 -11
- package/utils.mjs +51 -11
package/api.js
CHANGED
@@ -3248,8 +3248,8 @@ var require_hanji = __commonJS({
|
|
3248
3248
|
};
|
3249
3249
|
exports2.deferred = deferred;
|
3250
3250
|
var Terminal = class {
|
3251
|
-
constructor(
|
3252
|
-
this.view =
|
3251
|
+
constructor(view2, stdin, stdout, closable) {
|
3252
|
+
this.view = view2;
|
3253
3253
|
this.stdin = stdin;
|
3254
3254
|
this.stdout = stdout;
|
3255
3255
|
this.closable = closable;
|
@@ -3287,7 +3287,7 @@ var require_hanji = __commonJS({
|
|
3287
3287
|
this.resolve({ status: "submitted", data: this.view.result() });
|
3288
3288
|
return;
|
3289
3289
|
}
|
3290
|
-
|
3290
|
+
view2.input(str, key);
|
3291
3291
|
};
|
3292
3292
|
this.stdin.on("keypress", keypress);
|
3293
3293
|
this.view.attach(this);
|
@@ -3349,8 +3349,8 @@ var require_hanji = __commonJS({
|
|
3349
3349
|
};
|
3350
3350
|
exports2.TaskView = TaskView2;
|
3351
3351
|
var TaskTerminal = class {
|
3352
|
-
constructor(
|
3353
|
-
this.view =
|
3352
|
+
constructor(view2, stdout) {
|
3353
|
+
this.view = view2;
|
3354
3354
|
this.stdout = stdout;
|
3355
3355
|
this.text = "";
|
3356
3356
|
this.view.attach(this);
|
@@ -3369,22 +3369,22 @@ var require_hanji = __commonJS({
|
|
3369
3369
|
}
|
3370
3370
|
};
|
3371
3371
|
exports2.TaskTerminal = TaskTerminal;
|
3372
|
-
function render6(
|
3372
|
+
function render6(view2) {
|
3373
3373
|
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
3374
|
-
if (
|
3375
|
-
const terminal = new Terminal(
|
3374
|
+
if (view2 instanceof Prompt3) {
|
3375
|
+
const terminal = new Terminal(view2, stdin, stdout, closable);
|
3376
3376
|
terminal.requestLayout();
|
3377
3377
|
return terminal.result();
|
3378
3378
|
}
|
3379
|
-
stdout.write(`${
|
3379
|
+
stdout.write(`${view2}
|
3380
3380
|
`);
|
3381
3381
|
closable.close();
|
3382
3382
|
return;
|
3383
3383
|
}
|
3384
3384
|
exports2.render = render6;
|
3385
|
-
function renderWithTask4(
|
3385
|
+
function renderWithTask4(view2, task) {
|
3386
3386
|
return __awaiter2(this, void 0, void 0, function* () {
|
3387
|
-
const terminal = new TaskTerminal(
|
3387
|
+
const terminal = new TaskTerminal(view2, process.stdout);
|
3388
3388
|
terminal.requestLayout();
|
3389
3389
|
const result = yield task;
|
3390
3390
|
terminal.clear();
|
@@ -7499,7 +7499,7 @@ var init_vector = __esm({
|
|
7499
7499
|
});
|
7500
7500
|
|
7501
7501
|
// src/serializer/pgSchema.ts
|
7502
|
-
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7502
|
+
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, viewWithOption, matViewWithOption, mergedViewWithOption, view, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7503
7503
|
var init_pgSchema = __esm({
|
7504
7504
|
"src/serializer/pgSchema.ts"() {
|
7505
7505
|
"use strict";
|
@@ -7694,6 +7694,44 @@ var init_pgSchema = __esm({
|
|
7694
7694
|
columns: stringType().array(),
|
7695
7695
|
nullsNotDistinct: booleanType()
|
7696
7696
|
}).strict();
|
7697
|
+
viewWithOption = objectType({
|
7698
|
+
checkOption: enumType(["local", "cascaded"]).optional(),
|
7699
|
+
securityBarrier: booleanType().optional(),
|
7700
|
+
securityInvoker: booleanType().optional()
|
7701
|
+
}).strict();
|
7702
|
+
matViewWithOption = objectType({
|
7703
|
+
fillfactor: numberType().optional(),
|
7704
|
+
toastTupleTarget: numberType().optional(),
|
7705
|
+
parallelWorkers: numberType().optional(),
|
7706
|
+
autovacuumEnabled: booleanType().optional(),
|
7707
|
+
vacuumIndexCleanup: enumType(["auto", "off", "on"]).optional(),
|
7708
|
+
vacuumTruncate: booleanType().optional(),
|
7709
|
+
autovacuumVacuumThreshold: numberType().optional(),
|
7710
|
+
autovacuumVacuumScaleFactor: numberType().optional(),
|
7711
|
+
autovacuumVacuumCostDelay: numberType().optional(),
|
7712
|
+
autovacuumVacuumCostLimit: numberType().optional(),
|
7713
|
+
autovacuumFreezeMinAge: numberType().optional(),
|
7714
|
+
autovacuumFreezeMaxAge: numberType().optional(),
|
7715
|
+
autovacuumFreezeTableAge: numberType().optional(),
|
7716
|
+
autovacuumMultixactFreezeMinAge: numberType().optional(),
|
7717
|
+
autovacuumMultixactFreezeMaxAge: numberType().optional(),
|
7718
|
+
autovacuumMultixactFreezeTableAge: numberType().optional(),
|
7719
|
+
logAutovacuumMinDuration: numberType().optional(),
|
7720
|
+
userCatalogTable: booleanType().optional()
|
7721
|
+
}).strict();
|
7722
|
+
mergedViewWithOption = viewWithOption.merge(matViewWithOption);
|
7723
|
+
view = objectType({
|
7724
|
+
name: stringType(),
|
7725
|
+
schema: stringType(),
|
7726
|
+
columns: recordType(stringType(), column2),
|
7727
|
+
definition: stringType().optional(),
|
7728
|
+
materialized: booleanType(),
|
7729
|
+
with: mergedViewWithOption.optional(),
|
7730
|
+
isExisting: booleanType(),
|
7731
|
+
withNoData: booleanType().optional(),
|
7732
|
+
using: stringType().optional(),
|
7733
|
+
tablespace: stringType().optional()
|
7734
|
+
}).strict();
|
7697
7735
|
tableV42 = objectType({
|
7698
7736
|
name: stringType(),
|
7699
7737
|
schema: stringType(),
|
@@ -7828,6 +7866,7 @@ var init_pgSchema = __esm({
|
|
7828
7866
|
tables: recordType(stringType(), table2),
|
7829
7867
|
enums: recordType(stringType(), enumSchema),
|
7830
7868
|
schemas: recordType(stringType(), stringType()),
|
7869
|
+
views: recordType(stringType(), view).default({}),
|
7831
7870
|
sequences: recordType(stringType(), sequenceSchema).default({}),
|
7832
7871
|
_meta: objectType({
|
7833
7872
|
schemas: recordType(stringType(), stringType()),
|
@@ -7872,6 +7911,7 @@ var init_pgSchema = __esm({
|
|
7872
7911
|
tables: recordType(stringType(), tableSquashed2),
|
7873
7912
|
enums: recordType(stringType(), enumSchema),
|
7874
7913
|
schemas: recordType(stringType(), stringType()),
|
7914
|
+
views: recordType(stringType(), view),
|
7875
7915
|
sequences: recordType(stringType(), sequenceSquashed)
|
7876
7916
|
}).strict();
|
7877
7917
|
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
@@ -8089,6 +8129,7 @@ var init_pgSchema = __esm({
|
|
8089
8129
|
tables: mappedTables,
|
8090
8130
|
enums: json3.enums,
|
8091
8131
|
schemas: json3.schemas,
|
8132
|
+
views: json3.views,
|
8092
8133
|
sequences: mappedSequences
|
8093
8134
|
};
|
8094
8135
|
};
|
@@ -11048,6 +11089,7 @@ function applyJsonDiff(json1, json22) {
|
|
11048
11089
|
difference.tables = difference.tables || {};
|
11049
11090
|
difference.enums = difference.enums || {};
|
11050
11091
|
difference.sequences = difference.sequences || {};
|
11092
|
+
difference.views = difference.views || {};
|
11051
11093
|
const schemaKeys = Object.keys(difference.schemas);
|
11052
11094
|
for (let key of schemaKeys) {
|
11053
11095
|
if (key.endsWith("__added") || key.endsWith("__deleted")) {
|
@@ -11103,6 +11145,65 @@ function applyJsonDiff(json1, json22) {
|
|
11103
11145
|
const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
|
11104
11146
|
return json22.sequences[it[0]];
|
11105
11147
|
});
|
11148
|
+
const viewsEntries = Object.entries(difference.views);
|
11149
|
+
const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
|
11150
|
+
([nameWithSchema, view2]) => {
|
11151
|
+
const deletedWithOption = view2.with__deleted;
|
11152
|
+
const addedWithOption = view2.with__added;
|
11153
|
+
const deletedWith = Object.fromEntries(
|
11154
|
+
Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__deleted")).map(([key, value]) => {
|
11155
|
+
return [key.replace("__deleted", ""), value];
|
11156
|
+
})
|
11157
|
+
);
|
11158
|
+
const addedWith = Object.fromEntries(
|
11159
|
+
Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__added")).map(([key, value]) => {
|
11160
|
+
return [key.replace("__added", ""), value];
|
11161
|
+
})
|
11162
|
+
);
|
11163
|
+
const alterWith = Object.fromEntries(
|
11164
|
+
Object.entries(view2.with || {}).filter(
|
11165
|
+
(it) => typeof it[1].__old !== "undefined" && typeof it[1].__new !== "undefined"
|
11166
|
+
).map(
|
11167
|
+
(it) => {
|
11168
|
+
return [it[0], it[1].__new];
|
11169
|
+
}
|
11170
|
+
)
|
11171
|
+
);
|
11172
|
+
const alteredSchema = view2.schema;
|
11173
|
+
const alteredDefinition = view2.definition;
|
11174
|
+
const alteredExisting = view2.isExisting;
|
11175
|
+
const addedTablespace = view2.tablespace__added;
|
11176
|
+
const droppedTablespace = view2.tablespace__deleted;
|
11177
|
+
const alterTablespaceTo = view2.tablespace;
|
11178
|
+
let alteredTablespace;
|
11179
|
+
if (addedTablespace) alteredTablespace = { __new: addedTablespace, __old: "pg_default" };
|
11180
|
+
if (droppedTablespace) alteredTablespace = { __new: "pg_default", __old: droppedTablespace };
|
11181
|
+
if (alterTablespaceTo) alteredTablespace = alterTablespaceTo;
|
11182
|
+
const addedUsing = view2.using__added;
|
11183
|
+
const droppedUsing = view2.using__deleted;
|
11184
|
+
const alterUsingTo = view2.using;
|
11185
|
+
let alteredUsing;
|
11186
|
+
if (addedUsing) alteredUsing = { __new: addedUsing, __old: "heap" };
|
11187
|
+
if (droppedUsing) alteredUsing = { __new: "heap", __old: droppedUsing };
|
11188
|
+
if (alterUsingTo) alteredUsing = alterUsingTo;
|
11189
|
+
return {
|
11190
|
+
name: json22.views[nameWithSchema].name,
|
11191
|
+
schema: json22.views[nameWithSchema].schema,
|
11192
|
+
deletedWithOption,
|
11193
|
+
addedWithOption,
|
11194
|
+
alteredWith: {
|
11195
|
+
deletedWith: Object.keys(deletedWith).length ? deletedWith : void 0,
|
11196
|
+
addedWith: Object.keys(addedWith).length ? addedWith : void 0,
|
11197
|
+
alterWith: Object.keys(alterWith).length ? alterWith : void 0
|
11198
|
+
},
|
11199
|
+
alteredSchema,
|
11200
|
+
alteredDefinition,
|
11201
|
+
alteredExisting,
|
11202
|
+
alteredTablespace,
|
11203
|
+
alteredUsing
|
11204
|
+
};
|
11205
|
+
}
|
11206
|
+
);
|
11106
11207
|
const alteredTablesWithColumns = Object.values(difference.tables).map(
|
11107
11208
|
(table4) => {
|
11108
11209
|
return findAlternationsInTable(table4);
|
@@ -11111,7 +11212,8 @@ function applyJsonDiff(json1, json22) {
|
|
11111
11212
|
return {
|
11112
11213
|
alteredTablesWithColumns,
|
11113
11214
|
alteredEnums,
|
11114
|
-
alteredSequences
|
11215
|
+
alteredSequences,
|
11216
|
+
alteredViews
|
11115
11217
|
};
|
11116
11218
|
}
|
11117
11219
|
var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
|
@@ -11506,7 +11608,7 @@ function fromJson(statements, dialect7, action, json22) {
|
|
11506
11608
|
}).filter((it) => it !== "");
|
11507
11609
|
return result;
|
11508
11610
|
}
|
11509
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
11611
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, PgDropViewConvertor, PgRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
11510
11612
|
var init_sqlgenerator = __esm({
|
11511
11613
|
"src/sqlgenerator.ts"() {
|
11512
11614
|
"use strict";
|
@@ -11719,6 +11821,114 @@ var init_sqlgenerator = __esm({
|
|
11719
11821
|
return statement;
|
11720
11822
|
}
|
11721
11823
|
};
|
11824
|
+
PgCreateViewConvertor = class extends Convertor {
|
11825
|
+
can(statement, dialect7) {
|
11826
|
+
return statement.type === "create_view" && dialect7 === "postgresql";
|
11827
|
+
}
|
11828
|
+
convert(st) {
|
11829
|
+
const { definition, name: viewName, schema: schema4, with: withOption, materialized, withNoData, tablespace, using } = st;
|
11830
|
+
const name2 = schema4 ? `"${schema4}"."${viewName}"` : `"${viewName}"`;
|
11831
|
+
let statement = materialized ? `CREATE MATERIALIZED VIEW ${name2}` : `CREATE VIEW ${name2}`;
|
11832
|
+
if (using) statement += ` USING "${using}"`;
|
11833
|
+
const options = [];
|
11834
|
+
if (withOption) {
|
11835
|
+
statement += ` WITH (`;
|
11836
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
11837
|
+
if (typeof value === "undefined") return;
|
11838
|
+
options.push(`${key.snake_case()} = ${value}`);
|
11839
|
+
});
|
11840
|
+
statement += options.join(", ");
|
11841
|
+
statement += `)`;
|
11842
|
+
}
|
11843
|
+
if (tablespace) statement += ` TABLESPACE ${tablespace}`;
|
11844
|
+
statement += ` AS (${definition})`;
|
11845
|
+
if (withNoData) statement += ` WITH NO DATA`;
|
11846
|
+
statement += `;`;
|
11847
|
+
return statement;
|
11848
|
+
}
|
11849
|
+
};
|
11850
|
+
PgDropViewConvertor = class extends Convertor {
|
11851
|
+
can(statement, dialect7) {
|
11852
|
+
return statement.type === "drop_view" && dialect7 === "postgresql";
|
11853
|
+
}
|
11854
|
+
convert(st) {
|
11855
|
+
const { name: viewName, schema: schema4, materialized } = st;
|
11856
|
+
const name2 = schema4 ? `"${schema4}"."${viewName}"` : `"${viewName}"`;
|
11857
|
+
return `DROP${materialized ? " MATERIALIZED" : ""} VIEW ${name2};`;
|
11858
|
+
}
|
11859
|
+
};
|
11860
|
+
PgRenameViewConvertor = class extends Convertor {
|
11861
|
+
can(statement, dialect7) {
|
11862
|
+
return statement.type === "rename_view" && dialect7 === "postgresql";
|
11863
|
+
}
|
11864
|
+
convert(st) {
|
11865
|
+
const { nameFrom: from, nameTo: to2, schema: schema4, materialized } = st;
|
11866
|
+
const nameFrom = `"${schema4}"."${from}"`;
|
11867
|
+
return `ALTER${materialized ? " MATERIALIZED" : ""} VIEW ${nameFrom} RENAME TO "${to2}";`;
|
11868
|
+
}
|
11869
|
+
};
|
11870
|
+
PgAlterViewSchemaConvertor = class extends Convertor {
|
11871
|
+
can(statement, dialect7) {
|
11872
|
+
return statement.type === "alter_view_alter_schema" && dialect7 === "postgresql";
|
11873
|
+
}
|
11874
|
+
convert(st) {
|
11875
|
+
const { fromSchema, toSchema, name: name2, materialized } = st;
|
11876
|
+
const statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${fromSchema}"."${name2}" SET SCHEMA "${toSchema}";`;
|
11877
|
+
return statement;
|
11878
|
+
}
|
11879
|
+
};
|
11880
|
+
PgAlterViewAddWithOptionConvertor = class extends Convertor {
|
11881
|
+
can(statement, dialect7) {
|
11882
|
+
return statement.type === "alter_view_add_with_option" && dialect7 === "postgresql";
|
11883
|
+
}
|
11884
|
+
convert(st) {
|
11885
|
+
const { schema: schema4, with: withOption, name: name2, materialized } = st;
|
11886
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema4}"."${name2}" SET (`;
|
11887
|
+
const options = [];
|
11888
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
11889
|
+
options.push(`${key.snake_case()} = ${value}`);
|
11890
|
+
});
|
11891
|
+
statement += options.join(", ");
|
11892
|
+
statement += `);`;
|
11893
|
+
return statement;
|
11894
|
+
}
|
11895
|
+
};
|
11896
|
+
PgAlterViewDropWithOptionConvertor = class extends Convertor {
|
11897
|
+
can(statement, dialect7) {
|
11898
|
+
return statement.type === "alter_view_drop_with_option" && dialect7 === "postgresql";
|
11899
|
+
}
|
11900
|
+
convert(st) {
|
11901
|
+
const { schema: schema4, name: name2, materialized, with: withOptions } = st;
|
11902
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema4}"."${name2}" RESET (`;
|
11903
|
+
const options = [];
|
11904
|
+
Object.entries(withOptions).forEach(([key, value]) => {
|
11905
|
+
options.push(`${key.snake_case()}`);
|
11906
|
+
});
|
11907
|
+
statement += options.join(", ");
|
11908
|
+
statement += ");";
|
11909
|
+
return statement;
|
11910
|
+
}
|
11911
|
+
};
|
11912
|
+
PgAlterViewAlterTablespaceConvertor = class extends Convertor {
|
11913
|
+
can(statement, dialect7) {
|
11914
|
+
return statement.type === "alter_view_alter_tablespace" && dialect7 === "postgresql";
|
11915
|
+
}
|
11916
|
+
convert(st) {
|
11917
|
+
const { schema: schema4, name: name2, toTablespace } = st;
|
11918
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema4}"."${name2}" SET TABLESPACE ${toTablespace};`;
|
11919
|
+
return statement;
|
11920
|
+
}
|
11921
|
+
};
|
11922
|
+
PgAlterViewAlterUsingConvertor = class extends Convertor {
|
11923
|
+
can(statement, dialect7) {
|
11924
|
+
return statement.type === "alter_view_alter_using" && dialect7 === "postgresql";
|
11925
|
+
}
|
11926
|
+
convert(st) {
|
11927
|
+
const { schema: schema4, name: name2, toUsing } = st;
|
11928
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema4}"."${name2}" SET ACCESS METHOD "${toUsing}";`;
|
11929
|
+
return statement;
|
11930
|
+
}
|
11931
|
+
};
|
11722
11932
|
PgAlterTableAlterColumnSetGenerated = class extends Convertor {
|
11723
11933
|
can(statement, dialect7) {
|
11724
11934
|
return statement.type === "alter_table_alter_column_set_identity" && dialect7 === "postgresql";
|
@@ -13054,6 +13264,14 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13054
13264
|
convertors.push(new SQLiteCreateTableConvertor());
|
13055
13265
|
convertors.push(new SQLiteRecreateTableConvertor());
|
13056
13266
|
convertors.push(new LibSQLRecreateTableConvertor());
|
13267
|
+
convertors.push(new PgCreateViewConvertor());
|
13268
|
+
convertors.push(new PgDropViewConvertor());
|
13269
|
+
convertors.push(new PgRenameViewConvertor());
|
13270
|
+
convertors.push(new PgAlterViewSchemaConvertor());
|
13271
|
+
convertors.push(new PgAlterViewAddWithOptionConvertor());
|
13272
|
+
convertors.push(new PgAlterViewDropWithOptionConvertor());
|
13273
|
+
convertors.push(new PgAlterViewAlterTablespaceConvertor());
|
13274
|
+
convertors.push(new PgAlterViewAlterUsingConvertor());
|
13057
13275
|
convertors.push(new CreateTypeEnumConvertor());
|
13058
13276
|
convertors.push(new CreatePgSequenceConvertor());
|
13059
13277
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13387,7 +13605,7 @@ var init_sqlitePushUtils = __esm({
|
|
13387
13605
|
});
|
13388
13606
|
|
13389
13607
|
// src/jsonStatements.ts
|
13390
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13608
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql, preparePgCreateViewJson, preparePgDropViewJson, preparePgRenameViewJson, preparePgAlterViewAlterSchemaJson, preparePgAlterViewAddWithOptionJson, preparePgAlterViewDropWithOptionJson, preparePgAlterViewAlterTablespaceJson, preparePgAlterViewAlterUsingJson;
|
13391
13609
|
var init_jsonStatements = __esm({
|
13392
13610
|
"src/jsonStatements.ts"() {
|
13393
13611
|
"use strict";
|
@@ -14720,6 +14938,81 @@ var init_jsonStatements = __esm({
|
|
14720
14938
|
};
|
14721
14939
|
});
|
14722
14940
|
};
|
14941
|
+
preparePgCreateViewJson = (name2, schema4, definition, materialized, withNoData = false, withOption, using, tablespace) => {
|
14942
|
+
return {
|
14943
|
+
type: "create_view",
|
14944
|
+
name: name2,
|
14945
|
+
schema: schema4,
|
14946
|
+
definition,
|
14947
|
+
with: withOption,
|
14948
|
+
materialized,
|
14949
|
+
withNoData,
|
14950
|
+
using,
|
14951
|
+
tablespace
|
14952
|
+
};
|
14953
|
+
};
|
14954
|
+
preparePgDropViewJson = (name2, schema4, materialized) => {
|
14955
|
+
return {
|
14956
|
+
type: "drop_view",
|
14957
|
+
name: name2,
|
14958
|
+
schema: schema4,
|
14959
|
+
materialized
|
14960
|
+
};
|
14961
|
+
};
|
14962
|
+
preparePgRenameViewJson = (to2, from, schema4, materialized) => {
|
14963
|
+
return {
|
14964
|
+
type: "rename_view",
|
14965
|
+
nameTo: to2,
|
14966
|
+
nameFrom: from,
|
14967
|
+
schema: schema4,
|
14968
|
+
materialized
|
14969
|
+
};
|
14970
|
+
};
|
14971
|
+
preparePgAlterViewAlterSchemaJson = (to2, from, name2, materialized) => {
|
14972
|
+
return {
|
14973
|
+
type: "alter_view_alter_schema",
|
14974
|
+
fromSchema: from,
|
14975
|
+
toSchema: to2,
|
14976
|
+
name: name2,
|
14977
|
+
materialized
|
14978
|
+
};
|
14979
|
+
};
|
14980
|
+
preparePgAlterViewAddWithOptionJson = (name2, schema4, materialized, withOption) => {
|
14981
|
+
return {
|
14982
|
+
type: "alter_view_add_with_option",
|
14983
|
+
name: name2,
|
14984
|
+
schema: schema4,
|
14985
|
+
materialized,
|
14986
|
+
with: withOption
|
14987
|
+
};
|
14988
|
+
};
|
14989
|
+
preparePgAlterViewDropWithOptionJson = (name2, schema4, materialized, withOption) => {
|
14990
|
+
return {
|
14991
|
+
type: "alter_view_drop_with_option",
|
14992
|
+
name: name2,
|
14993
|
+
schema: schema4,
|
14994
|
+
materialized,
|
14995
|
+
with: withOption
|
14996
|
+
};
|
14997
|
+
};
|
14998
|
+
preparePgAlterViewAlterTablespaceJson = (name2, schema4, materialized, to2) => {
|
14999
|
+
return {
|
15000
|
+
type: "alter_view_alter_tablespace",
|
15001
|
+
name: name2,
|
15002
|
+
schema: schema4,
|
15003
|
+
materialized,
|
15004
|
+
toTablespace: to2
|
15005
|
+
};
|
15006
|
+
};
|
15007
|
+
preparePgAlterViewAlterUsingJson = (name2, schema4, materialized, to2) => {
|
15008
|
+
return {
|
15009
|
+
type: "alter_view_alter_using",
|
15010
|
+
name: name2,
|
15011
|
+
schema: schema4,
|
15012
|
+
materialized,
|
15013
|
+
toUsing: to2
|
15014
|
+
};
|
15015
|
+
};
|
14723
15016
|
}
|
14724
15017
|
});
|
14725
15018
|
|
@@ -15008,6 +15301,7 @@ var init_statementCombiner = __esm({
|
|
15008
15301
|
var snapshotsDiffer_exports = {};
|
15009
15302
|
__export(snapshotsDiffer_exports, {
|
15010
15303
|
alteredTableScheme: () => alteredTableScheme,
|
15304
|
+
alteredViewSchema: () => alteredViewSchema,
|
15011
15305
|
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
15012
15306
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
15013
15307
|
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
@@ -15018,7 +15312,7 @@ __export(snapshotsDiffer_exports, {
|
|
15018
15312
|
makePatched: () => makePatched,
|
15019
15313
|
makeSelfOrPatched: () => makeSelfOrPatched
|
15020
15314
|
});
|
15021
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
15315
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, alteredViewSchema, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
15022
15316
|
var init_snapshotsDiffer = __esm({
|
15023
15317
|
"src/snapshotsDiffer.ts"() {
|
15024
15318
|
"use strict";
|
@@ -15187,10 +15481,42 @@ var init_snapshotsDiffer = __esm({
|
|
15187
15481
|
})
|
15188
15482
|
)
|
15189
15483
|
}).strict();
|
15484
|
+
alteredViewSchema = objectType({
|
15485
|
+
name: stringType(),
|
15486
|
+
schema: stringType(),
|
15487
|
+
deletedWithOption: mergedViewWithOption.optional(),
|
15488
|
+
addedWithOption: mergedViewWithOption.optional(),
|
15489
|
+
alteredWith: objectType({
|
15490
|
+
addedWith: mergedViewWithOption.optional(),
|
15491
|
+
deletedWith: mergedViewWithOption.optional(),
|
15492
|
+
alterWith: mergedViewWithOption.optional()
|
15493
|
+
}).strict(),
|
15494
|
+
alteredSchema: objectType({
|
15495
|
+
__old: stringType(),
|
15496
|
+
__new: stringType()
|
15497
|
+
}).strict().optional(),
|
15498
|
+
alteredDefinition: objectType({
|
15499
|
+
__old: stringType(),
|
15500
|
+
__new: stringType()
|
15501
|
+
}).strict().optional(),
|
15502
|
+
alteredExisting: objectType({
|
15503
|
+
__old: booleanType(),
|
15504
|
+
__new: booleanType()
|
15505
|
+
}).strict().optional(),
|
15506
|
+
alteredTablespace: objectType({
|
15507
|
+
__old: stringType(),
|
15508
|
+
__new: stringType()
|
15509
|
+
}).strict().optional(),
|
15510
|
+
alteredUsing: objectType({
|
15511
|
+
__old: stringType(),
|
15512
|
+
__new: stringType()
|
15513
|
+
}).strict().optional()
|
15514
|
+
}).strict();
|
15190
15515
|
diffResultScheme = objectType({
|
15191
15516
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
15192
15517
|
alteredEnums: changedEnumSchema.array(),
|
15193
|
-
alteredSequences: sequenceSquashed.array()
|
15518
|
+
alteredSequences: sequenceSquashed.array(),
|
15519
|
+
alteredViews: alteredViewSchema.array()
|
15194
15520
|
}).strict();
|
15195
15521
|
diffResultSchemeMysql = objectType({
|
15196
15522
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
@@ -15245,7 +15571,7 @@ var init_snapshotsDiffer = __esm({
|
|
15245
15571
|
}
|
15246
15572
|
return column4;
|
15247
15573
|
};
|
15248
|
-
applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
15574
|
+
applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
15249
15575
|
const schemasDiff = diffSchemasOrTables(json1.schemas, json22.schemas);
|
15250
15576
|
const {
|
15251
15577
|
created: createdSchemas,
|
@@ -15473,7 +15799,39 @@ var init_snapshotsDiffer = __esm({
|
|
15473
15799
|
return [tableKey2, tableValue];
|
15474
15800
|
}
|
15475
15801
|
);
|
15476
|
-
const
|
15802
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json22.views);
|
15803
|
+
const {
|
15804
|
+
created: createdViews,
|
15805
|
+
deleted: deletedViews,
|
15806
|
+
renamed: renamedViews,
|
15807
|
+
moved: movedViews
|
15808
|
+
} = await viewsResolver2({
|
15809
|
+
created: viewsDiff.added,
|
15810
|
+
deleted: viewsDiff.deleted
|
15811
|
+
});
|
15812
|
+
const renamesViewDic = {};
|
15813
|
+
renamedViews.forEach((it) => {
|
15814
|
+
renamesViewDic[`${it.from.schema}.${it.from.name}`] = { to: it.to.name, from: it.from.name };
|
15815
|
+
});
|
15816
|
+
const movedViewDic = {};
|
15817
|
+
movedViews.forEach((it) => {
|
15818
|
+
movedViewDic[`${it.schemaFrom}.${it.name}`] = { to: it.schemaTo, from: it.schemaFrom };
|
15819
|
+
});
|
15820
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
15821
|
+
viewsPatchedSnap1.views = mapEntries(
|
15822
|
+
viewsPatchedSnap1.views,
|
15823
|
+
(viewKey, viewValue) => {
|
15824
|
+
const rename = renamesViewDic[`${viewValue.schema}.${viewValue.name}`];
|
15825
|
+
const moved = movedViewDic[`${viewValue.schema}.${viewValue.name}`];
|
15826
|
+
if (rename) {
|
15827
|
+
viewValue.name = rename.to;
|
15828
|
+
viewKey = `${viewValue.schema}.${viewValue.name}`;
|
15829
|
+
}
|
15830
|
+
if (moved) viewKey = `${moved.to}.${viewValue.name}`;
|
15831
|
+
return [viewKey, viewValue];
|
15832
|
+
}
|
15833
|
+
);
|
15834
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json22);
|
15477
15835
|
const typedResult = diffResultScheme.parse(diffResult);
|
15478
15836
|
const jsonStatements = [];
|
15479
15837
|
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
@@ -15725,6 +16083,137 @@ var init_snapshotsDiffer = __esm({
|
|
15725
16083
|
const createTables = createdTables.map((it) => {
|
15726
16084
|
return preparePgCreateTableJson(it, curFull);
|
15727
16085
|
});
|
16086
|
+
const createViews = [];
|
16087
|
+
const dropViews = [];
|
16088
|
+
const renameViews = [];
|
16089
|
+
const alterViews = [];
|
16090
|
+
createViews.push(
|
16091
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
16092
|
+
return preparePgCreateViewJson(
|
16093
|
+
it.name,
|
16094
|
+
it.schema,
|
16095
|
+
it.definition,
|
16096
|
+
it.materialized,
|
16097
|
+
it.withNoData,
|
16098
|
+
it.with,
|
16099
|
+
it.using,
|
16100
|
+
it.tablespace
|
16101
|
+
);
|
16102
|
+
})
|
16103
|
+
);
|
16104
|
+
dropViews.push(
|
16105
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
16106
|
+
return preparePgDropViewJson(it.name, it.schema, it.materialized);
|
16107
|
+
})
|
16108
|
+
);
|
16109
|
+
renameViews.push(
|
16110
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
16111
|
+
return preparePgRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
|
16112
|
+
})
|
16113
|
+
);
|
16114
|
+
alterViews.push(
|
16115
|
+
...movedViews.filter((it) => !json22.views[`${it.schemaTo}.${it.name}`].isExisting).map((it) => {
|
16116
|
+
return preparePgAlterViewAlterSchemaJson(
|
16117
|
+
it.schemaTo,
|
16118
|
+
it.schemaFrom,
|
16119
|
+
it.name,
|
16120
|
+
json22.views[`${it.schemaTo}.${it.name}`].materialized
|
16121
|
+
);
|
16122
|
+
})
|
16123
|
+
);
|
16124
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json22.views[`${it.schema}.${it.name}`].isExisting);
|
16125
|
+
for (const alteredView of alteredViews) {
|
16126
|
+
const viewKey = `${alteredView.schema}.${alteredView.name}`;
|
16127
|
+
const { materialized, with: withOption, definition, withNoData, using, tablespace } = json22.views[viewKey];
|
16128
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
16129
|
+
dropViews.push(preparePgDropViewJson(alteredView.name, alteredView.schema, materialized));
|
16130
|
+
createViews.push(
|
16131
|
+
preparePgCreateViewJson(
|
16132
|
+
alteredView.name,
|
16133
|
+
alteredView.schema,
|
16134
|
+
definition,
|
16135
|
+
materialized,
|
16136
|
+
withNoData,
|
16137
|
+
withOption,
|
16138
|
+
using,
|
16139
|
+
tablespace
|
16140
|
+
)
|
16141
|
+
);
|
16142
|
+
continue;
|
16143
|
+
}
|
16144
|
+
if (alteredView.addedWithOption) {
|
16145
|
+
alterViews.push(
|
16146
|
+
preparePgAlterViewAddWithOptionJson(
|
16147
|
+
alteredView.name,
|
16148
|
+
alteredView.schema,
|
16149
|
+
materialized,
|
16150
|
+
alteredView.addedWithOption
|
16151
|
+
)
|
16152
|
+
);
|
16153
|
+
}
|
16154
|
+
if (alteredView.deletedWithOption) {
|
16155
|
+
alterViews.push(
|
16156
|
+
preparePgAlterViewDropWithOptionJson(
|
16157
|
+
alteredView.name,
|
16158
|
+
alteredView.schema,
|
16159
|
+
materialized,
|
16160
|
+
alteredView.deletedWithOption
|
16161
|
+
)
|
16162
|
+
);
|
16163
|
+
}
|
16164
|
+
if (alteredView.alteredWith) {
|
16165
|
+
if (alteredView.alteredWith.addedWith) {
|
16166
|
+
alterViews.push(
|
16167
|
+
preparePgAlterViewAddWithOptionJson(
|
16168
|
+
alteredView.name,
|
16169
|
+
alteredView.schema,
|
16170
|
+
materialized,
|
16171
|
+
alteredView.alteredWith.addedWith
|
16172
|
+
)
|
16173
|
+
);
|
16174
|
+
}
|
16175
|
+
if (alteredView.alteredWith.deletedWith) {
|
16176
|
+
alterViews.push(
|
16177
|
+
preparePgAlterViewDropWithOptionJson(
|
16178
|
+
alteredView.name,
|
16179
|
+
alteredView.schema,
|
16180
|
+
materialized,
|
16181
|
+
alteredView.alteredWith.deletedWith
|
16182
|
+
)
|
16183
|
+
);
|
16184
|
+
}
|
16185
|
+
if (alteredView.alteredWith.alterWith) {
|
16186
|
+
alterViews.push(
|
16187
|
+
preparePgAlterViewAddWithOptionJson(
|
16188
|
+
alteredView.name,
|
16189
|
+
alteredView.schema,
|
16190
|
+
materialized,
|
16191
|
+
alteredView.alteredWith.alterWith
|
16192
|
+
)
|
16193
|
+
);
|
16194
|
+
}
|
16195
|
+
}
|
16196
|
+
if (alteredView.alteredTablespace) {
|
16197
|
+
alterViews.push(
|
16198
|
+
preparePgAlterViewAlterTablespaceJson(
|
16199
|
+
alteredView.name,
|
16200
|
+
alteredView.schema,
|
16201
|
+
materialized,
|
16202
|
+
alteredView.alteredTablespace.__new
|
16203
|
+
)
|
16204
|
+
);
|
16205
|
+
}
|
16206
|
+
if (alteredView.alteredUsing) {
|
16207
|
+
alterViews.push(
|
16208
|
+
preparePgAlterViewAlterUsingJson(
|
16209
|
+
alteredView.name,
|
16210
|
+
alteredView.schema,
|
16211
|
+
materialized,
|
16212
|
+
alteredView.alteredUsing.__new
|
16213
|
+
)
|
16214
|
+
);
|
16215
|
+
}
|
16216
|
+
}
|
15728
16217
|
jsonStatements.push(...createSchemas);
|
15729
16218
|
jsonStatements.push(...renameSchemas);
|
15730
16219
|
jsonStatements.push(...createEnums);
|
@@ -15736,6 +16225,9 @@ var init_snapshotsDiffer = __esm({
|
|
15736
16225
|
jsonStatements.push(...renameSequences);
|
15737
16226
|
jsonStatements.push(...jsonAlterSequences);
|
15738
16227
|
jsonStatements.push(...createTables);
|
16228
|
+
jsonStatements.push(...dropViews);
|
16229
|
+
jsonStatements.push(...renameViews);
|
16230
|
+
jsonStatements.push(...alterViews);
|
15739
16231
|
jsonStatements.push(...jsonDropTables);
|
15740
16232
|
jsonStatements.push(...jsonSetTableSchemas);
|
15741
16233
|
jsonStatements.push(...jsonRenameTables);
|
@@ -15755,6 +16247,7 @@ var init_snapshotsDiffer = __esm({
|
|
15755
16247
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15756
16248
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15757
16249
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16250
|
+
jsonStatements.push(...createViews);
|
15758
16251
|
jsonStatements.push(...dropEnums);
|
15759
16252
|
jsonStatements.push(...dropSequences);
|
15760
16253
|
jsonStatements.push(...dropSchemas);
|
@@ -16823,7 +17316,7 @@ var init_outputs = __esm({
|
|
16823
17316
|
});
|
16824
17317
|
|
16825
17318
|
// src/cli/commands/migrate.ts
|
16826
|
-
var import_hanji2, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
|
17319
|
+
var import_hanji2, schemasResolver, tablesResolver, viewsResolver, sequencesResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
|
16827
17320
|
var init_migrate = __esm({
|
16828
17321
|
"src/cli/commands/migrate.ts"() {
|
16829
17322
|
"use strict";
|
@@ -16868,6 +17361,24 @@ var init_migrate = __esm({
|
|
16868
17361
|
throw e5;
|
16869
17362
|
}
|
16870
17363
|
};
|
17364
|
+
viewsResolver = async (input) => {
|
17365
|
+
try {
|
17366
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
17367
|
+
input.created,
|
17368
|
+
input.deleted,
|
17369
|
+
"view"
|
17370
|
+
);
|
17371
|
+
return {
|
17372
|
+
created,
|
17373
|
+
deleted,
|
17374
|
+
moved,
|
17375
|
+
renamed
|
17376
|
+
};
|
17377
|
+
} catch (e5) {
|
17378
|
+
console.error(e5);
|
17379
|
+
throw e5;
|
17380
|
+
}
|
17381
|
+
};
|
16871
17382
|
sequencesResolver = async (input) => {
|
16872
17383
|
try {
|
16873
17384
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -19058,7 +19569,7 @@ function fillPlaceholders(params, values2) {
|
|
19058
19569
|
return p7;
|
19059
19570
|
});
|
19060
19571
|
}
|
19061
|
-
var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, _a25, _b10,
|
19572
|
+
var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, _a25, _b10, View4;
|
19062
19573
|
var init_sql = __esm({
|
19063
19574
|
"../drizzle-orm/dist/sql/sql.js"() {
|
19064
19575
|
"use strict";
|
@@ -19161,7 +19672,7 @@ var init_sql = __esm({
|
|
19161
19672
|
}
|
19162
19673
|
return { sql: escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName), params: [] };
|
19163
19674
|
}
|
19164
|
-
if (is(chunk,
|
19675
|
+
if (is(chunk, View4)) {
|
19165
19676
|
const schemaName = chunk[ViewBaseConfig].schema;
|
19166
19677
|
const viewName = chunk[ViewBaseConfig].name;
|
19167
19678
|
return {
|
@@ -19380,7 +19891,7 @@ var init_sql = __esm({
|
|
19380
19891
|
};
|
19381
19892
|
__publicField(Placeholder, _a24, "Placeholder");
|
19382
19893
|
_b10 = entityKind, _a25 = ViewBaseConfig;
|
19383
|
-
|
19894
|
+
View4 = class {
|
19384
19895
|
constructor({ name: name2, schema: schema4, selectedFields, query }) {
|
19385
19896
|
/** @internal */
|
19386
19897
|
__publicField(this, _a25);
|
@@ -19398,7 +19909,7 @@ var init_sql = __esm({
|
|
19398
19909
|
return new SQL([this]);
|
19399
19910
|
}
|
19400
19911
|
};
|
19401
|
-
__publicField(
|
19912
|
+
__publicField(View4, _b10, "View");
|
19402
19913
|
Column2.prototype.getSQL = function() {
|
19403
19914
|
return new SQL([this]);
|
19404
19915
|
};
|
@@ -19549,7 +20060,7 @@ var init_errors = __esm({
|
|
19549
20060
|
|
19550
20061
|
// ../drizzle-orm/dist/sql/expressions/conditions.js
|
19551
20062
|
function bindIfParam(value, column4) {
|
19552
|
-
if (isDriverValueEncoder(column4) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column2) && !is(value, Table2) && !is(value,
|
20063
|
+
if (isDriverValueEncoder(column4) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column2) && !is(value, Table2) && !is(value, View4)) {
|
19553
20064
|
return new Param(value, column4);
|
19554
20065
|
}
|
19555
20066
|
return value;
|
@@ -20850,12 +21361,12 @@ var require_utils2 = __commonJS({
|
|
20850
21361
|
}
|
20851
21362
|
return JSON.stringify(val2);
|
20852
21363
|
}
|
20853
|
-
function pad(
|
20854
|
-
|
20855
|
-
while (
|
20856
|
-
|
21364
|
+
function pad(number2, digits) {
|
21365
|
+
number2 = "" + number2;
|
21366
|
+
while (number2.length < digits) {
|
21367
|
+
number2 = "0" + number2;
|
20857
21368
|
}
|
20858
|
-
return
|
21369
|
+
return number2;
|
20859
21370
|
}
|
20860
21371
|
function dateToString(date3) {
|
20861
21372
|
var offset = -date3.getTimezoneOffset();
|
@@ -24532,7 +25043,7 @@ function getTableColumns(table4) {
|
|
24532
25043
|
return table4[Table2.Symbol.Columns];
|
24533
25044
|
}
|
24534
25045
|
function getTableLikeName(table4) {
|
24535
|
-
return is(table4, Subquery) ? table4._.alias : is(table4,
|
25046
|
+
return is(table4, Subquery) ? table4._.alias : is(table4, View4) ? table4[ViewBaseConfig].name : is(table4, SQL) ? void 0 : table4[Table2.Symbol.IsAlias] ? table4[Table2.Symbol.Name] : table4[Table2.Symbol.BaseName];
|
24536
25047
|
}
|
24537
25048
|
function getColumnNameAndConfig(a7, b8) {
|
24538
25049
|
return {
|
@@ -25753,23 +26264,23 @@ function hexToBytes(hex2) {
|
|
25753
26264
|
}
|
25754
26265
|
function bytesToFloat64(bytes2, offset) {
|
25755
26266
|
const buffer2 = new ArrayBuffer(8);
|
25756
|
-
const
|
26267
|
+
const view2 = new DataView(buffer2);
|
25757
26268
|
for (let i5 = 0; i5 < 8; i5++) {
|
25758
|
-
|
26269
|
+
view2.setUint8(i5, bytes2[offset + i5]);
|
25759
26270
|
}
|
25760
|
-
return
|
26271
|
+
return view2.getFloat64(0, true);
|
25761
26272
|
}
|
25762
26273
|
function parseEWKB(hex2) {
|
25763
26274
|
const bytes2 = hexToBytes(hex2);
|
25764
26275
|
let offset = 0;
|
25765
26276
|
const byteOrder = bytes2[offset];
|
25766
26277
|
offset += 1;
|
25767
|
-
const
|
25768
|
-
const geomType =
|
26278
|
+
const view2 = new DataView(bytes2.buffer);
|
26279
|
+
const geomType = view2.getUint32(offset, byteOrder === 1);
|
25769
26280
|
offset += 4;
|
25770
26281
|
let _srid;
|
25771
26282
|
if (geomType & 536870912) {
|
25772
|
-
_srid =
|
26283
|
+
_srid = view2.getUint32(offset, byteOrder === 1);
|
25773
26284
|
offset += 4;
|
25774
26285
|
}
|
25775
26286
|
if ((geomType & 65535) === 1) {
|
@@ -27008,7 +27519,7 @@ var init_view_base = __esm({
|
|
27008
27519
|
"use strict";
|
27009
27520
|
init_entity();
|
27010
27521
|
init_sql();
|
27011
|
-
PgViewBase = class extends (_b99 =
|
27522
|
+
PgViewBase = class extends (_b99 = View4, _a126 = entityKind, _b99) {
|
27012
27523
|
};
|
27013
27524
|
__publicField(PgViewBase, _a126, "PgViewBase");
|
27014
27525
|
}
|
@@ -27231,7 +27742,7 @@ var init_dialect = __esm({
|
|
27231
27742
|
joinsArray.push(
|
27232
27743
|
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
27233
27744
|
);
|
27234
|
-
} else if (is(table22,
|
27745
|
+
} else if (is(table22, View4)) {
|
27235
27746
|
const viewName = table22[ViewBaseConfig].name;
|
27236
27747
|
const viewSchema = table22[ViewBaseConfig].schema;
|
27237
27748
|
const origViewName = table22[ViewBaseConfig].originalName;
|
@@ -27368,10 +27879,10 @@ var init_dialect = __esm({
|
|
27368
27879
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
27369
27880
|
return sql`${withSql}insert into ${table4} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`;
|
27370
27881
|
}
|
27371
|
-
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
|
27882
|
+
buildRefreshMaterializedViewQuery({ view: view2, concurrently, withNoData }) {
|
27372
27883
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
27373
27884
|
const withNoDataSql = withNoData ? sql` with no data` : void 0;
|
27374
|
-
return sql`refresh materialized view${concurrentlySql} ${
|
27885
|
+
return sql`refresh materialized view${concurrentlySql} ${view2}${withNoDataSql}`;
|
27375
27886
|
}
|
27376
27887
|
prepareTyping(encoder) {
|
27377
27888
|
if (is(encoder, PgJsonb) || is(encoder, PgJson)) {
|
@@ -28145,7 +28656,7 @@ var init_selection_proxy = __esm({
|
|
28145
28656
|
if (typeof prop === "symbol") {
|
28146
28657
|
return subquery[prop];
|
28147
28658
|
}
|
28148
|
-
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery,
|
28659
|
+
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View4) ? subquery[ViewBaseConfig].selectedFields : subquery;
|
28149
28660
|
const value = columns[prop];
|
28150
28661
|
if (is(value, SQL.Aliased)) {
|
28151
28662
|
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
@@ -28627,7 +29138,7 @@ var init_select2 = __esm({
|
|
28627
29138
|
};
|
28628
29139
|
}
|
28629
29140
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
28630
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
29141
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View4) ? table4[ViewBaseConfig].selectedFields : table4[Table2.Symbol.Columns];
|
28631
29142
|
this.config.fields[tableName] = selection;
|
28632
29143
|
}
|
28633
29144
|
}
|
@@ -29046,7 +29557,7 @@ var init_refresh_materialized_view = __esm({
|
|
29046
29557
|
init_query_promise();
|
29047
29558
|
init_tracing();
|
29048
29559
|
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a134 = entityKind, _b102) {
|
29049
|
-
constructor(
|
29560
|
+
constructor(view2, session, dialect7) {
|
29050
29561
|
super();
|
29051
29562
|
__publicField(this, "config");
|
29052
29563
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -29056,7 +29567,7 @@ var init_refresh_materialized_view = __esm({
|
|
29056
29567
|
});
|
29057
29568
|
this.session = session;
|
29058
29569
|
this.dialect = dialect7;
|
29059
|
-
this.config = { view };
|
29570
|
+
this.config = { view: view2 };
|
29060
29571
|
}
|
29061
29572
|
concurrently() {
|
29062
29573
|
if (this.config.withNoData !== void 0) {
|
@@ -29687,8 +30198,8 @@ var init_db = __esm({
|
|
29687
30198
|
delete(table4) {
|
29688
30199
|
return new PgDeleteBase(table4, this.session, this.dialect);
|
29689
30200
|
}
|
29690
|
-
refreshMaterializedView(
|
29691
|
-
return new PgRefreshMaterializedView(
|
30201
|
+
refreshMaterializedView(view2) {
|
30202
|
+
return new PgRefreshMaterializedView(view2, this.session, this.dialect);
|
29692
30203
|
}
|
29693
30204
|
execute(query) {
|
29694
30205
|
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
@@ -29918,6 +30429,12 @@ function pgMaterializedViewWithSchema(name2, selection, schema4) {
|
|
29918
30429
|
}
|
29919
30430
|
return new MaterializedViewBuilder(name2, schema4);
|
29920
30431
|
}
|
30432
|
+
function isPgView(obj) {
|
30433
|
+
return is(obj, PgView);
|
30434
|
+
}
|
30435
|
+
function isPgMaterializedView(obj) {
|
30436
|
+
return is(obj, PgMaterializedView);
|
30437
|
+
}
|
29921
30438
|
var _a148, DefaultViewBuilderCore, _a149, _b107, ViewBuilder, _a150, _b108, ManualViewBuilder, _a151, MaterializedViewBuilderCore, _a152, _b109, MaterializedViewBuilder, _a153, _b110, ManualMaterializedViewBuilder, _a154, _b111, _c4, PgView, PgMaterializedViewConfig, _a155, _b112, _c5, PgMaterializedView;
|
29922
30439
|
var init_view = __esm({
|
29923
30440
|
"../drizzle-orm/dist/pg-core/view.js"() {
|
@@ -30081,7 +30598,12 @@ var init_view = __esm({
|
|
30081
30598
|
existing() {
|
30082
30599
|
return new Proxy(
|
30083
30600
|
new PgMaterializedView({
|
30084
|
-
pgConfig:
|
30601
|
+
pgConfig: {
|
30602
|
+
tablespace: this.config.tablespace,
|
30603
|
+
using: this.config.using,
|
30604
|
+
with: this.config.with,
|
30605
|
+
withNoData: this.config.withNoData
|
30606
|
+
},
|
30085
30607
|
config: {
|
30086
30608
|
name: this.name,
|
30087
30609
|
schema: this.schema,
|
@@ -30100,7 +30622,12 @@ var init_view = __esm({
|
|
30100
30622
|
as(query) {
|
30101
30623
|
return new Proxy(
|
30102
30624
|
new PgMaterializedView({
|
30103
|
-
pgConfig:
|
30625
|
+
pgConfig: {
|
30626
|
+
tablespace: this.config.tablespace,
|
30627
|
+
using: this.config.using,
|
30628
|
+
with: this.config.with,
|
30629
|
+
withNoData: this.config.withNoData
|
30630
|
+
},
|
30104
30631
|
config: {
|
30105
30632
|
name: this.name,
|
30106
30633
|
schema: this.schema,
|
@@ -30324,17 +30851,32 @@ function getTableConfig(table4) {
|
|
30324
30851
|
schema: schema4
|
30325
30852
|
};
|
30326
30853
|
}
|
30854
|
+
function getViewConfig(view2) {
|
30855
|
+
return {
|
30856
|
+
...view2[ViewBaseConfig],
|
30857
|
+
...view2[PgViewConfig]
|
30858
|
+
};
|
30859
|
+
}
|
30860
|
+
function getMaterializedViewConfig(view2) {
|
30861
|
+
return {
|
30862
|
+
...view2[ViewBaseConfig],
|
30863
|
+
...view2[PgMaterializedViewConfig]
|
30864
|
+
};
|
30865
|
+
}
|
30327
30866
|
var init_utils4 = __esm({
|
30328
30867
|
"../drizzle-orm/dist/pg-core/utils.js"() {
|
30329
30868
|
"use strict";
|
30330
30869
|
init_entity();
|
30331
30870
|
init_table2();
|
30332
30871
|
init_table();
|
30872
|
+
init_view_common();
|
30333
30873
|
init_checks();
|
30334
30874
|
init_foreign_keys();
|
30335
30875
|
init_indexes();
|
30336
30876
|
init_primary_keys();
|
30337
30877
|
init_unique_constraint();
|
30878
|
+
init_view_common2();
|
30879
|
+
init_view();
|
30338
30880
|
}
|
30339
30881
|
});
|
30340
30882
|
|
@@ -38575,15 +39117,15 @@ var init_HeaderFormatter = __esm({
|
|
38575
39117
|
throw new Error("Int64 buffers must be exactly 8 bytes");
|
38576
39118
|
}
|
38577
39119
|
}
|
38578
|
-
static fromNumber(
|
38579
|
-
if (
|
38580
|
-
throw new Error(`${
|
39120
|
+
static fromNumber(number2) {
|
39121
|
+
if (number2 > 9223372036854776e3 || number2 < -9223372036854776e3) {
|
39122
|
+
throw new Error(`${number2} is too large (or, if negative, too small) to represent as an Int64`);
|
38581
39123
|
}
|
38582
39124
|
const bytes2 = new Uint8Array(8);
|
38583
|
-
for (let i5 = 7, remaining = Math.abs(Math.round(
|
39125
|
+
for (let i5 = 7, remaining = Math.abs(Math.round(number2)); i5 > -1 && remaining > 0; i5--, remaining /= 256) {
|
38584
39126
|
bytes2[i5] = remaining;
|
38585
39127
|
}
|
38586
|
-
if (
|
39128
|
+
if (number2 < 0) {
|
38587
39129
|
negate(bytes2);
|
38588
39130
|
}
|
38589
39131
|
return new _Int64(bytes2);
|
@@ -50827,7 +51369,7 @@ var init_view_base2 = __esm({
|
|
50827
51369
|
"use strict";
|
50828
51370
|
init_entity();
|
50829
51371
|
init_sql();
|
50830
|
-
SQLiteViewBase = class extends (_b152 =
|
51372
|
+
SQLiteViewBase = class extends (_b152 = View4, _a206 = entityKind, _b152) {
|
50831
51373
|
};
|
50832
51374
|
__publicField(SQLiteViewBase, _a206, "SQLiteViewBase");
|
50833
51375
|
}
|
@@ -51765,7 +52307,7 @@ var init_select3 = __esm({
|
|
51765
52307
|
};
|
51766
52308
|
}
|
51767
52309
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
51768
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
52310
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View4) ? table4[ViewBaseConfig].selectedFields : table4[Table2.Symbol.Columns];
|
51769
52311
|
this.config.fields[tableName] = selection;
|
51770
52312
|
}
|
51771
52313
|
}
|
@@ -59422,7 +59964,7 @@ function stringOpt(value) {
|
|
59422
59964
|
}
|
59423
59965
|
throw typeError(value, "string or null");
|
59424
59966
|
}
|
59425
|
-
function
|
59967
|
+
function number(value) {
|
59426
59968
|
if (typeof value === "number") {
|
59427
59969
|
return value;
|
59428
59970
|
}
|
@@ -61202,7 +61744,7 @@ function Error2(obj) {
|
|
61202
61744
|
function StmtResult(obj) {
|
61203
61745
|
const cols = arrayObjectsMap(obj["cols"], Col);
|
61204
61746
|
const rows = array(obj["rows"]).map((rowObj) => arrayObjectsMap(rowObj, Value4));
|
61205
|
-
const affectedRowCount =
|
61747
|
+
const affectedRowCount = number(obj["affected_row_count"]);
|
61206
61748
|
const lastInsertRowidStr = stringOpt(obj["last_insert_rowid"]);
|
61207
61749
|
const lastInsertRowid = lastInsertRowidStr !== void 0 ? BigInt(lastInsertRowidStr) : void 0;
|
61208
61750
|
return { cols, rows, affectedRowCount, lastInsertRowid };
|
@@ -61230,16 +61772,16 @@ function BatchResult(obj) {
|
|
61230
61772
|
function CursorEntry(obj) {
|
61231
61773
|
const type = string(obj["type"]);
|
61232
61774
|
if (type === "step_begin") {
|
61233
|
-
const step =
|
61775
|
+
const step = number(obj["step"]);
|
61234
61776
|
const cols = arrayObjectsMap(obj["cols"], Col);
|
61235
61777
|
return { type: "step_begin", step, cols };
|
61236
61778
|
} else if (type === "step_end") {
|
61237
|
-
const affectedRowCount =
|
61779
|
+
const affectedRowCount = number(obj["affected_row_count"]);
|
61238
61780
|
const lastInsertRowidStr = stringOpt(obj["last_insert_rowid"]);
|
61239
61781
|
const lastInsertRowid = lastInsertRowidStr !== void 0 ? BigInt(lastInsertRowidStr) : void 0;
|
61240
61782
|
return { type: "step_end", affectedRowCount, lastInsertRowid };
|
61241
61783
|
} else if (type === "step_error") {
|
61242
|
-
const step =
|
61784
|
+
const step = number(obj["step"]);
|
61243
61785
|
const error2 = Error2(object(obj["error"]));
|
61244
61786
|
return { type: "step_error", step, error: error2 };
|
61245
61787
|
} else if (type === "row") {
|
@@ -61276,7 +61818,7 @@ function Value4(obj) {
|
|
61276
61818
|
const value = string(obj["value"]);
|
61277
61819
|
return BigInt(value);
|
61278
61820
|
} else if (type === "float") {
|
61279
|
-
return
|
61821
|
+
return number(obj["value"]);
|
61280
61822
|
} else if (type === "text") {
|
61281
61823
|
return string(obj["value"]);
|
61282
61824
|
} else if (type === "blob") {
|
@@ -61303,11 +61845,11 @@ function ServerMsg(obj) {
|
|
61303
61845
|
const error2 = Error2(object(obj["error"]));
|
61304
61846
|
return { type: "hello_error", error: error2 };
|
61305
61847
|
} else if (type === "response_ok") {
|
61306
|
-
const requestId =
|
61848
|
+
const requestId = number(obj["request_id"]);
|
61307
61849
|
const response = Response(object(obj["response"]));
|
61308
61850
|
return { type: "response_ok", requestId, response };
|
61309
61851
|
} else if (type === "response_error") {
|
61310
|
-
const requestId =
|
61852
|
+
const requestId = number(obj["request_id"]);
|
61311
61853
|
const error2 = Error2(object(obj["error"]));
|
61312
61854
|
return { type: "response_error", requestId, error: error2 };
|
61313
61855
|
} else {
|
@@ -64481,12 +65023,12 @@ var require_SqlString = __commonJS({
|
|
64481
65023
|
}
|
64482
65024
|
return "'" + escapedVal + "'";
|
64483
65025
|
}
|
64484
|
-
function zeroPad(
|
64485
|
-
|
64486
|
-
while (
|
64487
|
-
|
65026
|
+
function zeroPad(number2, length) {
|
65027
|
+
number2 = number2.toString();
|
65028
|
+
while (number2.length < length) {
|
65029
|
+
number2 = "0" + number2;
|
64488
65030
|
}
|
64489
|
-
return
|
65031
|
+
return number2;
|
64490
65032
|
}
|
64491
65033
|
function convertTimezone(tz) {
|
64492
65034
|
if (tz === "Z") {
|
@@ -85057,7 +85599,7 @@ var init_view_base3 = __esm({
|
|
85057
85599
|
"use strict";
|
85058
85600
|
init_entity();
|
85059
85601
|
init_sql();
|
85060
|
-
MySqlViewBase = class extends (_b249 =
|
85602
|
+
MySqlViewBase = class extends (_b249 = View4, _a325 = entityKind, _b249) {
|
85061
85603
|
};
|
85062
85604
|
__publicField(MySqlViewBase, _a325, "MySqlViewBase");
|
85063
85605
|
}
|
@@ -85271,7 +85813,7 @@ var init_dialect3 = __esm({
|
|
85271
85813
|
joinsArray.push(
|
85272
85814
|
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
85273
85815
|
);
|
85274
|
-
} else if (is(table22,
|
85816
|
+
} else if (is(table22, View4)) {
|
85275
85817
|
const viewName = table22[ViewBaseConfig].name;
|
85276
85818
|
const viewSchema = table22[ViewBaseConfig].schema;
|
85277
85819
|
const origViewName = table22[ViewBaseConfig].originalName;
|
@@ -86287,7 +86829,7 @@ var init_select4 = __esm({
|
|
86287
86829
|
};
|
86288
86830
|
}
|
86289
86831
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
86290
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
86832
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View4) ? table4[ViewBaseConfig].selectedFields : table4[Table2.Symbol.Columns];
|
86291
86833
|
this.config.fields[tableName] = selection;
|
86292
86834
|
}
|
86293
86835
|
}
|
@@ -95006,13 +95548,13 @@ function Connection2(options, queues = {}, { onopen = noop, onend = noop, onclos
|
|
95006
95548
|
start = index4;
|
95007
95549
|
while (x6[index4++] !== 0) ;
|
95008
95550
|
const table4 = x6.readUInt32BE(index4);
|
95009
|
-
const
|
95551
|
+
const number2 = x6.readUInt16BE(index4 + 4);
|
95010
95552
|
const type = x6.readUInt32BE(index4 + 6);
|
95011
95553
|
query.statement.columns[i5] = {
|
95012
95554
|
name: transform.column.from ? transform.column.from(x6.toString("utf8", start, index4 - 1)) : x6.toString("utf8", start, index4 - 1),
|
95013
95555
|
parser: parsers2[type],
|
95014
95556
|
table: table4,
|
95015
|
-
number:
|
95557
|
+
number: number2,
|
95016
95558
|
type
|
95017
95559
|
};
|
95018
95560
|
index4 += 18;
|
@@ -112425,7 +112967,7 @@ __export(dist_exports4, {
|
|
112425
112967
|
Table: () => Table2,
|
112426
112968
|
TableAliasProxyHandler: () => TableAliasProxyHandler,
|
112427
112969
|
TransactionRollbackError: () => TransactionRollbackError,
|
112428
|
-
View: () =>
|
112970
|
+
View: () => View4,
|
112429
112971
|
ViewBaseConfig: () => ViewBaseConfig,
|
112430
112972
|
WithSubquery: () => WithSubquery,
|
112431
112973
|
aliasedRelation: () => aliasedRelation,
|
@@ -112586,8 +113128,9 @@ var init_pgSerializer = __esm({
|
|
112586
113128
|
indexName = (tableName, columns) => {
|
112587
113129
|
return `${tableName}_${columns.join("_")}_index`;
|
112588
113130
|
};
|
112589
|
-
generatePgSnapshot = (tables, enums, schemas, sequences, schemaFilter) => {
|
113131
|
+
generatePgSnapshot = (tables, enums, schemas, sequences, views, matViews, schemaFilter) => {
|
112590
113132
|
const result = {};
|
113133
|
+
const resultViews = {};
|
112591
113134
|
const sequencesToReturn = {};
|
112592
113135
|
const indexesInSchema = {};
|
112593
113136
|
for (const table4 of tables) {
|
@@ -112884,6 +113427,149 @@ ${withStyle.errorWarning(
|
|
112884
113427
|
} else {
|
112885
113428
|
}
|
112886
113429
|
}
|
113430
|
+
const combinedViews = [...views, ...matViews];
|
113431
|
+
for (const view2 of combinedViews) {
|
113432
|
+
let viewName;
|
113433
|
+
let schema4;
|
113434
|
+
let query;
|
113435
|
+
let selectedFields;
|
113436
|
+
let isExisting;
|
113437
|
+
let withOption;
|
113438
|
+
let tablespace;
|
113439
|
+
let using;
|
113440
|
+
let withNoData;
|
113441
|
+
let materialized = false;
|
113442
|
+
if (is(view2, PgView)) {
|
113443
|
+
({ name: viewName, schema: schema4, query, selectedFields, isExisting, with: withOption } = getViewConfig(view2));
|
113444
|
+
} else {
|
113445
|
+
({ name: viewName, schema: schema4, query, selectedFields, isExisting, with: withOption, tablespace, using, withNoData } = getMaterializedViewConfig(
|
113446
|
+
view2
|
113447
|
+
));
|
113448
|
+
materialized = true;
|
113449
|
+
}
|
113450
|
+
const viewSchema = schema4 ?? "public";
|
113451
|
+
const viewKey = `${viewSchema}.${viewName}`;
|
113452
|
+
const columnsObject = {};
|
113453
|
+
const uniqueConstraintObject = {};
|
113454
|
+
const existingView = resultViews[viewKey];
|
113455
|
+
if (typeof existingView !== "undefined") {
|
113456
|
+
console.log(
|
113457
|
+
`
|
113458
|
+
${withStyle.errorWarning(
|
113459
|
+
`We've found duplicated view name across ${source_default.underline.blue(
|
113460
|
+
schema4 ?? "public"
|
113461
|
+
)} schema. Please rename your view`
|
113462
|
+
)}`
|
113463
|
+
);
|
113464
|
+
process.exit(1);
|
113465
|
+
}
|
113466
|
+
for (const key in selectedFields) {
|
113467
|
+
if (is(selectedFields[key], PgColumn)) {
|
113468
|
+
const column4 = selectedFields[key];
|
113469
|
+
const notNull = column4.notNull;
|
113470
|
+
const primaryKey = column4.primary;
|
113471
|
+
const sqlTypeLowered = column4.getSQLType().toLowerCase();
|
113472
|
+
const typeSchema = is(column4, PgEnumColumn) ? column4.enum.schema || "public" : void 0;
|
113473
|
+
const generated = column4.generated;
|
113474
|
+
const identity = column4.generatedIdentity;
|
113475
|
+
const increment = stringFromIdentityProperty(identity?.sequenceOptions?.increment) ?? "1";
|
113476
|
+
const minValue = stringFromIdentityProperty(identity?.sequenceOptions?.minValue) ?? (parseFloat(increment) < 0 ? minRangeForIdentityBasedOn(column4.columnType) : "1");
|
113477
|
+
const maxValue = stringFromIdentityProperty(identity?.sequenceOptions?.maxValue) ?? (parseFloat(increment) < 0 ? "-1" : maxRangeForIdentityBasedOn(column4.getSQLType()));
|
113478
|
+
const startWith = stringFromIdentityProperty(identity?.sequenceOptions?.startWith) ?? (parseFloat(increment) < 0 ? maxValue : minValue);
|
113479
|
+
const cache = stringFromIdentityProperty(identity?.sequenceOptions?.cache) ?? "1";
|
113480
|
+
const columnToSet = {
|
113481
|
+
name: column4.name,
|
113482
|
+
type: column4.getSQLType(),
|
113483
|
+
typeSchema,
|
113484
|
+
primaryKey,
|
113485
|
+
notNull,
|
113486
|
+
generated: generated ? {
|
113487
|
+
as: is(generated.as, SQL) ? dialect4.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect4.sqlToQuery(generated.as()).sql : generated.as,
|
113488
|
+
type: "stored"
|
113489
|
+
} : void 0,
|
113490
|
+
identity: identity ? {
|
113491
|
+
type: identity.type,
|
113492
|
+
name: identity.sequenceName ?? `${viewName}_${column4.name}_seq`,
|
113493
|
+
schema: schema4 ?? "public",
|
113494
|
+
increment,
|
113495
|
+
startWith,
|
113496
|
+
minValue,
|
113497
|
+
maxValue,
|
113498
|
+
cache,
|
113499
|
+
cycle: identity?.sequenceOptions?.cycle ?? false
|
113500
|
+
} : void 0
|
113501
|
+
};
|
113502
|
+
if (column4.isUnique) {
|
113503
|
+
const existingUnique = uniqueConstraintObject[column4.uniqueName];
|
113504
|
+
if (typeof existingUnique !== "undefined") {
|
113505
|
+
console.log(
|
113506
|
+
`
|
113507
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
113508
|
+
viewName
|
113509
|
+
)} table.
|
113510
|
+
The unique constraint ${source_default.underline.blue(
|
113511
|
+
column4.uniqueName
|
113512
|
+
)} on the ${source_default.underline.blue(
|
113513
|
+
column4.name
|
113514
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
113515
|
+
existingUnique.columns.join(",")
|
113516
|
+
)} columns
|
113517
|
+
`)}`
|
113518
|
+
);
|
113519
|
+
process.exit(1);
|
113520
|
+
}
|
113521
|
+
uniqueConstraintObject[column4.uniqueName] = {
|
113522
|
+
name: column4.uniqueName,
|
113523
|
+
nullsNotDistinct: column4.uniqueType === "not distinct",
|
113524
|
+
columns: [columnToSet.name]
|
113525
|
+
};
|
113526
|
+
}
|
113527
|
+
if (column4.default !== void 0) {
|
113528
|
+
if (is(column4.default, SQL)) {
|
113529
|
+
columnToSet.default = sqlToStr(column4.default);
|
113530
|
+
} else {
|
113531
|
+
if (typeof column4.default === "string") {
|
113532
|
+
columnToSet.default = `'${column4.default}'`;
|
113533
|
+
} else {
|
113534
|
+
if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
|
113535
|
+
columnToSet.default = `'${JSON.stringify(
|
113536
|
+
column4.default
|
113537
|
+
)}'::${sqlTypeLowered}`;
|
113538
|
+
} else if (column4.default instanceof Date) {
|
113539
|
+
if (sqlTypeLowered === "date") {
|
113540
|
+
columnToSet.default = `'${column4.default.toISOString().split("T")[0]}'`;
|
113541
|
+
} else if (sqlTypeLowered === "timestamp") {
|
113542
|
+
columnToSet.default = `'${column4.default.toISOString().replace("T", " ").slice(0, 23)}'`;
|
113543
|
+
} else {
|
113544
|
+
columnToSet.default = `'${column4.default.toISOString()}'`;
|
113545
|
+
}
|
113546
|
+
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
|
113547
|
+
columnToSet.default = `'${buildArrayString(
|
113548
|
+
column4.default,
|
113549
|
+
sqlTypeLowered
|
113550
|
+
)}'`;
|
113551
|
+
} else {
|
113552
|
+
columnToSet.default = column4.default;
|
113553
|
+
}
|
113554
|
+
}
|
113555
|
+
}
|
113556
|
+
}
|
113557
|
+
columnsObject[column4.name] = columnToSet;
|
113558
|
+
}
|
113559
|
+
}
|
113560
|
+
resultViews[viewKey] = {
|
113561
|
+
columns: columnsObject,
|
113562
|
+
definition: isExisting ? void 0 : dialect4.sqlToQuery(query).sql,
|
113563
|
+
name: viewName,
|
113564
|
+
schema: viewSchema,
|
113565
|
+
isExisting,
|
113566
|
+
with: withOption,
|
113567
|
+
withNoData,
|
113568
|
+
materialized,
|
113569
|
+
tablespace,
|
113570
|
+
using
|
113571
|
+
};
|
113572
|
+
}
|
112887
113573
|
const enumsToReturn = enums.reduce((map2, obj) => {
|
112888
113574
|
const enumSchema3 = obj.schema || "public";
|
112889
113575
|
const key = `${enumSchema3}.${obj.enumName}`;
|
@@ -112910,6 +113596,7 @@ ${withStyle.errorWarning(
|
|
112910
113596
|
enums: enumsToReturn,
|
112911
113597
|
schemas: schemasObject,
|
112912
113598
|
sequences: sequencesToReturn,
|
113599
|
+
views: resultViews,
|
112913
113600
|
_meta: {
|
112914
113601
|
schemas: {},
|
112915
113602
|
tables: {},
|
@@ -112926,10 +113613,25 @@ ${withStyle.errorWarning(
|
|
112926
113613
|
};
|
112927
113614
|
fromDatabase = async (db2, tablesFilter = () => true, schemaFilters, progressCallback) => {
|
112928
113615
|
const result = {};
|
113616
|
+
const views = {};
|
112929
113617
|
const internals = { tables: {} };
|
112930
|
-
const where = schemaFilters.map((t6) => `
|
113618
|
+
const where = schemaFilters.map((t6) => `n.nspname = '${t6}'`).join(" or ");
|
112931
113619
|
const allTables = await db2.query(
|
112932
|
-
`SELECT
|
113620
|
+
`SELECT
|
113621
|
+
n.nspname AS table_schema,
|
113622
|
+
c.relname AS table_name,
|
113623
|
+
CASE
|
113624
|
+
WHEN c.relkind = 'r' THEN 'table'
|
113625
|
+
WHEN c.relkind = 'v' THEN 'view'
|
113626
|
+
WHEN c.relkind = 'm' THEN 'materialized_view'
|
113627
|
+
END AS type
|
113628
|
+
FROM
|
113629
|
+
pg_catalog.pg_class c
|
113630
|
+
JOIN
|
113631
|
+
pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
113632
|
+
WHERE
|
113633
|
+
c.relkind IN ('r', 'v', 'm')
|
113634
|
+
${where === "" ? "" : ` AND ${where}`};`
|
112933
113635
|
);
|
112934
113636
|
const schemas = new Set(allTables.map((it) => it.table_schema));
|
112935
113637
|
schemas.delete("public");
|
@@ -113007,7 +113709,7 @@ ${withStyle.errorWarning(
|
|
113007
113709
|
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
113008
113710
|
}
|
113009
113711
|
const sequencesInColumns = [];
|
113010
|
-
const all = allTables.map((row) => {
|
113712
|
+
const all = allTables.filter((it) => it.type === "table").map((row) => {
|
113011
113713
|
return new Promise(async (res, rej) => {
|
113012
113714
|
const tableName = row.table_name;
|
113013
113715
|
if (!tablesFilter(tableName)) return res("");
|
@@ -113413,6 +114115,334 @@ ${withStyle.errorWarning(
|
|
113413
114115
|
}
|
113414
114116
|
for await (const _4 of all) {
|
113415
114117
|
}
|
114118
|
+
const allViews = allTables.filter((it) => it.type === "view" || it.type === "materialized_view").map((row) => {
|
114119
|
+
return new Promise(async (res, rej) => {
|
114120
|
+
const viewName = row.table_name;
|
114121
|
+
if (!tablesFilter(viewName)) return res("");
|
114122
|
+
tableCount += 1;
|
114123
|
+
const viewSchema = row.table_schema;
|
114124
|
+
try {
|
114125
|
+
const columnToReturn = {};
|
114126
|
+
const viewResponses = await db2.query(`WITH view_columns AS (
|
114127
|
+
SELECT DISTINCT
|
114128
|
+
nv.nspname::information_schema.sql_identifier AS view_schema,
|
114129
|
+
v.relname::information_schema.sql_identifier AS view_name,
|
114130
|
+
nt.nspname::information_schema.sql_identifier AS table_schema,
|
114131
|
+
t.relname::information_schema.sql_identifier AS table_name,
|
114132
|
+
a.attname::information_schema.sql_identifier AS column_name
|
114133
|
+
FROM pg_namespace nv
|
114134
|
+
JOIN pg_class v ON nv.oid = v.relnamespace
|
114135
|
+
JOIN pg_depend dv ON v.oid = dv.refobjid
|
114136
|
+
JOIN pg_depend dt ON dv.objid = dt.objid
|
114137
|
+
JOIN pg_class t ON dt.refobjid = t.oid
|
114138
|
+
JOIN pg_namespace nt ON t.relnamespace = nt.oid
|
114139
|
+
JOIN pg_attribute a ON t.oid = a.attrelid
|
114140
|
+
WHERE (v.relkind = 'v'::"char" OR v.relkind = 'm'::"char")
|
114141
|
+
AND dv.refclassid = 'pg_class'::regclass::oid
|
114142
|
+
AND dv.classid = 'pg_rewrite'::regclass::oid
|
114143
|
+
AND dv.deptype = 'i'::"char"
|
114144
|
+
AND dv.objid = dt.objid
|
114145
|
+
AND dv.refobjid <> dt.refobjid
|
114146
|
+
AND dt.classid = 'pg_rewrite'::regclass::oid
|
114147
|
+
AND dt.refclassid = 'pg_class'::regclass::oid
|
114148
|
+
AND t.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])
|
114149
|
+
AND dt.refobjsubid = a.attnum
|
114150
|
+
AND pg_has_role(t.relowner, 'USAGE'::text)
|
114151
|
+
AND nv.nspname::information_schema.sql_identifier = '${viewSchema}'
|
114152
|
+
AND v.relname::information_schema.sql_identifier = '${viewName}'
|
114153
|
+
),
|
114154
|
+
column_descriptions AS (
|
114155
|
+
SELECT DISTINCT
|
114156
|
+
a.attrelid::regclass::text AS table_name,
|
114157
|
+
a.attname AS column_name,
|
114158
|
+
c.is_nullable,
|
114159
|
+
a.attndims AS array_dimensions,
|
114160
|
+
CASE
|
114161
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
|
114162
|
+
SELECT FROM pg_attrdef ad
|
114163
|
+
WHERE ad.adrelid = a.attrelid
|
114164
|
+
AND ad.adnum = a.attnum
|
114165
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
114166
|
+
)
|
114167
|
+
THEN CASE a.atttypid
|
114168
|
+
WHEN 'int'::regtype THEN 'serial'
|
114169
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
114170
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
114171
|
+
END
|
114172
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
114173
|
+
END AS data_type,
|
114174
|
+
pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
|
114175
|
+
c.column_default,
|
114176
|
+
c.data_type AS additional_dt,
|
114177
|
+
c.udt_name AS enum_name,
|
114178
|
+
c.is_generated,
|
114179
|
+
c.generation_expression,
|
114180
|
+
c.is_identity,
|
114181
|
+
c.identity_generation,
|
114182
|
+
c.identity_start,
|
114183
|
+
c.identity_increment,
|
114184
|
+
c.identity_maximum,
|
114185
|
+
c.identity_minimum,
|
114186
|
+
c.identity_cycle
|
114187
|
+
FROM pg_attribute a
|
114188
|
+
JOIN information_schema.columns c ON c.column_name = a.attname
|
114189
|
+
JOIN pg_type t ON t.oid = a.atttypid
|
114190
|
+
LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
114191
|
+
WHERE a.attnum > 0
|
114192
|
+
AND NOT a.attisdropped
|
114193
|
+
),
|
114194
|
+
table_constraints AS (
|
114195
|
+
SELECT DISTINCT ON (ccu.column_name)
|
114196
|
+
ccu.column_name,
|
114197
|
+
c.data_type,
|
114198
|
+
tc.constraint_type,
|
114199
|
+
tc.constraint_name,
|
114200
|
+
tc.constraint_schema,
|
114201
|
+
tc.table_name
|
114202
|
+
FROM information_schema.table_constraints tc
|
114203
|
+
JOIN information_schema.constraint_column_usage ccu USING (constraint_schema, constraint_name)
|
114204
|
+
JOIN information_schema.columns c ON c.table_schema = tc.constraint_schema
|
114205
|
+
AND tc.table_name = c.table_name
|
114206
|
+
AND ccu.column_name = c.column_name
|
114207
|
+
),
|
114208
|
+
additional_column_info AS (
|
114209
|
+
SELECT DISTINCT
|
114210
|
+
a.attrelid::regclass::text AS table_name,
|
114211
|
+
a.attname AS column_name,
|
114212
|
+
is_nullable,
|
114213
|
+
a.attndims AS array_dimensions,
|
114214
|
+
CASE
|
114215
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
|
114216
|
+
SELECT FROM pg_attrdef ad
|
114217
|
+
WHERE ad.adrelid = a.attrelid
|
114218
|
+
AND ad.adnum = a.attnum
|
114219
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
114220
|
+
)
|
114221
|
+
THEN CASE a.atttypid
|
114222
|
+
WHEN 'int'::regtype THEN 'serial'
|
114223
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
114224
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
114225
|
+
END
|
114226
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
114227
|
+
END AS data_type,
|
114228
|
+
pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
|
114229
|
+
c.column_default,
|
114230
|
+
c.data_type AS additional_dt,
|
114231
|
+
c.udt_name AS enum_name,
|
114232
|
+
c.is_generated,
|
114233
|
+
generation_expression,
|
114234
|
+
is_identity,
|
114235
|
+
identity_generation,
|
114236
|
+
identity_start,
|
114237
|
+
identity_increment,
|
114238
|
+
identity_maximum,
|
114239
|
+
identity_minimum,
|
114240
|
+
identity_cycle
|
114241
|
+
FROM pg_attribute a
|
114242
|
+
JOIN information_schema.columns c ON c.column_name = a.attname
|
114243
|
+
LEFT JOIN pg_type t ON t.oid = a.atttypid
|
114244
|
+
LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
114245
|
+
WHERE a.attnum > 0
|
114246
|
+
AND NOT a.attisdropped
|
114247
|
+
)
|
114248
|
+
SELECT DISTINCT ON (vc.table_name, vc.column_name)
|
114249
|
+
vc.view_schema,
|
114250
|
+
vc.view_name,
|
114251
|
+
vc.table_schema,
|
114252
|
+
vc.table_name,
|
114253
|
+
vc.column_name,
|
114254
|
+
COALESCE(cd.data_type, aci.data_type) AS data_type,
|
114255
|
+
tc.constraint_type,
|
114256
|
+
tc.constraint_name,
|
114257
|
+
aci.is_nullable,
|
114258
|
+
aci.array_dimensions,
|
114259
|
+
aci.seq_name,
|
114260
|
+
aci.column_default,
|
114261
|
+
aci.additional_dt,
|
114262
|
+
aci.enum_name,
|
114263
|
+
aci.is_generated,
|
114264
|
+
aci.generation_expression,
|
114265
|
+
aci.is_identity,
|
114266
|
+
aci.identity_generation,
|
114267
|
+
aci.identity_start,
|
114268
|
+
aci.identity_increment,
|
114269
|
+
aci.identity_maximum,
|
114270
|
+
aci.identity_minimum,
|
114271
|
+
aci.identity_cycle
|
114272
|
+
FROM view_columns vc
|
114273
|
+
LEFT JOIN column_descriptions cd ON vc.table_name = cd.table_name AND vc.column_name = cd.column_name
|
114274
|
+
LEFT JOIN table_constraints tc ON vc.table_name = tc.table_name AND vc.column_name = tc.column_name
|
114275
|
+
LEFT JOIN additional_column_info aci ON vc.table_name = aci.table_name AND vc.column_name = aci.column_name
|
114276
|
+
ORDER BY vc.table_name, vc.column_name;`);
|
114277
|
+
for (const viewResponse of viewResponses) {
|
114278
|
+
const columnName = viewResponse.column_name;
|
114279
|
+
const columnAdditionalDT = viewResponse.additional_dt;
|
114280
|
+
const columnDimensions = viewResponse.array_dimensions;
|
114281
|
+
const enumType2 = viewResponse.enum_name;
|
114282
|
+
let columnType = viewResponse.data_type;
|
114283
|
+
const typeSchema = viewResponse.type_schema;
|
114284
|
+
const isGenerated = viewResponse.is_generated === "ALWAYS";
|
114285
|
+
const generationExpression = viewResponse.generation_expression;
|
114286
|
+
const isIdentity = viewResponse.is_identity === "YES";
|
114287
|
+
const identityGeneration = viewResponse.identity_generation === "ALWAYS" ? "always" : "byDefault";
|
114288
|
+
const identityStart = viewResponse.identity_start;
|
114289
|
+
const identityIncrement = viewResponse.identity_increment;
|
114290
|
+
const identityMaximum = viewResponse.identity_maximum;
|
114291
|
+
const identityMinimum = viewResponse.identity_minimum;
|
114292
|
+
const identityCycle = viewResponse.identity_cycle === "YES";
|
114293
|
+
const identityName = viewResponse.seq_name;
|
114294
|
+
const defaultValueRes = viewResponse.column_default;
|
114295
|
+
const primaryKey = viewResponse.constraint_type === "PRIMARY KEY";
|
114296
|
+
let columnTypeMapped = columnType;
|
114297
|
+
if (columnAdditionalDT === "ARRAY") {
|
114298
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
114299
|
+
internals.tables[viewName] = {
|
114300
|
+
columns: {
|
114301
|
+
[columnName]: {
|
114302
|
+
isArray: true,
|
114303
|
+
dimensions: columnDimensions,
|
114304
|
+
rawType: columnTypeMapped.substring(
|
114305
|
+
0,
|
114306
|
+
columnTypeMapped.length - 2
|
114307
|
+
)
|
114308
|
+
}
|
114309
|
+
}
|
114310
|
+
};
|
114311
|
+
} else {
|
114312
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
114313
|
+
internals.tables[viewName].columns[columnName] = {
|
114314
|
+
isArray: true,
|
114315
|
+
dimensions: columnDimensions,
|
114316
|
+
rawType: columnTypeMapped.substring(
|
114317
|
+
0,
|
114318
|
+
columnTypeMapped.length - 2
|
114319
|
+
)
|
114320
|
+
};
|
114321
|
+
}
|
114322
|
+
}
|
114323
|
+
}
|
114324
|
+
const defaultValue = defaultForColumn(
|
114325
|
+
viewResponse,
|
114326
|
+
internals,
|
114327
|
+
viewName
|
114328
|
+
);
|
114329
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
114330
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
114331
|
+
internals.tables[viewName] = {
|
114332
|
+
columns: {
|
114333
|
+
[columnName]: {
|
114334
|
+
isDefaultAnExpression: true
|
114335
|
+
}
|
114336
|
+
}
|
114337
|
+
};
|
114338
|
+
} else {
|
114339
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
114340
|
+
internals.tables[viewName].columns[columnName] = {
|
114341
|
+
isDefaultAnExpression: true
|
114342
|
+
};
|
114343
|
+
} else {
|
114344
|
+
internals.tables[viewName].columns[columnName].isDefaultAnExpression = true;
|
114345
|
+
}
|
114346
|
+
}
|
114347
|
+
}
|
114348
|
+
const isSerial = columnType === "serial";
|
114349
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
114350
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
114351
|
+
}
|
114352
|
+
if (columnAdditionalDT === "ARRAY") {
|
114353
|
+
for (let i5 = 1; i5 < Number(columnDimensions); i5++) {
|
114354
|
+
columnTypeMapped += "[]";
|
114355
|
+
}
|
114356
|
+
}
|
114357
|
+
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
114358
|
+
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
114359
|
+
columnToReturn[columnName] = {
|
114360
|
+
name: columnName,
|
114361
|
+
type: (
|
114362
|
+
// filter vectors, but in future we should filter any extension that was installed by user
|
114363
|
+
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
114364
|
+
),
|
114365
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
114366
|
+
primaryKey,
|
114367
|
+
notNull: viewResponse.is_nullable === "NO",
|
114368
|
+
generated: isGenerated ? { as: generationExpression, type: "stored" } : void 0,
|
114369
|
+
identity: isIdentity ? {
|
114370
|
+
type: identityGeneration,
|
114371
|
+
name: identityName,
|
114372
|
+
increment: stringFromDatabaseIdentityProperty(identityIncrement),
|
114373
|
+
minValue: stringFromDatabaseIdentityProperty(identityMinimum),
|
114374
|
+
maxValue: stringFromDatabaseIdentityProperty(identityMaximum),
|
114375
|
+
startWith: stringFromDatabaseIdentityProperty(identityStart),
|
114376
|
+
cache: sequencesToReturn[identityName]?.cache ? sequencesToReturn[identityName]?.cache : sequencesToReturn[`${viewSchema}.${identityName}`]?.cache ? sequencesToReturn[`${viewSchema}.${identityName}`]?.cache : void 0,
|
114377
|
+
cycle: identityCycle,
|
114378
|
+
schema: viewSchema
|
114379
|
+
} : void 0
|
114380
|
+
};
|
114381
|
+
if (identityName) {
|
114382
|
+
delete sequencesToReturn[`${viewSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
|
114383
|
+
delete sequencesToReturn[identityName];
|
114384
|
+
}
|
114385
|
+
if (!isSerial && typeof defaultValue !== "undefined") {
|
114386
|
+
columnToReturn[columnName].default = defaultValue;
|
114387
|
+
}
|
114388
|
+
}
|
114389
|
+
const [viewInfo] = await db2.query(`
|
114390
|
+
SELECT
|
114391
|
+
c.relname AS view_name,
|
114392
|
+
n.nspname AS schema_name,
|
114393
|
+
pg_get_viewdef(c.oid, true) AS definition,
|
114394
|
+
ts.spcname AS tablespace_name,
|
114395
|
+
c.reloptions AS options,
|
114396
|
+
pg_tablespace_location(ts.oid) AS location
|
114397
|
+
FROM
|
114398
|
+
pg_class c
|
114399
|
+
JOIN
|
114400
|
+
pg_namespace n ON c.relnamespace = n.oid
|
114401
|
+
LEFT JOIN
|
114402
|
+
pg_tablespace ts ON c.reltablespace = ts.oid
|
114403
|
+
WHERE
|
114404
|
+
(c.relkind = 'm' OR c.relkind = 'v')
|
114405
|
+
AND n.nspname = '${viewSchema}'
|
114406
|
+
AND c.relname = '${viewName}';`);
|
114407
|
+
const resultWith = {};
|
114408
|
+
if (viewInfo.options) {
|
114409
|
+
viewInfo.options.forEach((pair) => {
|
114410
|
+
const splitted = pair.split("=");
|
114411
|
+
const key = splitted[0];
|
114412
|
+
const value = splitted[1];
|
114413
|
+
if (value === "true") {
|
114414
|
+
resultWith[key] = true;
|
114415
|
+
} else if (value === "false") {
|
114416
|
+
resultWith[key] = false;
|
114417
|
+
} else if (!isNaN(Number(value))) {
|
114418
|
+
resultWith[key] = Number(value);
|
114419
|
+
} else {
|
114420
|
+
resultWith[key] = value;
|
114421
|
+
}
|
114422
|
+
});
|
114423
|
+
}
|
114424
|
+
const definition = viewInfo.definition.replace(/\s+/g, " ").replace(";", "").trim();
|
114425
|
+
const withOption = Object.values(resultWith).length ? Object.fromEntries(Object.entries(resultWith).map(([key, value]) => [key.camelCase(), value])) : void 0;
|
114426
|
+
const materialized = row.type === "materialized_view";
|
114427
|
+
views[`${viewSchema}.${viewName}`] = {
|
114428
|
+
name: viewName,
|
114429
|
+
schema: viewSchema,
|
114430
|
+
columns: columnToReturn,
|
114431
|
+
isExisting: false,
|
114432
|
+
definition,
|
114433
|
+
materialized,
|
114434
|
+
with: withOption,
|
114435
|
+
tablespace: viewInfo.tablespace_name ?? void 0
|
114436
|
+
};
|
114437
|
+
} catch (e5) {
|
114438
|
+
rej(e5);
|
114439
|
+
return;
|
114440
|
+
}
|
114441
|
+
res("");
|
114442
|
+
});
|
114443
|
+
});
|
114444
|
+
for await (const _4 of allViews) {
|
114445
|
+
}
|
113416
114446
|
if (progressCallback) {
|
113417
114447
|
progressCallback("columns", columnsCount, "done");
|
113418
114448
|
progressCallback("indexes", indexesCount, "done");
|
@@ -113426,6 +114456,7 @@ ${withStyle.errorWarning(
|
|
113426
114456
|
enums: enumsToReturn,
|
113427
114457
|
schemas: schemasObject,
|
113428
114458
|
sequences: sequencesToReturn,
|
114459
|
+
views,
|
113429
114460
|
_meta: {
|
113430
114461
|
schemas: {},
|
113431
114462
|
tables: {},
|
@@ -115288,6 +116319,8 @@ var init_pgImports = __esm({
|
|
115288
116319
|
const enums = [];
|
115289
116320
|
const schemas = [];
|
115290
116321
|
const sequences = [];
|
116322
|
+
const views = [];
|
116323
|
+
const matViews = [];
|
115291
116324
|
const i0values = Object.values(exports2);
|
115292
116325
|
i0values.forEach((t6) => {
|
115293
116326
|
if (isPgEnum(t6)) {
|
@@ -115300,11 +116333,17 @@ var init_pgImports = __esm({
|
|
115300
116333
|
if (is(t6, PgSchema5)) {
|
115301
116334
|
schemas.push(t6);
|
115302
116335
|
}
|
116336
|
+
if (isPgView(t6)) {
|
116337
|
+
views.push(t6);
|
116338
|
+
}
|
116339
|
+
if (isPgMaterializedView(t6)) {
|
116340
|
+
matViews.push(t6);
|
116341
|
+
}
|
115303
116342
|
if (isPgSequence(t6)) {
|
115304
116343
|
sequences.push(t6);
|
115305
116344
|
}
|
115306
116345
|
});
|
115307
|
-
return { tables, enums, schemas, sequences };
|
116346
|
+
return { tables, enums, schemas, sequences, views, matViews };
|
115308
116347
|
};
|
115309
116348
|
}
|
115310
116349
|
});
|
@@ -116158,6 +117197,9 @@ String.prototype.capitalise = function() {
|
|
116158
117197
|
String.prototype.concatIf = function(it, condition) {
|
116159
117198
|
return condition ? `${this}${it}` : String(this);
|
116160
117199
|
};
|
117200
|
+
String.prototype.snake_case = function() {
|
117201
|
+
return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
|
117202
|
+
};
|
116161
117203
|
Array.prototype.random = function() {
|
116162
117204
|
return this[~~(Math.random() * this.length)];
|
116163
117205
|
};
|
@@ -116218,6 +117260,8 @@ var generateDrizzleJson = (imports, prevId, schemaFilters) => {
|
|
116218
117260
|
prepared.enums,
|
116219
117261
|
prepared.schemas,
|
116220
117262
|
prepared.sequences,
|
117263
|
+
prepared.views,
|
117264
|
+
prepared.matViews,
|
116221
117265
|
schemaFilters
|
116222
117266
|
);
|
116223
117267
|
return fillPgSnapshot({
|
@@ -116240,6 +117284,7 @@ var generateMigration = async (prev, cur) => {
|
|
116240
117284
|
sequencesResolver,
|
116241
117285
|
tablesResolver,
|
116242
117286
|
columnsResolver,
|
117287
|
+
viewsResolver,
|
116243
117288
|
validatedPrev,
|
116244
117289
|
validatedCur
|
116245
117290
|
);
|
@@ -116272,6 +117317,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
|
|
116272
117317
|
sequencesResolver,
|
116273
117318
|
tablesResolver,
|
116274
117319
|
columnsResolver,
|
117320
|
+
viewsResolver,
|
116275
117321
|
validatedPrev,
|
116276
117322
|
validatedCur,
|
116277
117323
|
"push"
|