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.mjs
CHANGED
@@ -3253,8 +3253,8 @@ var require_hanji = __commonJS({
|
|
3253
3253
|
};
|
3254
3254
|
exports.deferred = deferred;
|
3255
3255
|
var Terminal = class {
|
3256
|
-
constructor(
|
3257
|
-
this.view =
|
3256
|
+
constructor(view2, stdin, stdout, closable) {
|
3257
|
+
this.view = view2;
|
3258
3258
|
this.stdin = stdin;
|
3259
3259
|
this.stdout = stdout;
|
3260
3260
|
this.closable = closable;
|
@@ -3292,7 +3292,7 @@ var require_hanji = __commonJS({
|
|
3292
3292
|
this.resolve({ status: "submitted", data: this.view.result() });
|
3293
3293
|
return;
|
3294
3294
|
}
|
3295
|
-
|
3295
|
+
view2.input(str, key);
|
3296
3296
|
};
|
3297
3297
|
this.stdin.on("keypress", keypress);
|
3298
3298
|
this.view.attach(this);
|
@@ -3354,8 +3354,8 @@ var require_hanji = __commonJS({
|
|
3354
3354
|
};
|
3355
3355
|
exports.TaskView = TaskView2;
|
3356
3356
|
var TaskTerminal = class {
|
3357
|
-
constructor(
|
3358
|
-
this.view =
|
3357
|
+
constructor(view2, stdout) {
|
3358
|
+
this.view = view2;
|
3359
3359
|
this.stdout = stdout;
|
3360
3360
|
this.text = "";
|
3361
3361
|
this.view.attach(this);
|
@@ -3374,22 +3374,22 @@ var require_hanji = __commonJS({
|
|
3374
3374
|
}
|
3375
3375
|
};
|
3376
3376
|
exports.TaskTerminal = TaskTerminal;
|
3377
|
-
function render6(
|
3377
|
+
function render6(view2) {
|
3378
3378
|
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
3379
|
-
if (
|
3380
|
-
const terminal = new Terminal(
|
3379
|
+
if (view2 instanceof Prompt3) {
|
3380
|
+
const terminal = new Terminal(view2, stdin, stdout, closable);
|
3381
3381
|
terminal.requestLayout();
|
3382
3382
|
return terminal.result();
|
3383
3383
|
}
|
3384
|
-
stdout.write(`${
|
3384
|
+
stdout.write(`${view2}
|
3385
3385
|
`);
|
3386
3386
|
closable.close();
|
3387
3387
|
return;
|
3388
3388
|
}
|
3389
3389
|
exports.render = render6;
|
3390
|
-
function renderWithTask4(
|
3390
|
+
function renderWithTask4(view2, task) {
|
3391
3391
|
return __awaiter2(this, void 0, void 0, function* () {
|
3392
|
-
const terminal = new TaskTerminal(
|
3392
|
+
const terminal = new TaskTerminal(view2, process.stdout);
|
3393
3393
|
terminal.requestLayout();
|
3394
3394
|
const result = yield task;
|
3395
3395
|
terminal.clear();
|
@@ -7504,7 +7504,7 @@ var init_vector = __esm({
|
|
7504
7504
|
});
|
7505
7505
|
|
7506
7506
|
// src/serializer/pgSchema.ts
|
7507
|
-
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;
|
7507
|
+
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;
|
7508
7508
|
var init_pgSchema = __esm({
|
7509
7509
|
"src/serializer/pgSchema.ts"() {
|
7510
7510
|
"use strict";
|
@@ -7699,6 +7699,44 @@ var init_pgSchema = __esm({
|
|
7699
7699
|
columns: stringType().array(),
|
7700
7700
|
nullsNotDistinct: booleanType()
|
7701
7701
|
}).strict();
|
7702
|
+
viewWithOption = objectType({
|
7703
|
+
checkOption: enumType(["local", "cascaded"]).optional(),
|
7704
|
+
securityBarrier: booleanType().optional(),
|
7705
|
+
securityInvoker: booleanType().optional()
|
7706
|
+
}).strict();
|
7707
|
+
matViewWithOption = objectType({
|
7708
|
+
fillfactor: numberType().optional(),
|
7709
|
+
toastTupleTarget: numberType().optional(),
|
7710
|
+
parallelWorkers: numberType().optional(),
|
7711
|
+
autovacuumEnabled: booleanType().optional(),
|
7712
|
+
vacuumIndexCleanup: enumType(["auto", "off", "on"]).optional(),
|
7713
|
+
vacuumTruncate: booleanType().optional(),
|
7714
|
+
autovacuumVacuumThreshold: numberType().optional(),
|
7715
|
+
autovacuumVacuumScaleFactor: numberType().optional(),
|
7716
|
+
autovacuumVacuumCostDelay: numberType().optional(),
|
7717
|
+
autovacuumVacuumCostLimit: numberType().optional(),
|
7718
|
+
autovacuumFreezeMinAge: numberType().optional(),
|
7719
|
+
autovacuumFreezeMaxAge: numberType().optional(),
|
7720
|
+
autovacuumFreezeTableAge: numberType().optional(),
|
7721
|
+
autovacuumMultixactFreezeMinAge: numberType().optional(),
|
7722
|
+
autovacuumMultixactFreezeMaxAge: numberType().optional(),
|
7723
|
+
autovacuumMultixactFreezeTableAge: numberType().optional(),
|
7724
|
+
logAutovacuumMinDuration: numberType().optional(),
|
7725
|
+
userCatalogTable: booleanType().optional()
|
7726
|
+
}).strict();
|
7727
|
+
mergedViewWithOption = viewWithOption.merge(matViewWithOption);
|
7728
|
+
view = objectType({
|
7729
|
+
name: stringType(),
|
7730
|
+
schema: stringType(),
|
7731
|
+
columns: recordType(stringType(), column2),
|
7732
|
+
definition: stringType().optional(),
|
7733
|
+
materialized: booleanType(),
|
7734
|
+
with: mergedViewWithOption.optional(),
|
7735
|
+
isExisting: booleanType(),
|
7736
|
+
withNoData: booleanType().optional(),
|
7737
|
+
using: stringType().optional(),
|
7738
|
+
tablespace: stringType().optional()
|
7739
|
+
}).strict();
|
7702
7740
|
tableV42 = objectType({
|
7703
7741
|
name: stringType(),
|
7704
7742
|
schema: stringType(),
|
@@ -7833,6 +7871,7 @@ var init_pgSchema = __esm({
|
|
7833
7871
|
tables: recordType(stringType(), table2),
|
7834
7872
|
enums: recordType(stringType(), enumSchema),
|
7835
7873
|
schemas: recordType(stringType(), stringType()),
|
7874
|
+
views: recordType(stringType(), view).default({}),
|
7836
7875
|
sequences: recordType(stringType(), sequenceSchema).default({}),
|
7837
7876
|
_meta: objectType({
|
7838
7877
|
schemas: recordType(stringType(), stringType()),
|
@@ -7877,6 +7916,7 @@ var init_pgSchema = __esm({
|
|
7877
7916
|
tables: recordType(stringType(), tableSquashed2),
|
7878
7917
|
enums: recordType(stringType(), enumSchema),
|
7879
7918
|
schemas: recordType(stringType(), stringType()),
|
7919
|
+
views: recordType(stringType(), view),
|
7880
7920
|
sequences: recordType(stringType(), sequenceSquashed)
|
7881
7921
|
}).strict();
|
7882
7922
|
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
@@ -8094,6 +8134,7 @@ var init_pgSchema = __esm({
|
|
8094
8134
|
tables: mappedTables,
|
8095
8135
|
enums: json3.enums,
|
8096
8136
|
schemas: json3.schemas,
|
8137
|
+
views: json3.views,
|
8097
8138
|
sequences: mappedSequences
|
8098
8139
|
};
|
8099
8140
|
};
|
@@ -11053,6 +11094,7 @@ function applyJsonDiff(json1, json22) {
|
|
11053
11094
|
difference.tables = difference.tables || {};
|
11054
11095
|
difference.enums = difference.enums || {};
|
11055
11096
|
difference.sequences = difference.sequences || {};
|
11097
|
+
difference.views = difference.views || {};
|
11056
11098
|
const schemaKeys = Object.keys(difference.schemas);
|
11057
11099
|
for (let key of schemaKeys) {
|
11058
11100
|
if (key.endsWith("__added") || key.endsWith("__deleted")) {
|
@@ -11108,6 +11150,65 @@ function applyJsonDiff(json1, json22) {
|
|
11108
11150
|
const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
|
11109
11151
|
return json22.sequences[it[0]];
|
11110
11152
|
});
|
11153
|
+
const viewsEntries = Object.entries(difference.views);
|
11154
|
+
const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
|
11155
|
+
([nameWithSchema, view2]) => {
|
11156
|
+
const deletedWithOption = view2.with__deleted;
|
11157
|
+
const addedWithOption = view2.with__added;
|
11158
|
+
const deletedWith = Object.fromEntries(
|
11159
|
+
Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__deleted")).map(([key, value]) => {
|
11160
|
+
return [key.replace("__deleted", ""), value];
|
11161
|
+
})
|
11162
|
+
);
|
11163
|
+
const addedWith = Object.fromEntries(
|
11164
|
+
Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__added")).map(([key, value]) => {
|
11165
|
+
return [key.replace("__added", ""), value];
|
11166
|
+
})
|
11167
|
+
);
|
11168
|
+
const alterWith = Object.fromEntries(
|
11169
|
+
Object.entries(view2.with || {}).filter(
|
11170
|
+
(it) => typeof it[1].__old !== "undefined" && typeof it[1].__new !== "undefined"
|
11171
|
+
).map(
|
11172
|
+
(it) => {
|
11173
|
+
return [it[0], it[1].__new];
|
11174
|
+
}
|
11175
|
+
)
|
11176
|
+
);
|
11177
|
+
const alteredSchema = view2.schema;
|
11178
|
+
const alteredDefinition = view2.definition;
|
11179
|
+
const alteredExisting = view2.isExisting;
|
11180
|
+
const addedTablespace = view2.tablespace__added;
|
11181
|
+
const droppedTablespace = view2.tablespace__deleted;
|
11182
|
+
const alterTablespaceTo = view2.tablespace;
|
11183
|
+
let alteredTablespace;
|
11184
|
+
if (addedTablespace) alteredTablespace = { __new: addedTablespace, __old: "pg_default" };
|
11185
|
+
if (droppedTablespace) alteredTablespace = { __new: "pg_default", __old: droppedTablespace };
|
11186
|
+
if (alterTablespaceTo) alteredTablespace = alterTablespaceTo;
|
11187
|
+
const addedUsing = view2.using__added;
|
11188
|
+
const droppedUsing = view2.using__deleted;
|
11189
|
+
const alterUsingTo = view2.using;
|
11190
|
+
let alteredUsing;
|
11191
|
+
if (addedUsing) alteredUsing = { __new: addedUsing, __old: "heap" };
|
11192
|
+
if (droppedUsing) alteredUsing = { __new: "heap", __old: droppedUsing };
|
11193
|
+
if (alterUsingTo) alteredUsing = alterUsingTo;
|
11194
|
+
return {
|
11195
|
+
name: json22.views[nameWithSchema].name,
|
11196
|
+
schema: json22.views[nameWithSchema].schema,
|
11197
|
+
deletedWithOption,
|
11198
|
+
addedWithOption,
|
11199
|
+
alteredWith: {
|
11200
|
+
deletedWith: Object.keys(deletedWith).length ? deletedWith : void 0,
|
11201
|
+
addedWith: Object.keys(addedWith).length ? addedWith : void 0,
|
11202
|
+
alterWith: Object.keys(alterWith).length ? alterWith : void 0
|
11203
|
+
},
|
11204
|
+
alteredSchema,
|
11205
|
+
alteredDefinition,
|
11206
|
+
alteredExisting,
|
11207
|
+
alteredTablespace,
|
11208
|
+
alteredUsing
|
11209
|
+
};
|
11210
|
+
}
|
11211
|
+
);
|
11111
11212
|
const alteredTablesWithColumns = Object.values(difference.tables).map(
|
11112
11213
|
(table4) => {
|
11113
11214
|
return findAlternationsInTable(table4);
|
@@ -11116,7 +11217,8 @@ function applyJsonDiff(json1, json22) {
|
|
11116
11217
|
return {
|
11117
11218
|
alteredTablesWithColumns,
|
11118
11219
|
alteredEnums,
|
11119
|
-
alteredSequences
|
11220
|
+
alteredSequences,
|
11221
|
+
alteredViews
|
11120
11222
|
};
|
11121
11223
|
}
|
11122
11224
|
var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
|
@@ -11511,7 +11613,7 @@ function fromJson(statements, dialect7, action, json22) {
|
|
11511
11613
|
}).filter((it) => it !== "");
|
11512
11614
|
return result;
|
11513
11615
|
}
|
11514
|
-
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;
|
11616
|
+
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;
|
11515
11617
|
var init_sqlgenerator = __esm({
|
11516
11618
|
"src/sqlgenerator.ts"() {
|
11517
11619
|
"use strict";
|
@@ -11724,6 +11826,114 @@ var init_sqlgenerator = __esm({
|
|
11724
11826
|
return statement;
|
11725
11827
|
}
|
11726
11828
|
};
|
11829
|
+
PgCreateViewConvertor = class extends Convertor {
|
11830
|
+
can(statement, dialect7) {
|
11831
|
+
return statement.type === "create_view" && dialect7 === "postgresql";
|
11832
|
+
}
|
11833
|
+
convert(st) {
|
11834
|
+
const { definition, name: viewName, schema: schema4, with: withOption, materialized, withNoData, tablespace, using } = st;
|
11835
|
+
const name2 = schema4 ? `"${schema4}"."${viewName}"` : `"${viewName}"`;
|
11836
|
+
let statement = materialized ? `CREATE MATERIALIZED VIEW ${name2}` : `CREATE VIEW ${name2}`;
|
11837
|
+
if (using) statement += ` USING "${using}"`;
|
11838
|
+
const options = [];
|
11839
|
+
if (withOption) {
|
11840
|
+
statement += ` WITH (`;
|
11841
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
11842
|
+
if (typeof value === "undefined") return;
|
11843
|
+
options.push(`${key.snake_case()} = ${value}`);
|
11844
|
+
});
|
11845
|
+
statement += options.join(", ");
|
11846
|
+
statement += `)`;
|
11847
|
+
}
|
11848
|
+
if (tablespace) statement += ` TABLESPACE ${tablespace}`;
|
11849
|
+
statement += ` AS (${definition})`;
|
11850
|
+
if (withNoData) statement += ` WITH NO DATA`;
|
11851
|
+
statement += `;`;
|
11852
|
+
return statement;
|
11853
|
+
}
|
11854
|
+
};
|
11855
|
+
PgDropViewConvertor = class extends Convertor {
|
11856
|
+
can(statement, dialect7) {
|
11857
|
+
return statement.type === "drop_view" && dialect7 === "postgresql";
|
11858
|
+
}
|
11859
|
+
convert(st) {
|
11860
|
+
const { name: viewName, schema: schema4, materialized } = st;
|
11861
|
+
const name2 = schema4 ? `"${schema4}"."${viewName}"` : `"${viewName}"`;
|
11862
|
+
return `DROP${materialized ? " MATERIALIZED" : ""} VIEW ${name2};`;
|
11863
|
+
}
|
11864
|
+
};
|
11865
|
+
PgRenameViewConvertor = class extends Convertor {
|
11866
|
+
can(statement, dialect7) {
|
11867
|
+
return statement.type === "rename_view" && dialect7 === "postgresql";
|
11868
|
+
}
|
11869
|
+
convert(st) {
|
11870
|
+
const { nameFrom: from, nameTo: to2, schema: schema4, materialized } = st;
|
11871
|
+
const nameFrom = `"${schema4}"."${from}"`;
|
11872
|
+
return `ALTER${materialized ? " MATERIALIZED" : ""} VIEW ${nameFrom} RENAME TO "${to2}";`;
|
11873
|
+
}
|
11874
|
+
};
|
11875
|
+
PgAlterViewSchemaConvertor = class extends Convertor {
|
11876
|
+
can(statement, dialect7) {
|
11877
|
+
return statement.type === "alter_view_alter_schema" && dialect7 === "postgresql";
|
11878
|
+
}
|
11879
|
+
convert(st) {
|
11880
|
+
const { fromSchema, toSchema, name: name2, materialized } = st;
|
11881
|
+
const statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${fromSchema}"."${name2}" SET SCHEMA "${toSchema}";`;
|
11882
|
+
return statement;
|
11883
|
+
}
|
11884
|
+
};
|
11885
|
+
PgAlterViewAddWithOptionConvertor = class extends Convertor {
|
11886
|
+
can(statement, dialect7) {
|
11887
|
+
return statement.type === "alter_view_add_with_option" && dialect7 === "postgresql";
|
11888
|
+
}
|
11889
|
+
convert(st) {
|
11890
|
+
const { schema: schema4, with: withOption, name: name2, materialized } = st;
|
11891
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema4}"."${name2}" SET (`;
|
11892
|
+
const options = [];
|
11893
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
11894
|
+
options.push(`${key.snake_case()} = ${value}`);
|
11895
|
+
});
|
11896
|
+
statement += options.join(", ");
|
11897
|
+
statement += `);`;
|
11898
|
+
return statement;
|
11899
|
+
}
|
11900
|
+
};
|
11901
|
+
PgAlterViewDropWithOptionConvertor = class extends Convertor {
|
11902
|
+
can(statement, dialect7) {
|
11903
|
+
return statement.type === "alter_view_drop_with_option" && dialect7 === "postgresql";
|
11904
|
+
}
|
11905
|
+
convert(st) {
|
11906
|
+
const { schema: schema4, name: name2, materialized, with: withOptions } = st;
|
11907
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema4}"."${name2}" RESET (`;
|
11908
|
+
const options = [];
|
11909
|
+
Object.entries(withOptions).forEach(([key, value]) => {
|
11910
|
+
options.push(`${key.snake_case()}`);
|
11911
|
+
});
|
11912
|
+
statement += options.join(", ");
|
11913
|
+
statement += ");";
|
11914
|
+
return statement;
|
11915
|
+
}
|
11916
|
+
};
|
11917
|
+
PgAlterViewAlterTablespaceConvertor = class extends Convertor {
|
11918
|
+
can(statement, dialect7) {
|
11919
|
+
return statement.type === "alter_view_alter_tablespace" && dialect7 === "postgresql";
|
11920
|
+
}
|
11921
|
+
convert(st) {
|
11922
|
+
const { schema: schema4, name: name2, toTablespace } = st;
|
11923
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema4}"."${name2}" SET TABLESPACE ${toTablespace};`;
|
11924
|
+
return statement;
|
11925
|
+
}
|
11926
|
+
};
|
11927
|
+
PgAlterViewAlterUsingConvertor = class extends Convertor {
|
11928
|
+
can(statement, dialect7) {
|
11929
|
+
return statement.type === "alter_view_alter_using" && dialect7 === "postgresql";
|
11930
|
+
}
|
11931
|
+
convert(st) {
|
11932
|
+
const { schema: schema4, name: name2, toUsing } = st;
|
11933
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema4}"."${name2}" SET ACCESS METHOD "${toUsing}";`;
|
11934
|
+
return statement;
|
11935
|
+
}
|
11936
|
+
};
|
11727
11937
|
PgAlterTableAlterColumnSetGenerated = class extends Convertor {
|
11728
11938
|
can(statement, dialect7) {
|
11729
11939
|
return statement.type === "alter_table_alter_column_set_identity" && dialect7 === "postgresql";
|
@@ -13059,6 +13269,14 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13059
13269
|
convertors.push(new SQLiteCreateTableConvertor());
|
13060
13270
|
convertors.push(new SQLiteRecreateTableConvertor());
|
13061
13271
|
convertors.push(new LibSQLRecreateTableConvertor());
|
13272
|
+
convertors.push(new PgCreateViewConvertor());
|
13273
|
+
convertors.push(new PgDropViewConvertor());
|
13274
|
+
convertors.push(new PgRenameViewConvertor());
|
13275
|
+
convertors.push(new PgAlterViewSchemaConvertor());
|
13276
|
+
convertors.push(new PgAlterViewAddWithOptionConvertor());
|
13277
|
+
convertors.push(new PgAlterViewDropWithOptionConvertor());
|
13278
|
+
convertors.push(new PgAlterViewAlterTablespaceConvertor());
|
13279
|
+
convertors.push(new PgAlterViewAlterUsingConvertor());
|
13062
13280
|
convertors.push(new CreateTypeEnumConvertor());
|
13063
13281
|
convertors.push(new CreatePgSequenceConvertor());
|
13064
13282
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13392,7 +13610,7 @@ var init_sqlitePushUtils = __esm({
|
|
13392
13610
|
});
|
13393
13611
|
|
13394
13612
|
// src/jsonStatements.ts
|
13395
|
-
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;
|
13613
|
+
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;
|
13396
13614
|
var init_jsonStatements = __esm({
|
13397
13615
|
"src/jsonStatements.ts"() {
|
13398
13616
|
"use strict";
|
@@ -14725,6 +14943,81 @@ var init_jsonStatements = __esm({
|
|
14725
14943
|
};
|
14726
14944
|
});
|
14727
14945
|
};
|
14946
|
+
preparePgCreateViewJson = (name2, schema4, definition, materialized, withNoData = false, withOption, using, tablespace) => {
|
14947
|
+
return {
|
14948
|
+
type: "create_view",
|
14949
|
+
name: name2,
|
14950
|
+
schema: schema4,
|
14951
|
+
definition,
|
14952
|
+
with: withOption,
|
14953
|
+
materialized,
|
14954
|
+
withNoData,
|
14955
|
+
using,
|
14956
|
+
tablespace
|
14957
|
+
};
|
14958
|
+
};
|
14959
|
+
preparePgDropViewJson = (name2, schema4, materialized) => {
|
14960
|
+
return {
|
14961
|
+
type: "drop_view",
|
14962
|
+
name: name2,
|
14963
|
+
schema: schema4,
|
14964
|
+
materialized
|
14965
|
+
};
|
14966
|
+
};
|
14967
|
+
preparePgRenameViewJson = (to2, from, schema4, materialized) => {
|
14968
|
+
return {
|
14969
|
+
type: "rename_view",
|
14970
|
+
nameTo: to2,
|
14971
|
+
nameFrom: from,
|
14972
|
+
schema: schema4,
|
14973
|
+
materialized
|
14974
|
+
};
|
14975
|
+
};
|
14976
|
+
preparePgAlterViewAlterSchemaJson = (to2, from, name2, materialized) => {
|
14977
|
+
return {
|
14978
|
+
type: "alter_view_alter_schema",
|
14979
|
+
fromSchema: from,
|
14980
|
+
toSchema: to2,
|
14981
|
+
name: name2,
|
14982
|
+
materialized
|
14983
|
+
};
|
14984
|
+
};
|
14985
|
+
preparePgAlterViewAddWithOptionJson = (name2, schema4, materialized, withOption) => {
|
14986
|
+
return {
|
14987
|
+
type: "alter_view_add_with_option",
|
14988
|
+
name: name2,
|
14989
|
+
schema: schema4,
|
14990
|
+
materialized,
|
14991
|
+
with: withOption
|
14992
|
+
};
|
14993
|
+
};
|
14994
|
+
preparePgAlterViewDropWithOptionJson = (name2, schema4, materialized, withOption) => {
|
14995
|
+
return {
|
14996
|
+
type: "alter_view_drop_with_option",
|
14997
|
+
name: name2,
|
14998
|
+
schema: schema4,
|
14999
|
+
materialized,
|
15000
|
+
with: withOption
|
15001
|
+
};
|
15002
|
+
};
|
15003
|
+
preparePgAlterViewAlterTablespaceJson = (name2, schema4, materialized, to2) => {
|
15004
|
+
return {
|
15005
|
+
type: "alter_view_alter_tablespace",
|
15006
|
+
name: name2,
|
15007
|
+
schema: schema4,
|
15008
|
+
materialized,
|
15009
|
+
toTablespace: to2
|
15010
|
+
};
|
15011
|
+
};
|
15012
|
+
preparePgAlterViewAlterUsingJson = (name2, schema4, materialized, to2) => {
|
15013
|
+
return {
|
15014
|
+
type: "alter_view_alter_using",
|
15015
|
+
name: name2,
|
15016
|
+
schema: schema4,
|
15017
|
+
materialized,
|
15018
|
+
toUsing: to2
|
15019
|
+
};
|
15020
|
+
};
|
14728
15021
|
}
|
14729
15022
|
});
|
14730
15023
|
|
@@ -15013,6 +15306,7 @@ var init_statementCombiner = __esm({
|
|
15013
15306
|
var snapshotsDiffer_exports = {};
|
15014
15307
|
__export(snapshotsDiffer_exports, {
|
15015
15308
|
alteredTableScheme: () => alteredTableScheme,
|
15309
|
+
alteredViewSchema: () => alteredViewSchema,
|
15016
15310
|
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
15017
15311
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
15018
15312
|
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
@@ -15023,7 +15317,7 @@ __export(snapshotsDiffer_exports, {
|
|
15023
15317
|
makePatched: () => makePatched,
|
15024
15318
|
makeSelfOrPatched: () => makeSelfOrPatched
|
15025
15319
|
});
|
15026
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
15320
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, alteredViewSchema, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
15027
15321
|
var init_snapshotsDiffer = __esm({
|
15028
15322
|
"src/snapshotsDiffer.ts"() {
|
15029
15323
|
"use strict";
|
@@ -15192,10 +15486,42 @@ var init_snapshotsDiffer = __esm({
|
|
15192
15486
|
})
|
15193
15487
|
)
|
15194
15488
|
}).strict();
|
15489
|
+
alteredViewSchema = objectType({
|
15490
|
+
name: stringType(),
|
15491
|
+
schema: stringType(),
|
15492
|
+
deletedWithOption: mergedViewWithOption.optional(),
|
15493
|
+
addedWithOption: mergedViewWithOption.optional(),
|
15494
|
+
alteredWith: objectType({
|
15495
|
+
addedWith: mergedViewWithOption.optional(),
|
15496
|
+
deletedWith: mergedViewWithOption.optional(),
|
15497
|
+
alterWith: mergedViewWithOption.optional()
|
15498
|
+
}).strict(),
|
15499
|
+
alteredSchema: objectType({
|
15500
|
+
__old: stringType(),
|
15501
|
+
__new: stringType()
|
15502
|
+
}).strict().optional(),
|
15503
|
+
alteredDefinition: objectType({
|
15504
|
+
__old: stringType(),
|
15505
|
+
__new: stringType()
|
15506
|
+
}).strict().optional(),
|
15507
|
+
alteredExisting: objectType({
|
15508
|
+
__old: booleanType(),
|
15509
|
+
__new: booleanType()
|
15510
|
+
}).strict().optional(),
|
15511
|
+
alteredTablespace: objectType({
|
15512
|
+
__old: stringType(),
|
15513
|
+
__new: stringType()
|
15514
|
+
}).strict().optional(),
|
15515
|
+
alteredUsing: objectType({
|
15516
|
+
__old: stringType(),
|
15517
|
+
__new: stringType()
|
15518
|
+
}).strict().optional()
|
15519
|
+
}).strict();
|
15195
15520
|
diffResultScheme = objectType({
|
15196
15521
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
15197
15522
|
alteredEnums: changedEnumSchema.array(),
|
15198
|
-
alteredSequences: sequenceSquashed.array()
|
15523
|
+
alteredSequences: sequenceSquashed.array(),
|
15524
|
+
alteredViews: alteredViewSchema.array()
|
15199
15525
|
}).strict();
|
15200
15526
|
diffResultSchemeMysql = objectType({
|
15201
15527
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
@@ -15250,7 +15576,7 @@ var init_snapshotsDiffer = __esm({
|
|
15250
15576
|
}
|
15251
15577
|
return column4;
|
15252
15578
|
};
|
15253
|
-
applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
15579
|
+
applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
15254
15580
|
const schemasDiff = diffSchemasOrTables(json1.schemas, json22.schemas);
|
15255
15581
|
const {
|
15256
15582
|
created: createdSchemas,
|
@@ -15478,7 +15804,39 @@ var init_snapshotsDiffer = __esm({
|
|
15478
15804
|
return [tableKey2, tableValue];
|
15479
15805
|
}
|
15480
15806
|
);
|
15481
|
-
const
|
15807
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json22.views);
|
15808
|
+
const {
|
15809
|
+
created: createdViews,
|
15810
|
+
deleted: deletedViews,
|
15811
|
+
renamed: renamedViews,
|
15812
|
+
moved: movedViews
|
15813
|
+
} = await viewsResolver2({
|
15814
|
+
created: viewsDiff.added,
|
15815
|
+
deleted: viewsDiff.deleted
|
15816
|
+
});
|
15817
|
+
const renamesViewDic = {};
|
15818
|
+
renamedViews.forEach((it) => {
|
15819
|
+
renamesViewDic[`${it.from.schema}.${it.from.name}`] = { to: it.to.name, from: it.from.name };
|
15820
|
+
});
|
15821
|
+
const movedViewDic = {};
|
15822
|
+
movedViews.forEach((it) => {
|
15823
|
+
movedViewDic[`${it.schemaFrom}.${it.name}`] = { to: it.schemaTo, from: it.schemaFrom };
|
15824
|
+
});
|
15825
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
15826
|
+
viewsPatchedSnap1.views = mapEntries(
|
15827
|
+
viewsPatchedSnap1.views,
|
15828
|
+
(viewKey, viewValue) => {
|
15829
|
+
const rename = renamesViewDic[`${viewValue.schema}.${viewValue.name}`];
|
15830
|
+
const moved = movedViewDic[`${viewValue.schema}.${viewValue.name}`];
|
15831
|
+
if (rename) {
|
15832
|
+
viewValue.name = rename.to;
|
15833
|
+
viewKey = `${viewValue.schema}.${viewValue.name}`;
|
15834
|
+
}
|
15835
|
+
if (moved) viewKey = `${moved.to}.${viewValue.name}`;
|
15836
|
+
return [viewKey, viewValue];
|
15837
|
+
}
|
15838
|
+
);
|
15839
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json22);
|
15482
15840
|
const typedResult = diffResultScheme.parse(diffResult);
|
15483
15841
|
const jsonStatements = [];
|
15484
15842
|
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
@@ -15730,6 +16088,137 @@ var init_snapshotsDiffer = __esm({
|
|
15730
16088
|
const createTables = createdTables.map((it) => {
|
15731
16089
|
return preparePgCreateTableJson(it, curFull);
|
15732
16090
|
});
|
16091
|
+
const createViews = [];
|
16092
|
+
const dropViews = [];
|
16093
|
+
const renameViews = [];
|
16094
|
+
const alterViews = [];
|
16095
|
+
createViews.push(
|
16096
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
16097
|
+
return preparePgCreateViewJson(
|
16098
|
+
it.name,
|
16099
|
+
it.schema,
|
16100
|
+
it.definition,
|
16101
|
+
it.materialized,
|
16102
|
+
it.withNoData,
|
16103
|
+
it.with,
|
16104
|
+
it.using,
|
16105
|
+
it.tablespace
|
16106
|
+
);
|
16107
|
+
})
|
16108
|
+
);
|
16109
|
+
dropViews.push(
|
16110
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
16111
|
+
return preparePgDropViewJson(it.name, it.schema, it.materialized);
|
16112
|
+
})
|
16113
|
+
);
|
16114
|
+
renameViews.push(
|
16115
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
16116
|
+
return preparePgRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
|
16117
|
+
})
|
16118
|
+
);
|
16119
|
+
alterViews.push(
|
16120
|
+
...movedViews.filter((it) => !json22.views[`${it.schemaTo}.${it.name}`].isExisting).map((it) => {
|
16121
|
+
return preparePgAlterViewAlterSchemaJson(
|
16122
|
+
it.schemaTo,
|
16123
|
+
it.schemaFrom,
|
16124
|
+
it.name,
|
16125
|
+
json22.views[`${it.schemaTo}.${it.name}`].materialized
|
16126
|
+
);
|
16127
|
+
})
|
16128
|
+
);
|
16129
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json22.views[`${it.schema}.${it.name}`].isExisting);
|
16130
|
+
for (const alteredView of alteredViews) {
|
16131
|
+
const viewKey = `${alteredView.schema}.${alteredView.name}`;
|
16132
|
+
const { materialized, with: withOption, definition, withNoData, using, tablespace } = json22.views[viewKey];
|
16133
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
16134
|
+
dropViews.push(preparePgDropViewJson(alteredView.name, alteredView.schema, materialized));
|
16135
|
+
createViews.push(
|
16136
|
+
preparePgCreateViewJson(
|
16137
|
+
alteredView.name,
|
16138
|
+
alteredView.schema,
|
16139
|
+
definition,
|
16140
|
+
materialized,
|
16141
|
+
withNoData,
|
16142
|
+
withOption,
|
16143
|
+
using,
|
16144
|
+
tablespace
|
16145
|
+
)
|
16146
|
+
);
|
16147
|
+
continue;
|
16148
|
+
}
|
16149
|
+
if (alteredView.addedWithOption) {
|
16150
|
+
alterViews.push(
|
16151
|
+
preparePgAlterViewAddWithOptionJson(
|
16152
|
+
alteredView.name,
|
16153
|
+
alteredView.schema,
|
16154
|
+
materialized,
|
16155
|
+
alteredView.addedWithOption
|
16156
|
+
)
|
16157
|
+
);
|
16158
|
+
}
|
16159
|
+
if (alteredView.deletedWithOption) {
|
16160
|
+
alterViews.push(
|
16161
|
+
preparePgAlterViewDropWithOptionJson(
|
16162
|
+
alteredView.name,
|
16163
|
+
alteredView.schema,
|
16164
|
+
materialized,
|
16165
|
+
alteredView.deletedWithOption
|
16166
|
+
)
|
16167
|
+
);
|
16168
|
+
}
|
16169
|
+
if (alteredView.alteredWith) {
|
16170
|
+
if (alteredView.alteredWith.addedWith) {
|
16171
|
+
alterViews.push(
|
16172
|
+
preparePgAlterViewAddWithOptionJson(
|
16173
|
+
alteredView.name,
|
16174
|
+
alteredView.schema,
|
16175
|
+
materialized,
|
16176
|
+
alteredView.alteredWith.addedWith
|
16177
|
+
)
|
16178
|
+
);
|
16179
|
+
}
|
16180
|
+
if (alteredView.alteredWith.deletedWith) {
|
16181
|
+
alterViews.push(
|
16182
|
+
preparePgAlterViewDropWithOptionJson(
|
16183
|
+
alteredView.name,
|
16184
|
+
alteredView.schema,
|
16185
|
+
materialized,
|
16186
|
+
alteredView.alteredWith.deletedWith
|
16187
|
+
)
|
16188
|
+
);
|
16189
|
+
}
|
16190
|
+
if (alteredView.alteredWith.alterWith) {
|
16191
|
+
alterViews.push(
|
16192
|
+
preparePgAlterViewAddWithOptionJson(
|
16193
|
+
alteredView.name,
|
16194
|
+
alteredView.schema,
|
16195
|
+
materialized,
|
16196
|
+
alteredView.alteredWith.alterWith
|
16197
|
+
)
|
16198
|
+
);
|
16199
|
+
}
|
16200
|
+
}
|
16201
|
+
if (alteredView.alteredTablespace) {
|
16202
|
+
alterViews.push(
|
16203
|
+
preparePgAlterViewAlterTablespaceJson(
|
16204
|
+
alteredView.name,
|
16205
|
+
alteredView.schema,
|
16206
|
+
materialized,
|
16207
|
+
alteredView.alteredTablespace.__new
|
16208
|
+
)
|
16209
|
+
);
|
16210
|
+
}
|
16211
|
+
if (alteredView.alteredUsing) {
|
16212
|
+
alterViews.push(
|
16213
|
+
preparePgAlterViewAlterUsingJson(
|
16214
|
+
alteredView.name,
|
16215
|
+
alteredView.schema,
|
16216
|
+
materialized,
|
16217
|
+
alteredView.alteredUsing.__new
|
16218
|
+
)
|
16219
|
+
);
|
16220
|
+
}
|
16221
|
+
}
|
15733
16222
|
jsonStatements.push(...createSchemas);
|
15734
16223
|
jsonStatements.push(...renameSchemas);
|
15735
16224
|
jsonStatements.push(...createEnums);
|
@@ -15741,6 +16230,9 @@ var init_snapshotsDiffer = __esm({
|
|
15741
16230
|
jsonStatements.push(...renameSequences);
|
15742
16231
|
jsonStatements.push(...jsonAlterSequences);
|
15743
16232
|
jsonStatements.push(...createTables);
|
16233
|
+
jsonStatements.push(...dropViews);
|
16234
|
+
jsonStatements.push(...renameViews);
|
16235
|
+
jsonStatements.push(...alterViews);
|
15744
16236
|
jsonStatements.push(...jsonDropTables);
|
15745
16237
|
jsonStatements.push(...jsonSetTableSchemas);
|
15746
16238
|
jsonStatements.push(...jsonRenameTables);
|
@@ -15760,6 +16252,7 @@ var init_snapshotsDiffer = __esm({
|
|
15760
16252
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15761
16253
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15762
16254
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16255
|
+
jsonStatements.push(...createViews);
|
15763
16256
|
jsonStatements.push(...dropEnums);
|
15764
16257
|
jsonStatements.push(...dropSequences);
|
15765
16258
|
jsonStatements.push(...dropSchemas);
|
@@ -16828,7 +17321,7 @@ var init_outputs = __esm({
|
|
16828
17321
|
});
|
16829
17322
|
|
16830
17323
|
// src/cli/commands/migrate.ts
|
16831
|
-
var import_hanji2, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
|
17324
|
+
var import_hanji2, schemasResolver, tablesResolver, viewsResolver, sequencesResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
|
16832
17325
|
var init_migrate = __esm({
|
16833
17326
|
"src/cli/commands/migrate.ts"() {
|
16834
17327
|
"use strict";
|
@@ -16873,6 +17366,24 @@ var init_migrate = __esm({
|
|
16873
17366
|
throw e5;
|
16874
17367
|
}
|
16875
17368
|
};
|
17369
|
+
viewsResolver = async (input) => {
|
17370
|
+
try {
|
17371
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
17372
|
+
input.created,
|
17373
|
+
input.deleted,
|
17374
|
+
"view"
|
17375
|
+
);
|
17376
|
+
return {
|
17377
|
+
created,
|
17378
|
+
deleted,
|
17379
|
+
moved,
|
17380
|
+
renamed
|
17381
|
+
};
|
17382
|
+
} catch (e5) {
|
17383
|
+
console.error(e5);
|
17384
|
+
throw e5;
|
17385
|
+
}
|
17386
|
+
};
|
16876
17387
|
sequencesResolver = async (input) => {
|
16877
17388
|
try {
|
16878
17389
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -19063,7 +19574,7 @@ function fillPlaceholders(params, values2) {
|
|
19063
19574
|
return p7;
|
19064
19575
|
});
|
19065
19576
|
}
|
19066
|
-
var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, _a25, _b10,
|
19577
|
+
var _a19, FakePrimitiveParam, _a20, StringChunk, _a21, _SQL, SQL, _a22, Name, noopDecoder, noopEncoder, noopMapper, _a23, Param, _a24, Placeholder, _a25, _b10, View4;
|
19067
19578
|
var init_sql = __esm({
|
19068
19579
|
"../drizzle-orm/dist/sql/sql.js"() {
|
19069
19580
|
"use strict";
|
@@ -19166,7 +19677,7 @@ var init_sql = __esm({
|
|
19166
19677
|
}
|
19167
19678
|
return { sql: escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName), params: [] };
|
19168
19679
|
}
|
19169
|
-
if (is(chunk,
|
19680
|
+
if (is(chunk, View4)) {
|
19170
19681
|
const schemaName = chunk[ViewBaseConfig].schema;
|
19171
19682
|
const viewName = chunk[ViewBaseConfig].name;
|
19172
19683
|
return {
|
@@ -19385,7 +19896,7 @@ var init_sql = __esm({
|
|
19385
19896
|
};
|
19386
19897
|
__publicField(Placeholder, _a24, "Placeholder");
|
19387
19898
|
_b10 = entityKind, _a25 = ViewBaseConfig;
|
19388
|
-
|
19899
|
+
View4 = class {
|
19389
19900
|
constructor({ name: name2, schema: schema4, selectedFields, query }) {
|
19390
19901
|
/** @internal */
|
19391
19902
|
__publicField(this, _a25);
|
@@ -19403,7 +19914,7 @@ var init_sql = __esm({
|
|
19403
19914
|
return new SQL([this]);
|
19404
19915
|
}
|
19405
19916
|
};
|
19406
|
-
__publicField(
|
19917
|
+
__publicField(View4, _b10, "View");
|
19407
19918
|
Column2.prototype.getSQL = function() {
|
19408
19919
|
return new SQL([this]);
|
19409
19920
|
};
|
@@ -19554,7 +20065,7 @@ var init_errors = __esm({
|
|
19554
20065
|
|
19555
20066
|
// ../drizzle-orm/dist/sql/expressions/conditions.js
|
19556
20067
|
function bindIfParam(value, column4) {
|
19557
|
-
if (isDriverValueEncoder(column4) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column2) && !is(value, Table2) && !is(value,
|
20068
|
+
if (isDriverValueEncoder(column4) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column2) && !is(value, Table2) && !is(value, View4)) {
|
19558
20069
|
return new Param(value, column4);
|
19559
20070
|
}
|
19560
20071
|
return value;
|
@@ -20855,12 +21366,12 @@ var require_utils2 = __commonJS({
|
|
20855
21366
|
}
|
20856
21367
|
return JSON.stringify(val2);
|
20857
21368
|
}
|
20858
|
-
function pad(
|
20859
|
-
|
20860
|
-
while (
|
20861
|
-
|
21369
|
+
function pad(number2, digits) {
|
21370
|
+
number2 = "" + number2;
|
21371
|
+
while (number2.length < digits) {
|
21372
|
+
number2 = "0" + number2;
|
20862
21373
|
}
|
20863
|
-
return
|
21374
|
+
return number2;
|
20864
21375
|
}
|
20865
21376
|
function dateToString(date3) {
|
20866
21377
|
var offset = -date3.getTimezoneOffset();
|
@@ -24537,7 +25048,7 @@ function getTableColumns(table4) {
|
|
24537
25048
|
return table4[Table2.Symbol.Columns];
|
24538
25049
|
}
|
24539
25050
|
function getTableLikeName(table4) {
|
24540
|
-
return is(table4, Subquery) ? table4._.alias : is(table4,
|
25051
|
+
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];
|
24541
25052
|
}
|
24542
25053
|
function getColumnNameAndConfig(a7, b8) {
|
24543
25054
|
return {
|
@@ -25758,23 +26269,23 @@ function hexToBytes(hex2) {
|
|
25758
26269
|
}
|
25759
26270
|
function bytesToFloat64(bytes2, offset) {
|
25760
26271
|
const buffer2 = new ArrayBuffer(8);
|
25761
|
-
const
|
26272
|
+
const view2 = new DataView(buffer2);
|
25762
26273
|
for (let i5 = 0; i5 < 8; i5++) {
|
25763
|
-
|
26274
|
+
view2.setUint8(i5, bytes2[offset + i5]);
|
25764
26275
|
}
|
25765
|
-
return
|
26276
|
+
return view2.getFloat64(0, true);
|
25766
26277
|
}
|
25767
26278
|
function parseEWKB(hex2) {
|
25768
26279
|
const bytes2 = hexToBytes(hex2);
|
25769
26280
|
let offset = 0;
|
25770
26281
|
const byteOrder = bytes2[offset];
|
25771
26282
|
offset += 1;
|
25772
|
-
const
|
25773
|
-
const geomType =
|
26283
|
+
const view2 = new DataView(bytes2.buffer);
|
26284
|
+
const geomType = view2.getUint32(offset, byteOrder === 1);
|
25774
26285
|
offset += 4;
|
25775
26286
|
let _srid;
|
25776
26287
|
if (geomType & 536870912) {
|
25777
|
-
_srid =
|
26288
|
+
_srid = view2.getUint32(offset, byteOrder === 1);
|
25778
26289
|
offset += 4;
|
25779
26290
|
}
|
25780
26291
|
if ((geomType & 65535) === 1) {
|
@@ -27013,7 +27524,7 @@ var init_view_base = __esm({
|
|
27013
27524
|
"use strict";
|
27014
27525
|
init_entity();
|
27015
27526
|
init_sql();
|
27016
|
-
PgViewBase = class extends (_b99 =
|
27527
|
+
PgViewBase = class extends (_b99 = View4, _a126 = entityKind, _b99) {
|
27017
27528
|
};
|
27018
27529
|
__publicField(PgViewBase, _a126, "PgViewBase");
|
27019
27530
|
}
|
@@ -27236,7 +27747,7 @@ var init_dialect = __esm({
|
|
27236
27747
|
joinsArray.push(
|
27237
27748
|
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}`
|
27238
27749
|
);
|
27239
|
-
} else if (is(table22,
|
27750
|
+
} else if (is(table22, View4)) {
|
27240
27751
|
const viewName = table22[ViewBaseConfig].name;
|
27241
27752
|
const viewSchema = table22[ViewBaseConfig].schema;
|
27242
27753
|
const origViewName = table22[ViewBaseConfig].originalName;
|
@@ -27373,10 +27884,10 @@ var init_dialect = __esm({
|
|
27373
27884
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
27374
27885
|
return sql`${withSql}insert into ${table4} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`;
|
27375
27886
|
}
|
27376
|
-
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
|
27887
|
+
buildRefreshMaterializedViewQuery({ view: view2, concurrently, withNoData }) {
|
27377
27888
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
27378
27889
|
const withNoDataSql = withNoData ? sql` with no data` : void 0;
|
27379
|
-
return sql`refresh materialized view${concurrentlySql} ${
|
27890
|
+
return sql`refresh materialized view${concurrentlySql} ${view2}${withNoDataSql}`;
|
27380
27891
|
}
|
27381
27892
|
prepareTyping(encoder) {
|
27382
27893
|
if (is(encoder, PgJsonb) || is(encoder, PgJson)) {
|
@@ -28150,7 +28661,7 @@ var init_selection_proxy = __esm({
|
|
28150
28661
|
if (typeof prop === "symbol") {
|
28151
28662
|
return subquery[prop];
|
28152
28663
|
}
|
28153
|
-
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery,
|
28664
|
+
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View4) ? subquery[ViewBaseConfig].selectedFields : subquery;
|
28154
28665
|
const value = columns[prop];
|
28155
28666
|
if (is(value, SQL.Aliased)) {
|
28156
28667
|
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
@@ -28632,7 +29143,7 @@ var init_select2 = __esm({
|
|
28632
29143
|
};
|
28633
29144
|
}
|
28634
29145
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
28635
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
29146
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View4) ? table4[ViewBaseConfig].selectedFields : table4[Table2.Symbol.Columns];
|
28636
29147
|
this.config.fields[tableName] = selection;
|
28637
29148
|
}
|
28638
29149
|
}
|
@@ -29051,7 +29562,7 @@ var init_refresh_materialized_view = __esm({
|
|
29051
29562
|
init_query_promise();
|
29052
29563
|
init_tracing();
|
29053
29564
|
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a134 = entityKind, _b102) {
|
29054
|
-
constructor(
|
29565
|
+
constructor(view2, session, dialect7) {
|
29055
29566
|
super();
|
29056
29567
|
__publicField(this, "config");
|
29057
29568
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -29061,7 +29572,7 @@ var init_refresh_materialized_view = __esm({
|
|
29061
29572
|
});
|
29062
29573
|
this.session = session;
|
29063
29574
|
this.dialect = dialect7;
|
29064
|
-
this.config = { view };
|
29575
|
+
this.config = { view: view2 };
|
29065
29576
|
}
|
29066
29577
|
concurrently() {
|
29067
29578
|
if (this.config.withNoData !== void 0) {
|
@@ -29692,8 +30203,8 @@ var init_db = __esm({
|
|
29692
30203
|
delete(table4) {
|
29693
30204
|
return new PgDeleteBase(table4, this.session, this.dialect);
|
29694
30205
|
}
|
29695
|
-
refreshMaterializedView(
|
29696
|
-
return new PgRefreshMaterializedView(
|
30206
|
+
refreshMaterializedView(view2) {
|
30207
|
+
return new PgRefreshMaterializedView(view2, this.session, this.dialect);
|
29697
30208
|
}
|
29698
30209
|
execute(query) {
|
29699
30210
|
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
@@ -29923,6 +30434,12 @@ function pgMaterializedViewWithSchema(name2, selection, schema4) {
|
|
29923
30434
|
}
|
29924
30435
|
return new MaterializedViewBuilder(name2, schema4);
|
29925
30436
|
}
|
30437
|
+
function isPgView(obj) {
|
30438
|
+
return is(obj, PgView);
|
30439
|
+
}
|
30440
|
+
function isPgMaterializedView(obj) {
|
30441
|
+
return is(obj, PgMaterializedView);
|
30442
|
+
}
|
29926
30443
|
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;
|
29927
30444
|
var init_view = __esm({
|
29928
30445
|
"../drizzle-orm/dist/pg-core/view.js"() {
|
@@ -30086,7 +30603,12 @@ var init_view = __esm({
|
|
30086
30603
|
existing() {
|
30087
30604
|
return new Proxy(
|
30088
30605
|
new PgMaterializedView({
|
30089
|
-
pgConfig:
|
30606
|
+
pgConfig: {
|
30607
|
+
tablespace: this.config.tablespace,
|
30608
|
+
using: this.config.using,
|
30609
|
+
with: this.config.with,
|
30610
|
+
withNoData: this.config.withNoData
|
30611
|
+
},
|
30090
30612
|
config: {
|
30091
30613
|
name: this.name,
|
30092
30614
|
schema: this.schema,
|
@@ -30105,7 +30627,12 @@ var init_view = __esm({
|
|
30105
30627
|
as(query) {
|
30106
30628
|
return new Proxy(
|
30107
30629
|
new PgMaterializedView({
|
30108
|
-
pgConfig:
|
30630
|
+
pgConfig: {
|
30631
|
+
tablespace: this.config.tablespace,
|
30632
|
+
using: this.config.using,
|
30633
|
+
with: this.config.with,
|
30634
|
+
withNoData: this.config.withNoData
|
30635
|
+
},
|
30109
30636
|
config: {
|
30110
30637
|
name: this.name,
|
30111
30638
|
schema: this.schema,
|
@@ -30329,17 +30856,32 @@ function getTableConfig(table4) {
|
|
30329
30856
|
schema: schema4
|
30330
30857
|
};
|
30331
30858
|
}
|
30859
|
+
function getViewConfig(view2) {
|
30860
|
+
return {
|
30861
|
+
...view2[ViewBaseConfig],
|
30862
|
+
...view2[PgViewConfig]
|
30863
|
+
};
|
30864
|
+
}
|
30865
|
+
function getMaterializedViewConfig(view2) {
|
30866
|
+
return {
|
30867
|
+
...view2[ViewBaseConfig],
|
30868
|
+
...view2[PgMaterializedViewConfig]
|
30869
|
+
};
|
30870
|
+
}
|
30332
30871
|
var init_utils4 = __esm({
|
30333
30872
|
"../drizzle-orm/dist/pg-core/utils.js"() {
|
30334
30873
|
"use strict";
|
30335
30874
|
init_entity();
|
30336
30875
|
init_table2();
|
30337
30876
|
init_table();
|
30877
|
+
init_view_common();
|
30338
30878
|
init_checks();
|
30339
30879
|
init_foreign_keys();
|
30340
30880
|
init_indexes();
|
30341
30881
|
init_primary_keys();
|
30342
30882
|
init_unique_constraint();
|
30883
|
+
init_view_common2();
|
30884
|
+
init_view();
|
30343
30885
|
}
|
30344
30886
|
});
|
30345
30887
|
|
@@ -38580,15 +39122,15 @@ var init_HeaderFormatter = __esm({
|
|
38580
39122
|
throw new Error("Int64 buffers must be exactly 8 bytes");
|
38581
39123
|
}
|
38582
39124
|
}
|
38583
|
-
static fromNumber(
|
38584
|
-
if (
|
38585
|
-
throw new Error(`${
|
39125
|
+
static fromNumber(number2) {
|
39126
|
+
if (number2 > 9223372036854776e3 || number2 < -9223372036854776e3) {
|
39127
|
+
throw new Error(`${number2} is too large (or, if negative, too small) to represent as an Int64`);
|
38586
39128
|
}
|
38587
39129
|
const bytes2 = new Uint8Array(8);
|
38588
|
-
for (let i5 = 7, remaining = Math.abs(Math.round(
|
39130
|
+
for (let i5 = 7, remaining = Math.abs(Math.round(number2)); i5 > -1 && remaining > 0; i5--, remaining /= 256) {
|
38589
39131
|
bytes2[i5] = remaining;
|
38590
39132
|
}
|
38591
|
-
if (
|
39133
|
+
if (number2 < 0) {
|
38592
39134
|
negate(bytes2);
|
38593
39135
|
}
|
38594
39136
|
return new _Int64(bytes2);
|
@@ -50831,7 +51373,7 @@ var init_view_base2 = __esm({
|
|
50831
51373
|
"use strict";
|
50832
51374
|
init_entity();
|
50833
51375
|
init_sql();
|
50834
|
-
SQLiteViewBase = class extends (_b152 =
|
51376
|
+
SQLiteViewBase = class extends (_b152 = View4, _a206 = entityKind, _b152) {
|
50835
51377
|
};
|
50836
51378
|
__publicField(SQLiteViewBase, _a206, "SQLiteViewBase");
|
50837
51379
|
}
|
@@ -51769,7 +52311,7 @@ var init_select3 = __esm({
|
|
51769
52311
|
};
|
51770
52312
|
}
|
51771
52313
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
51772
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
52314
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View4) ? table4[ViewBaseConfig].selectedFields : table4[Table2.Symbol.Columns];
|
51773
52315
|
this.config.fields[tableName] = selection;
|
51774
52316
|
}
|
51775
52317
|
}
|
@@ -59426,7 +59968,7 @@ function stringOpt(value) {
|
|
59426
59968
|
}
|
59427
59969
|
throw typeError(value, "string or null");
|
59428
59970
|
}
|
59429
|
-
function
|
59971
|
+
function number(value) {
|
59430
59972
|
if (typeof value === "number") {
|
59431
59973
|
return value;
|
59432
59974
|
}
|
@@ -61206,7 +61748,7 @@ function Error2(obj) {
|
|
61206
61748
|
function StmtResult(obj) {
|
61207
61749
|
const cols = arrayObjectsMap(obj["cols"], Col);
|
61208
61750
|
const rows = array(obj["rows"]).map((rowObj) => arrayObjectsMap(rowObj, Value4));
|
61209
|
-
const affectedRowCount =
|
61751
|
+
const affectedRowCount = number(obj["affected_row_count"]);
|
61210
61752
|
const lastInsertRowidStr = stringOpt(obj["last_insert_rowid"]);
|
61211
61753
|
const lastInsertRowid = lastInsertRowidStr !== void 0 ? BigInt(lastInsertRowidStr) : void 0;
|
61212
61754
|
return { cols, rows, affectedRowCount, lastInsertRowid };
|
@@ -61234,16 +61776,16 @@ function BatchResult(obj) {
|
|
61234
61776
|
function CursorEntry(obj) {
|
61235
61777
|
const type = string(obj["type"]);
|
61236
61778
|
if (type === "step_begin") {
|
61237
|
-
const step =
|
61779
|
+
const step = number(obj["step"]);
|
61238
61780
|
const cols = arrayObjectsMap(obj["cols"], Col);
|
61239
61781
|
return { type: "step_begin", step, cols };
|
61240
61782
|
} else if (type === "step_end") {
|
61241
|
-
const affectedRowCount =
|
61783
|
+
const affectedRowCount = number(obj["affected_row_count"]);
|
61242
61784
|
const lastInsertRowidStr = stringOpt(obj["last_insert_rowid"]);
|
61243
61785
|
const lastInsertRowid = lastInsertRowidStr !== void 0 ? BigInt(lastInsertRowidStr) : void 0;
|
61244
61786
|
return { type: "step_end", affectedRowCount, lastInsertRowid };
|
61245
61787
|
} else if (type === "step_error") {
|
61246
|
-
const step =
|
61788
|
+
const step = number(obj["step"]);
|
61247
61789
|
const error2 = Error2(object(obj["error"]));
|
61248
61790
|
return { type: "step_error", step, error: error2 };
|
61249
61791
|
} else if (type === "row") {
|
@@ -61280,7 +61822,7 @@ function Value4(obj) {
|
|
61280
61822
|
const value = string(obj["value"]);
|
61281
61823
|
return BigInt(value);
|
61282
61824
|
} else if (type === "float") {
|
61283
|
-
return
|
61825
|
+
return number(obj["value"]);
|
61284
61826
|
} else if (type === "text") {
|
61285
61827
|
return string(obj["value"]);
|
61286
61828
|
} else if (type === "blob") {
|
@@ -61307,11 +61849,11 @@ function ServerMsg(obj) {
|
|
61307
61849
|
const error2 = Error2(object(obj["error"]));
|
61308
61850
|
return { type: "hello_error", error: error2 };
|
61309
61851
|
} else if (type === "response_ok") {
|
61310
|
-
const requestId =
|
61852
|
+
const requestId = number(obj["request_id"]);
|
61311
61853
|
const response = Response(object(obj["response"]));
|
61312
61854
|
return { type: "response_ok", requestId, response };
|
61313
61855
|
} else if (type === "response_error") {
|
61314
|
-
const requestId =
|
61856
|
+
const requestId = number(obj["request_id"]);
|
61315
61857
|
const error2 = Error2(object(obj["error"]));
|
61316
61858
|
return { type: "response_error", requestId, error: error2 };
|
61317
61859
|
} else {
|
@@ -64485,12 +65027,12 @@ var require_SqlString = __commonJS({
|
|
64485
65027
|
}
|
64486
65028
|
return "'" + escapedVal + "'";
|
64487
65029
|
}
|
64488
|
-
function zeroPad(
|
64489
|
-
|
64490
|
-
while (
|
64491
|
-
|
65030
|
+
function zeroPad(number2, length) {
|
65031
|
+
number2 = number2.toString();
|
65032
|
+
while (number2.length < length) {
|
65033
|
+
number2 = "0" + number2;
|
64492
65034
|
}
|
64493
|
-
return
|
65035
|
+
return number2;
|
64494
65036
|
}
|
64495
65037
|
function convertTimezone(tz) {
|
64496
65038
|
if (tz === "Z") {
|
@@ -85061,7 +85603,7 @@ var init_view_base3 = __esm({
|
|
85061
85603
|
"use strict";
|
85062
85604
|
init_entity();
|
85063
85605
|
init_sql();
|
85064
|
-
MySqlViewBase = class extends (_b249 =
|
85606
|
+
MySqlViewBase = class extends (_b249 = View4, _a325 = entityKind, _b249) {
|
85065
85607
|
};
|
85066
85608
|
__publicField(MySqlViewBase, _a325, "MySqlViewBase");
|
85067
85609
|
}
|
@@ -85275,7 +85817,7 @@ var init_dialect3 = __esm({
|
|
85275
85817
|
joinsArray.push(
|
85276
85818
|
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}`
|
85277
85819
|
);
|
85278
|
-
} else if (is(table22,
|
85820
|
+
} else if (is(table22, View4)) {
|
85279
85821
|
const viewName = table22[ViewBaseConfig].name;
|
85280
85822
|
const viewSchema = table22[ViewBaseConfig].schema;
|
85281
85823
|
const origViewName = table22[ViewBaseConfig].originalName;
|
@@ -86291,7 +86833,7 @@ var init_select4 = __esm({
|
|
86291
86833
|
};
|
86292
86834
|
}
|
86293
86835
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
86294
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
86836
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View4) ? table4[ViewBaseConfig].selectedFields : table4[Table2.Symbol.Columns];
|
86295
86837
|
this.config.fields[tableName] = selection;
|
86296
86838
|
}
|
86297
86839
|
}
|
@@ -95015,13 +95557,13 @@ function Connection2(options, queues = {}, { onopen = noop, onend = noop, onclos
|
|
95015
95557
|
start = index4;
|
95016
95558
|
while (x6[index4++] !== 0) ;
|
95017
95559
|
const table4 = x6.readUInt32BE(index4);
|
95018
|
-
const
|
95560
|
+
const number2 = x6.readUInt16BE(index4 + 4);
|
95019
95561
|
const type = x6.readUInt32BE(index4 + 6);
|
95020
95562
|
query.statement.columns[i5] = {
|
95021
95563
|
name: transform.column.from ? transform.column.from(x6.toString("utf8", start, index4 - 1)) : x6.toString("utf8", start, index4 - 1),
|
95022
95564
|
parser: parsers2[type],
|
95023
95565
|
table: table4,
|
95024
|
-
number:
|
95566
|
+
number: number2,
|
95025
95567
|
type
|
95026
95568
|
};
|
95027
95569
|
index4 += 18;
|
@@ -112426,7 +112968,7 @@ __export(dist_exports4, {
|
|
112426
112968
|
Table: () => Table2,
|
112427
112969
|
TableAliasProxyHandler: () => TableAliasProxyHandler,
|
112428
112970
|
TransactionRollbackError: () => TransactionRollbackError,
|
112429
|
-
View: () =>
|
112971
|
+
View: () => View4,
|
112430
112972
|
ViewBaseConfig: () => ViewBaseConfig,
|
112431
112973
|
WithSubquery: () => WithSubquery,
|
112432
112974
|
aliasedRelation: () => aliasedRelation,
|
@@ -112587,8 +113129,9 @@ var init_pgSerializer = __esm({
|
|
112587
113129
|
indexName = (tableName, columns) => {
|
112588
113130
|
return `${tableName}_${columns.join("_")}_index`;
|
112589
113131
|
};
|
112590
|
-
generatePgSnapshot = (tables, enums, schemas, sequences, schemaFilter) => {
|
113132
|
+
generatePgSnapshot = (tables, enums, schemas, sequences, views, matViews, schemaFilter) => {
|
112591
113133
|
const result = {};
|
113134
|
+
const resultViews = {};
|
112592
113135
|
const sequencesToReturn = {};
|
112593
113136
|
const indexesInSchema = {};
|
112594
113137
|
for (const table4 of tables) {
|
@@ -112885,6 +113428,149 @@ ${withStyle.errorWarning(
|
|
112885
113428
|
} else {
|
112886
113429
|
}
|
112887
113430
|
}
|
113431
|
+
const combinedViews = [...views, ...matViews];
|
113432
|
+
for (const view2 of combinedViews) {
|
113433
|
+
let viewName;
|
113434
|
+
let schema4;
|
113435
|
+
let query;
|
113436
|
+
let selectedFields;
|
113437
|
+
let isExisting;
|
113438
|
+
let withOption;
|
113439
|
+
let tablespace;
|
113440
|
+
let using;
|
113441
|
+
let withNoData;
|
113442
|
+
let materialized = false;
|
113443
|
+
if (is(view2, PgView)) {
|
113444
|
+
({ name: viewName, schema: schema4, query, selectedFields, isExisting, with: withOption } = getViewConfig(view2));
|
113445
|
+
} else {
|
113446
|
+
({ name: viewName, schema: schema4, query, selectedFields, isExisting, with: withOption, tablespace, using, withNoData } = getMaterializedViewConfig(
|
113447
|
+
view2
|
113448
|
+
));
|
113449
|
+
materialized = true;
|
113450
|
+
}
|
113451
|
+
const viewSchema = schema4 ?? "public";
|
113452
|
+
const viewKey = `${viewSchema}.${viewName}`;
|
113453
|
+
const columnsObject = {};
|
113454
|
+
const uniqueConstraintObject = {};
|
113455
|
+
const existingView = resultViews[viewKey];
|
113456
|
+
if (typeof existingView !== "undefined") {
|
113457
|
+
console.log(
|
113458
|
+
`
|
113459
|
+
${withStyle.errorWarning(
|
113460
|
+
`We've found duplicated view name across ${source_default.underline.blue(
|
113461
|
+
schema4 ?? "public"
|
113462
|
+
)} schema. Please rename your view`
|
113463
|
+
)}`
|
113464
|
+
);
|
113465
|
+
process.exit(1);
|
113466
|
+
}
|
113467
|
+
for (const key in selectedFields) {
|
113468
|
+
if (is(selectedFields[key], PgColumn)) {
|
113469
|
+
const column4 = selectedFields[key];
|
113470
|
+
const notNull = column4.notNull;
|
113471
|
+
const primaryKey = column4.primary;
|
113472
|
+
const sqlTypeLowered = column4.getSQLType().toLowerCase();
|
113473
|
+
const typeSchema = is(column4, PgEnumColumn) ? column4.enum.schema || "public" : void 0;
|
113474
|
+
const generated = column4.generated;
|
113475
|
+
const identity = column4.generatedIdentity;
|
113476
|
+
const increment = stringFromIdentityProperty(identity?.sequenceOptions?.increment) ?? "1";
|
113477
|
+
const minValue = stringFromIdentityProperty(identity?.sequenceOptions?.minValue) ?? (parseFloat(increment) < 0 ? minRangeForIdentityBasedOn(column4.columnType) : "1");
|
113478
|
+
const maxValue = stringFromIdentityProperty(identity?.sequenceOptions?.maxValue) ?? (parseFloat(increment) < 0 ? "-1" : maxRangeForIdentityBasedOn(column4.getSQLType()));
|
113479
|
+
const startWith = stringFromIdentityProperty(identity?.sequenceOptions?.startWith) ?? (parseFloat(increment) < 0 ? maxValue : minValue);
|
113480
|
+
const cache = stringFromIdentityProperty(identity?.sequenceOptions?.cache) ?? "1";
|
113481
|
+
const columnToSet = {
|
113482
|
+
name: column4.name,
|
113483
|
+
type: column4.getSQLType(),
|
113484
|
+
typeSchema,
|
113485
|
+
primaryKey,
|
113486
|
+
notNull,
|
113487
|
+
generated: generated ? {
|
113488
|
+
as: is(generated.as, SQL) ? dialect4.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect4.sqlToQuery(generated.as()).sql : generated.as,
|
113489
|
+
type: "stored"
|
113490
|
+
} : void 0,
|
113491
|
+
identity: identity ? {
|
113492
|
+
type: identity.type,
|
113493
|
+
name: identity.sequenceName ?? `${viewName}_${column4.name}_seq`,
|
113494
|
+
schema: schema4 ?? "public",
|
113495
|
+
increment,
|
113496
|
+
startWith,
|
113497
|
+
minValue,
|
113498
|
+
maxValue,
|
113499
|
+
cache,
|
113500
|
+
cycle: identity?.sequenceOptions?.cycle ?? false
|
113501
|
+
} : void 0
|
113502
|
+
};
|
113503
|
+
if (column4.isUnique) {
|
113504
|
+
const existingUnique = uniqueConstraintObject[column4.uniqueName];
|
113505
|
+
if (typeof existingUnique !== "undefined") {
|
113506
|
+
console.log(
|
113507
|
+
`
|
113508
|
+
${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
113509
|
+
viewName
|
113510
|
+
)} table.
|
113511
|
+
The unique constraint ${source_default.underline.blue(
|
113512
|
+
column4.uniqueName
|
113513
|
+
)} on the ${source_default.underline.blue(
|
113514
|
+
column4.name
|
113515
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
113516
|
+
existingUnique.columns.join(",")
|
113517
|
+
)} columns
|
113518
|
+
`)}`
|
113519
|
+
);
|
113520
|
+
process.exit(1);
|
113521
|
+
}
|
113522
|
+
uniqueConstraintObject[column4.uniqueName] = {
|
113523
|
+
name: column4.uniqueName,
|
113524
|
+
nullsNotDistinct: column4.uniqueType === "not distinct",
|
113525
|
+
columns: [columnToSet.name]
|
113526
|
+
};
|
113527
|
+
}
|
113528
|
+
if (column4.default !== void 0) {
|
113529
|
+
if (is(column4.default, SQL)) {
|
113530
|
+
columnToSet.default = sqlToStr(column4.default);
|
113531
|
+
} else {
|
113532
|
+
if (typeof column4.default === "string") {
|
113533
|
+
columnToSet.default = `'${column4.default}'`;
|
113534
|
+
} else {
|
113535
|
+
if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
|
113536
|
+
columnToSet.default = `'${JSON.stringify(
|
113537
|
+
column4.default
|
113538
|
+
)}'::${sqlTypeLowered}`;
|
113539
|
+
} else if (column4.default instanceof Date) {
|
113540
|
+
if (sqlTypeLowered === "date") {
|
113541
|
+
columnToSet.default = `'${column4.default.toISOString().split("T")[0]}'`;
|
113542
|
+
} else if (sqlTypeLowered === "timestamp") {
|
113543
|
+
columnToSet.default = `'${column4.default.toISOString().replace("T", " ").slice(0, 23)}'`;
|
113544
|
+
} else {
|
113545
|
+
columnToSet.default = `'${column4.default.toISOString()}'`;
|
113546
|
+
}
|
113547
|
+
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
|
113548
|
+
columnToSet.default = `'${buildArrayString(
|
113549
|
+
column4.default,
|
113550
|
+
sqlTypeLowered
|
113551
|
+
)}'`;
|
113552
|
+
} else {
|
113553
|
+
columnToSet.default = column4.default;
|
113554
|
+
}
|
113555
|
+
}
|
113556
|
+
}
|
113557
|
+
}
|
113558
|
+
columnsObject[column4.name] = columnToSet;
|
113559
|
+
}
|
113560
|
+
}
|
113561
|
+
resultViews[viewKey] = {
|
113562
|
+
columns: columnsObject,
|
113563
|
+
definition: isExisting ? void 0 : dialect4.sqlToQuery(query).sql,
|
113564
|
+
name: viewName,
|
113565
|
+
schema: viewSchema,
|
113566
|
+
isExisting,
|
113567
|
+
with: withOption,
|
113568
|
+
withNoData,
|
113569
|
+
materialized,
|
113570
|
+
tablespace,
|
113571
|
+
using
|
113572
|
+
};
|
113573
|
+
}
|
112888
113574
|
const enumsToReturn = enums.reduce((map2, obj) => {
|
112889
113575
|
const enumSchema3 = obj.schema || "public";
|
112890
113576
|
const key = `${enumSchema3}.${obj.enumName}`;
|
@@ -112911,6 +113597,7 @@ ${withStyle.errorWarning(
|
|
112911
113597
|
enums: enumsToReturn,
|
112912
113598
|
schemas: schemasObject,
|
112913
113599
|
sequences: sequencesToReturn,
|
113600
|
+
views: resultViews,
|
112914
113601
|
_meta: {
|
112915
113602
|
schemas: {},
|
112916
113603
|
tables: {},
|
@@ -112927,10 +113614,25 @@ ${withStyle.errorWarning(
|
|
112927
113614
|
};
|
112928
113615
|
fromDatabase = async (db2, tablesFilter = () => true, schemaFilters, progressCallback) => {
|
112929
113616
|
const result = {};
|
113617
|
+
const views = {};
|
112930
113618
|
const internals = { tables: {} };
|
112931
|
-
const where = schemaFilters.map((t6) => `
|
113619
|
+
const where = schemaFilters.map((t6) => `n.nspname = '${t6}'`).join(" or ");
|
112932
113620
|
const allTables = await db2.query(
|
112933
|
-
`SELECT
|
113621
|
+
`SELECT
|
113622
|
+
n.nspname AS table_schema,
|
113623
|
+
c.relname AS table_name,
|
113624
|
+
CASE
|
113625
|
+
WHEN c.relkind = 'r' THEN 'table'
|
113626
|
+
WHEN c.relkind = 'v' THEN 'view'
|
113627
|
+
WHEN c.relkind = 'm' THEN 'materialized_view'
|
113628
|
+
END AS type
|
113629
|
+
FROM
|
113630
|
+
pg_catalog.pg_class c
|
113631
|
+
JOIN
|
113632
|
+
pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
113633
|
+
WHERE
|
113634
|
+
c.relkind IN ('r', 'v', 'm')
|
113635
|
+
${where === "" ? "" : ` AND ${where}`};`
|
112934
113636
|
);
|
112935
113637
|
const schemas = new Set(allTables.map((it) => it.table_schema));
|
112936
113638
|
schemas.delete("public");
|
@@ -113008,7 +113710,7 @@ ${withStyle.errorWarning(
|
|
113008
113710
|
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
113009
113711
|
}
|
113010
113712
|
const sequencesInColumns = [];
|
113011
|
-
const all = allTables.map((row) => {
|
113713
|
+
const all = allTables.filter((it) => it.type === "table").map((row) => {
|
113012
113714
|
return new Promise(async (res, rej) => {
|
113013
113715
|
const tableName = row.table_name;
|
113014
113716
|
if (!tablesFilter(tableName)) return res("");
|
@@ -113414,6 +114116,334 @@ ${withStyle.errorWarning(
|
|
113414
114116
|
}
|
113415
114117
|
for await (const _4 of all) {
|
113416
114118
|
}
|
114119
|
+
const allViews = allTables.filter((it) => it.type === "view" || it.type === "materialized_view").map((row) => {
|
114120
|
+
return new Promise(async (res, rej) => {
|
114121
|
+
const viewName = row.table_name;
|
114122
|
+
if (!tablesFilter(viewName)) return res("");
|
114123
|
+
tableCount += 1;
|
114124
|
+
const viewSchema = row.table_schema;
|
114125
|
+
try {
|
114126
|
+
const columnToReturn = {};
|
114127
|
+
const viewResponses = await db2.query(`WITH view_columns AS (
|
114128
|
+
SELECT DISTINCT
|
114129
|
+
nv.nspname::information_schema.sql_identifier AS view_schema,
|
114130
|
+
v.relname::information_schema.sql_identifier AS view_name,
|
114131
|
+
nt.nspname::information_schema.sql_identifier AS table_schema,
|
114132
|
+
t.relname::information_schema.sql_identifier AS table_name,
|
114133
|
+
a.attname::information_schema.sql_identifier AS column_name
|
114134
|
+
FROM pg_namespace nv
|
114135
|
+
JOIN pg_class v ON nv.oid = v.relnamespace
|
114136
|
+
JOIN pg_depend dv ON v.oid = dv.refobjid
|
114137
|
+
JOIN pg_depend dt ON dv.objid = dt.objid
|
114138
|
+
JOIN pg_class t ON dt.refobjid = t.oid
|
114139
|
+
JOIN pg_namespace nt ON t.relnamespace = nt.oid
|
114140
|
+
JOIN pg_attribute a ON t.oid = a.attrelid
|
114141
|
+
WHERE (v.relkind = 'v'::"char" OR v.relkind = 'm'::"char")
|
114142
|
+
AND dv.refclassid = 'pg_class'::regclass::oid
|
114143
|
+
AND dv.classid = 'pg_rewrite'::regclass::oid
|
114144
|
+
AND dv.deptype = 'i'::"char"
|
114145
|
+
AND dv.objid = dt.objid
|
114146
|
+
AND dv.refobjid <> dt.refobjid
|
114147
|
+
AND dt.classid = 'pg_rewrite'::regclass::oid
|
114148
|
+
AND dt.refclassid = 'pg_class'::regclass::oid
|
114149
|
+
AND t.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])
|
114150
|
+
AND dt.refobjsubid = a.attnum
|
114151
|
+
AND pg_has_role(t.relowner, 'USAGE'::text)
|
114152
|
+
AND nv.nspname::information_schema.sql_identifier = '${viewSchema}'
|
114153
|
+
AND v.relname::information_schema.sql_identifier = '${viewName}'
|
114154
|
+
),
|
114155
|
+
column_descriptions AS (
|
114156
|
+
SELECT DISTINCT
|
114157
|
+
a.attrelid::regclass::text AS table_name,
|
114158
|
+
a.attname AS column_name,
|
114159
|
+
c.is_nullable,
|
114160
|
+
a.attndims AS array_dimensions,
|
114161
|
+
CASE
|
114162
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
|
114163
|
+
SELECT FROM pg_attrdef ad
|
114164
|
+
WHERE ad.adrelid = a.attrelid
|
114165
|
+
AND ad.adnum = a.attnum
|
114166
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
114167
|
+
)
|
114168
|
+
THEN CASE a.atttypid
|
114169
|
+
WHEN 'int'::regtype THEN 'serial'
|
114170
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
114171
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
114172
|
+
END
|
114173
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
114174
|
+
END AS data_type,
|
114175
|
+
pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
|
114176
|
+
c.column_default,
|
114177
|
+
c.data_type AS additional_dt,
|
114178
|
+
c.udt_name AS enum_name,
|
114179
|
+
c.is_generated,
|
114180
|
+
c.generation_expression,
|
114181
|
+
c.is_identity,
|
114182
|
+
c.identity_generation,
|
114183
|
+
c.identity_start,
|
114184
|
+
c.identity_increment,
|
114185
|
+
c.identity_maximum,
|
114186
|
+
c.identity_minimum,
|
114187
|
+
c.identity_cycle
|
114188
|
+
FROM pg_attribute a
|
114189
|
+
JOIN information_schema.columns c ON c.column_name = a.attname
|
114190
|
+
JOIN pg_type t ON t.oid = a.atttypid
|
114191
|
+
LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
114192
|
+
WHERE a.attnum > 0
|
114193
|
+
AND NOT a.attisdropped
|
114194
|
+
),
|
114195
|
+
table_constraints AS (
|
114196
|
+
SELECT DISTINCT ON (ccu.column_name)
|
114197
|
+
ccu.column_name,
|
114198
|
+
c.data_type,
|
114199
|
+
tc.constraint_type,
|
114200
|
+
tc.constraint_name,
|
114201
|
+
tc.constraint_schema,
|
114202
|
+
tc.table_name
|
114203
|
+
FROM information_schema.table_constraints tc
|
114204
|
+
JOIN information_schema.constraint_column_usage ccu USING (constraint_schema, constraint_name)
|
114205
|
+
JOIN information_schema.columns c ON c.table_schema = tc.constraint_schema
|
114206
|
+
AND tc.table_name = c.table_name
|
114207
|
+
AND ccu.column_name = c.column_name
|
114208
|
+
),
|
114209
|
+
additional_column_info AS (
|
114210
|
+
SELECT DISTINCT
|
114211
|
+
a.attrelid::regclass::text AS table_name,
|
114212
|
+
a.attname AS column_name,
|
114213
|
+
is_nullable,
|
114214
|
+
a.attndims AS array_dimensions,
|
114215
|
+
CASE
|
114216
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
|
114217
|
+
SELECT FROM pg_attrdef ad
|
114218
|
+
WHERE ad.adrelid = a.attrelid
|
114219
|
+
AND ad.adnum = a.attnum
|
114220
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
114221
|
+
)
|
114222
|
+
THEN CASE a.atttypid
|
114223
|
+
WHEN 'int'::regtype THEN 'serial'
|
114224
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
114225
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
114226
|
+
END
|
114227
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
114228
|
+
END AS data_type,
|
114229
|
+
pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
|
114230
|
+
c.column_default,
|
114231
|
+
c.data_type AS additional_dt,
|
114232
|
+
c.udt_name AS enum_name,
|
114233
|
+
c.is_generated,
|
114234
|
+
generation_expression,
|
114235
|
+
is_identity,
|
114236
|
+
identity_generation,
|
114237
|
+
identity_start,
|
114238
|
+
identity_increment,
|
114239
|
+
identity_maximum,
|
114240
|
+
identity_minimum,
|
114241
|
+
identity_cycle
|
114242
|
+
FROM pg_attribute a
|
114243
|
+
JOIN information_schema.columns c ON c.column_name = a.attname
|
114244
|
+
LEFT JOIN pg_type t ON t.oid = a.atttypid
|
114245
|
+
LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
114246
|
+
WHERE a.attnum > 0
|
114247
|
+
AND NOT a.attisdropped
|
114248
|
+
)
|
114249
|
+
SELECT DISTINCT ON (vc.table_name, vc.column_name)
|
114250
|
+
vc.view_schema,
|
114251
|
+
vc.view_name,
|
114252
|
+
vc.table_schema,
|
114253
|
+
vc.table_name,
|
114254
|
+
vc.column_name,
|
114255
|
+
COALESCE(cd.data_type, aci.data_type) AS data_type,
|
114256
|
+
tc.constraint_type,
|
114257
|
+
tc.constraint_name,
|
114258
|
+
aci.is_nullable,
|
114259
|
+
aci.array_dimensions,
|
114260
|
+
aci.seq_name,
|
114261
|
+
aci.column_default,
|
114262
|
+
aci.additional_dt,
|
114263
|
+
aci.enum_name,
|
114264
|
+
aci.is_generated,
|
114265
|
+
aci.generation_expression,
|
114266
|
+
aci.is_identity,
|
114267
|
+
aci.identity_generation,
|
114268
|
+
aci.identity_start,
|
114269
|
+
aci.identity_increment,
|
114270
|
+
aci.identity_maximum,
|
114271
|
+
aci.identity_minimum,
|
114272
|
+
aci.identity_cycle
|
114273
|
+
FROM view_columns vc
|
114274
|
+
LEFT JOIN column_descriptions cd ON vc.table_name = cd.table_name AND vc.column_name = cd.column_name
|
114275
|
+
LEFT JOIN table_constraints tc ON vc.table_name = tc.table_name AND vc.column_name = tc.column_name
|
114276
|
+
LEFT JOIN additional_column_info aci ON vc.table_name = aci.table_name AND vc.column_name = aci.column_name
|
114277
|
+
ORDER BY vc.table_name, vc.column_name;`);
|
114278
|
+
for (const viewResponse of viewResponses) {
|
114279
|
+
const columnName = viewResponse.column_name;
|
114280
|
+
const columnAdditionalDT = viewResponse.additional_dt;
|
114281
|
+
const columnDimensions = viewResponse.array_dimensions;
|
114282
|
+
const enumType2 = viewResponse.enum_name;
|
114283
|
+
let columnType = viewResponse.data_type;
|
114284
|
+
const typeSchema = viewResponse.type_schema;
|
114285
|
+
const isGenerated = viewResponse.is_generated === "ALWAYS";
|
114286
|
+
const generationExpression = viewResponse.generation_expression;
|
114287
|
+
const isIdentity = viewResponse.is_identity === "YES";
|
114288
|
+
const identityGeneration = viewResponse.identity_generation === "ALWAYS" ? "always" : "byDefault";
|
114289
|
+
const identityStart = viewResponse.identity_start;
|
114290
|
+
const identityIncrement = viewResponse.identity_increment;
|
114291
|
+
const identityMaximum = viewResponse.identity_maximum;
|
114292
|
+
const identityMinimum = viewResponse.identity_minimum;
|
114293
|
+
const identityCycle = viewResponse.identity_cycle === "YES";
|
114294
|
+
const identityName = viewResponse.seq_name;
|
114295
|
+
const defaultValueRes = viewResponse.column_default;
|
114296
|
+
const primaryKey = viewResponse.constraint_type === "PRIMARY KEY";
|
114297
|
+
let columnTypeMapped = columnType;
|
114298
|
+
if (columnAdditionalDT === "ARRAY") {
|
114299
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
114300
|
+
internals.tables[viewName] = {
|
114301
|
+
columns: {
|
114302
|
+
[columnName]: {
|
114303
|
+
isArray: true,
|
114304
|
+
dimensions: columnDimensions,
|
114305
|
+
rawType: columnTypeMapped.substring(
|
114306
|
+
0,
|
114307
|
+
columnTypeMapped.length - 2
|
114308
|
+
)
|
114309
|
+
}
|
114310
|
+
}
|
114311
|
+
};
|
114312
|
+
} else {
|
114313
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
114314
|
+
internals.tables[viewName].columns[columnName] = {
|
114315
|
+
isArray: true,
|
114316
|
+
dimensions: columnDimensions,
|
114317
|
+
rawType: columnTypeMapped.substring(
|
114318
|
+
0,
|
114319
|
+
columnTypeMapped.length - 2
|
114320
|
+
)
|
114321
|
+
};
|
114322
|
+
}
|
114323
|
+
}
|
114324
|
+
}
|
114325
|
+
const defaultValue = defaultForColumn(
|
114326
|
+
viewResponse,
|
114327
|
+
internals,
|
114328
|
+
viewName
|
114329
|
+
);
|
114330
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
114331
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
114332
|
+
internals.tables[viewName] = {
|
114333
|
+
columns: {
|
114334
|
+
[columnName]: {
|
114335
|
+
isDefaultAnExpression: true
|
114336
|
+
}
|
114337
|
+
}
|
114338
|
+
};
|
114339
|
+
} else {
|
114340
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
114341
|
+
internals.tables[viewName].columns[columnName] = {
|
114342
|
+
isDefaultAnExpression: true
|
114343
|
+
};
|
114344
|
+
} else {
|
114345
|
+
internals.tables[viewName].columns[columnName].isDefaultAnExpression = true;
|
114346
|
+
}
|
114347
|
+
}
|
114348
|
+
}
|
114349
|
+
const isSerial = columnType === "serial";
|
114350
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
114351
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
114352
|
+
}
|
114353
|
+
if (columnAdditionalDT === "ARRAY") {
|
114354
|
+
for (let i5 = 1; i5 < Number(columnDimensions); i5++) {
|
114355
|
+
columnTypeMapped += "[]";
|
114356
|
+
}
|
114357
|
+
}
|
114358
|
+
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
114359
|
+
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
114360
|
+
columnToReturn[columnName] = {
|
114361
|
+
name: columnName,
|
114362
|
+
type: (
|
114363
|
+
// filter vectors, but in future we should filter any extension that was installed by user
|
114364
|
+
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
114365
|
+
),
|
114366
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
114367
|
+
primaryKey,
|
114368
|
+
notNull: viewResponse.is_nullable === "NO",
|
114369
|
+
generated: isGenerated ? { as: generationExpression, type: "stored" } : void 0,
|
114370
|
+
identity: isIdentity ? {
|
114371
|
+
type: identityGeneration,
|
114372
|
+
name: identityName,
|
114373
|
+
increment: stringFromDatabaseIdentityProperty(identityIncrement),
|
114374
|
+
minValue: stringFromDatabaseIdentityProperty(identityMinimum),
|
114375
|
+
maxValue: stringFromDatabaseIdentityProperty(identityMaximum),
|
114376
|
+
startWith: stringFromDatabaseIdentityProperty(identityStart),
|
114377
|
+
cache: sequencesToReturn[identityName]?.cache ? sequencesToReturn[identityName]?.cache : sequencesToReturn[`${viewSchema}.${identityName}`]?.cache ? sequencesToReturn[`${viewSchema}.${identityName}`]?.cache : void 0,
|
114378
|
+
cycle: identityCycle,
|
114379
|
+
schema: viewSchema
|
114380
|
+
} : void 0
|
114381
|
+
};
|
114382
|
+
if (identityName) {
|
114383
|
+
delete sequencesToReturn[`${viewSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
|
114384
|
+
delete sequencesToReturn[identityName];
|
114385
|
+
}
|
114386
|
+
if (!isSerial && typeof defaultValue !== "undefined") {
|
114387
|
+
columnToReturn[columnName].default = defaultValue;
|
114388
|
+
}
|
114389
|
+
}
|
114390
|
+
const [viewInfo] = await db2.query(`
|
114391
|
+
SELECT
|
114392
|
+
c.relname AS view_name,
|
114393
|
+
n.nspname AS schema_name,
|
114394
|
+
pg_get_viewdef(c.oid, true) AS definition,
|
114395
|
+
ts.spcname AS tablespace_name,
|
114396
|
+
c.reloptions AS options,
|
114397
|
+
pg_tablespace_location(ts.oid) AS location
|
114398
|
+
FROM
|
114399
|
+
pg_class c
|
114400
|
+
JOIN
|
114401
|
+
pg_namespace n ON c.relnamespace = n.oid
|
114402
|
+
LEFT JOIN
|
114403
|
+
pg_tablespace ts ON c.reltablespace = ts.oid
|
114404
|
+
WHERE
|
114405
|
+
(c.relkind = 'm' OR c.relkind = 'v')
|
114406
|
+
AND n.nspname = '${viewSchema}'
|
114407
|
+
AND c.relname = '${viewName}';`);
|
114408
|
+
const resultWith = {};
|
114409
|
+
if (viewInfo.options) {
|
114410
|
+
viewInfo.options.forEach((pair) => {
|
114411
|
+
const splitted = pair.split("=");
|
114412
|
+
const key = splitted[0];
|
114413
|
+
const value = splitted[1];
|
114414
|
+
if (value === "true") {
|
114415
|
+
resultWith[key] = true;
|
114416
|
+
} else if (value === "false") {
|
114417
|
+
resultWith[key] = false;
|
114418
|
+
} else if (!isNaN(Number(value))) {
|
114419
|
+
resultWith[key] = Number(value);
|
114420
|
+
} else {
|
114421
|
+
resultWith[key] = value;
|
114422
|
+
}
|
114423
|
+
});
|
114424
|
+
}
|
114425
|
+
const definition = viewInfo.definition.replace(/\s+/g, " ").replace(";", "").trim();
|
114426
|
+
const withOption = Object.values(resultWith).length ? Object.fromEntries(Object.entries(resultWith).map(([key, value]) => [key.camelCase(), value])) : void 0;
|
114427
|
+
const materialized = row.type === "materialized_view";
|
114428
|
+
views[`${viewSchema}.${viewName}`] = {
|
114429
|
+
name: viewName,
|
114430
|
+
schema: viewSchema,
|
114431
|
+
columns: columnToReturn,
|
114432
|
+
isExisting: false,
|
114433
|
+
definition,
|
114434
|
+
materialized,
|
114435
|
+
with: withOption,
|
114436
|
+
tablespace: viewInfo.tablespace_name ?? void 0
|
114437
|
+
};
|
114438
|
+
} catch (e5) {
|
114439
|
+
rej(e5);
|
114440
|
+
return;
|
114441
|
+
}
|
114442
|
+
res("");
|
114443
|
+
});
|
114444
|
+
});
|
114445
|
+
for await (const _4 of allViews) {
|
114446
|
+
}
|
113417
114447
|
if (progressCallback) {
|
113418
114448
|
progressCallback("columns", columnsCount, "done");
|
113419
114449
|
progressCallback("indexes", indexesCount, "done");
|
@@ -113427,6 +114457,7 @@ ${withStyle.errorWarning(
|
|
113427
114457
|
enums: enumsToReturn,
|
113428
114458
|
schemas: schemasObject,
|
113429
114459
|
sequences: sequencesToReturn,
|
114460
|
+
views,
|
113430
114461
|
_meta: {
|
113431
114462
|
schemas: {},
|
113432
114463
|
tables: {},
|
@@ -115289,6 +116320,8 @@ var init_pgImports = __esm({
|
|
115289
116320
|
const enums = [];
|
115290
116321
|
const schemas = [];
|
115291
116322
|
const sequences = [];
|
116323
|
+
const views = [];
|
116324
|
+
const matViews = [];
|
115292
116325
|
const i0values = Object.values(exports);
|
115293
116326
|
i0values.forEach((t6) => {
|
115294
116327
|
if (isPgEnum(t6)) {
|
@@ -115301,11 +116334,17 @@ var init_pgImports = __esm({
|
|
115301
116334
|
if (is(t6, PgSchema5)) {
|
115302
116335
|
schemas.push(t6);
|
115303
116336
|
}
|
116337
|
+
if (isPgView(t6)) {
|
116338
|
+
views.push(t6);
|
116339
|
+
}
|
116340
|
+
if (isPgMaterializedView(t6)) {
|
116341
|
+
matViews.push(t6);
|
116342
|
+
}
|
115304
116343
|
if (isPgSequence(t6)) {
|
115305
116344
|
sequences.push(t6);
|
115306
116345
|
}
|
115307
116346
|
});
|
115308
|
-
return { tables, enums, schemas, sequences };
|
116347
|
+
return { tables, enums, schemas, sequences, views, matViews };
|
115309
116348
|
};
|
115310
116349
|
}
|
115311
116350
|
});
|
@@ -116145,6 +117184,9 @@ String.prototype.capitalise = function() {
|
|
116145
117184
|
String.prototype.concatIf = function(it, condition) {
|
116146
117185
|
return condition ? `${this}${it}` : String(this);
|
116147
117186
|
};
|
117187
|
+
String.prototype.snake_case = function() {
|
117188
|
+
return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
|
117189
|
+
};
|
116148
117190
|
Array.prototype.random = function() {
|
116149
117191
|
return this[~~(Math.random() * this.length)];
|
116150
117192
|
};
|
@@ -116205,6 +117247,8 @@ var generateDrizzleJson = (imports, prevId, schemaFilters) => {
|
|
116205
117247
|
prepared.enums,
|
116206
117248
|
prepared.schemas,
|
116207
117249
|
prepared.sequences,
|
117250
|
+
prepared.views,
|
117251
|
+
prepared.matViews,
|
116208
117252
|
schemaFilters
|
116209
117253
|
);
|
116210
117254
|
return fillPgSnapshot({
|
@@ -116227,6 +117271,7 @@ var generateMigration = async (prev, cur) => {
|
|
116227
117271
|
sequencesResolver,
|
116228
117272
|
tablesResolver,
|
116229
117273
|
columnsResolver,
|
117274
|
+
viewsResolver,
|
116230
117275
|
validatedPrev,
|
116231
117276
|
validatedCur
|
116232
117277
|
);
|
@@ -116259,6 +117304,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
|
|
116259
117304
|
sequencesResolver,
|
116260
117305
|
tablesResolver,
|
116261
117306
|
columnsResolver,
|
117307
|
+
viewsResolver,
|
116262
117308
|
validatedPrev,
|
116263
117309
|
validatedCur,
|
116264
117310
|
"push"
|