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.
Files changed (8) hide show
  1. package/api.d.mts +474 -0
  2. package/api.d.ts +474 -0
  3. package/api.js +1126 -80
  4. package/api.mjs +1126 -80
  5. package/bin.cjs +1168 -89
  6. package/package.json +1 -1
  7. package/utils.js +51 -11
  8. package/utils.mjs +51 -11
package/bin.cjs CHANGED
@@ -922,8 +922,8 @@ var require_hanji = __commonJS({
922
922
  };
923
923
  exports2.deferred = deferred;
924
924
  var Terminal = class {
925
- constructor(view, stdin, stdout, closable) {
926
- this.view = view;
925
+ constructor(view2, stdin, stdout, closable) {
926
+ this.view = view2;
927
927
  this.stdin = stdin;
928
928
  this.stdout = stdout;
929
929
  this.closable = closable;
@@ -961,7 +961,7 @@ var require_hanji = __commonJS({
961
961
  this.resolve({ status: "submitted", data: this.view.result() });
962
962
  return;
963
963
  }
964
- view.input(str, key);
964
+ view2.input(str, key);
965
965
  };
966
966
  this.stdin.on("keypress", keypress);
967
967
  this.view.attach(this);
@@ -1023,8 +1023,8 @@ var require_hanji = __commonJS({
1023
1023
  };
1024
1024
  exports2.TaskView = TaskView2;
1025
1025
  var TaskTerminal = class {
1026
- constructor(view, stdout) {
1027
- this.view = view;
1026
+ constructor(view2, stdout) {
1027
+ this.view = view2;
1028
1028
  this.stdout = stdout;
1029
1029
  this.text = "";
1030
1030
  this.view.attach(this);
@@ -1043,22 +1043,22 @@ var require_hanji = __commonJS({
1043
1043
  }
1044
1044
  };
1045
1045
  exports2.TaskTerminal = TaskTerminal;
1046
- function render9(view) {
1046
+ function render9(view2) {
1047
1047
  const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
1048
- if (view instanceof Prompt3) {
1049
- const terminal = new Terminal(view, stdin, stdout, closable);
1048
+ if (view2 instanceof Prompt3) {
1049
+ const terminal = new Terminal(view2, stdin, stdout, closable);
1050
1050
  terminal.requestLayout();
1051
1051
  return terminal.result();
1052
1052
  }
1053
- stdout.write(`${view}
1053
+ stdout.write(`${view2}
1054
1054
  `);
1055
1055
  closable.close();
1056
1056
  return;
1057
1057
  }
1058
1058
  exports2.render = render9;
1059
- function renderWithTask6(view, task) {
1059
+ function renderWithTask6(view2, task) {
1060
1060
  return __awaiter2(this, void 0, void 0, function* () {
1061
- const terminal = new TaskTerminal(view, process.stdout);
1061
+ const terminal = new TaskTerminal(view2, process.stdout);
1062
1062
  terminal.requestLayout();
1063
1063
  const result = yield task;
1064
1064
  terminal.clear();
@@ -5706,7 +5706,7 @@ var init_vector = __esm({
5706
5706
  });
5707
5707
 
5708
5708
  // src/serializer/pgSchema.ts
5709
- 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;
5709
+ 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;
5710
5710
  var init_pgSchema = __esm({
5711
5711
  "src/serializer/pgSchema.ts"() {
5712
5712
  "use strict";
@@ -5901,6 +5901,44 @@ var init_pgSchema = __esm({
5901
5901
  columns: stringType().array(),
5902
5902
  nullsNotDistinct: booleanType()
5903
5903
  }).strict();
5904
+ viewWithOption = objectType({
5905
+ checkOption: enumType(["local", "cascaded"]).optional(),
5906
+ securityBarrier: booleanType().optional(),
5907
+ securityInvoker: booleanType().optional()
5908
+ }).strict();
5909
+ matViewWithOption = objectType({
5910
+ fillfactor: numberType().optional(),
5911
+ toastTupleTarget: numberType().optional(),
5912
+ parallelWorkers: numberType().optional(),
5913
+ autovacuumEnabled: booleanType().optional(),
5914
+ vacuumIndexCleanup: enumType(["auto", "off", "on"]).optional(),
5915
+ vacuumTruncate: booleanType().optional(),
5916
+ autovacuumVacuumThreshold: numberType().optional(),
5917
+ autovacuumVacuumScaleFactor: numberType().optional(),
5918
+ autovacuumVacuumCostDelay: numberType().optional(),
5919
+ autovacuumVacuumCostLimit: numberType().optional(),
5920
+ autovacuumFreezeMinAge: numberType().optional(),
5921
+ autovacuumFreezeMaxAge: numberType().optional(),
5922
+ autovacuumFreezeTableAge: numberType().optional(),
5923
+ autovacuumMultixactFreezeMinAge: numberType().optional(),
5924
+ autovacuumMultixactFreezeMaxAge: numberType().optional(),
5925
+ autovacuumMultixactFreezeTableAge: numberType().optional(),
5926
+ logAutovacuumMinDuration: numberType().optional(),
5927
+ userCatalogTable: booleanType().optional()
5928
+ }).strict();
5929
+ mergedViewWithOption = viewWithOption.merge(matViewWithOption);
5930
+ view = objectType({
5931
+ name: stringType(),
5932
+ schema: stringType(),
5933
+ columns: recordType(stringType(), column2),
5934
+ definition: stringType().optional(),
5935
+ materialized: booleanType(),
5936
+ with: mergedViewWithOption.optional(),
5937
+ isExisting: booleanType(),
5938
+ withNoData: booleanType().optional(),
5939
+ using: stringType().optional(),
5940
+ tablespace: stringType().optional()
5941
+ }).strict();
5904
5942
  tableV42 = objectType({
5905
5943
  name: stringType(),
5906
5944
  schema: stringType(),
@@ -6035,6 +6073,7 @@ var init_pgSchema = __esm({
6035
6073
  tables: recordType(stringType(), table2),
6036
6074
  enums: recordType(stringType(), enumSchema),
6037
6075
  schemas: recordType(stringType(), stringType()),
6076
+ views: recordType(stringType(), view).default({}),
6038
6077
  sequences: recordType(stringType(), sequenceSchema).default({}),
6039
6078
  _meta: objectType({
6040
6079
  schemas: recordType(stringType(), stringType()),
@@ -6079,6 +6118,7 @@ var init_pgSchema = __esm({
6079
6118
  tables: recordType(stringType(), tableSquashed2),
6080
6119
  enums: recordType(stringType(), enumSchema),
6081
6120
  schemas: recordType(stringType(), stringType()),
6121
+ views: recordType(stringType(), view),
6082
6122
  sequences: recordType(stringType(), sequenceSquashed)
6083
6123
  }).strict();
6084
6124
  pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
@@ -6296,6 +6336,7 @@ var init_pgSchema = __esm({
6296
6336
  tables: mappedTables,
6297
6337
  enums: json.enums,
6298
6338
  schemas: json.schemas,
6339
+ views: json.views,
6299
6340
  sequences: mappedSequences
6300
6341
  };
6301
6342
  };
@@ -8811,6 +8852,9 @@ var init_utils3 = __esm({
8811
8852
  String.prototype.concatIf = function(it, condition) {
8812
8853
  return condition ? `${this}${it}` : String(this);
8813
8854
  };
8855
+ String.prototype.snake_case = function() {
8856
+ return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
8857
+ };
8814
8858
  Array.prototype.random = function() {
8815
8859
  return this[~~(Math.random() * this.length)];
8816
8860
  };
@@ -12507,11 +12551,11 @@ var require_node2 = __commonJS({
12507
12551
  };
12508
12552
  var require_base64 = __commonJS3((exports3) => {
12509
12553
  var intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
12510
- exports3.encode = function(number3) {
12511
- if (0 <= number3 && number3 < intToCharMap.length) {
12512
- return intToCharMap[number3];
12554
+ exports3.encode = function(number2) {
12555
+ if (0 <= number2 && number2 < intToCharMap.length) {
12556
+ return intToCharMap[number2];
12513
12557
  }
12514
- throw new TypeError("Must be between 0 and 63: " + number3);
12558
+ throw new TypeError("Must be between 0 and 63: " + number2);
12515
12559
  };
12516
12560
  exports3.decode = function(charCode) {
12517
12561
  var bigA = 65;
@@ -18464,6 +18508,8 @@ var init_pgImports = __esm({
18464
18508
  const enums = [];
18465
18509
  const schemas = [];
18466
18510
  const sequences = [];
18511
+ const views = [];
18512
+ const matViews = [];
18467
18513
  const i0values = Object.values(exports2);
18468
18514
  i0values.forEach((t2) => {
18469
18515
  if ((0, import_pg_core.isPgEnum)(t2)) {
@@ -18476,17 +18522,25 @@ var init_pgImports = __esm({
18476
18522
  if ((0, import_drizzle_orm4.is)(t2, import_pg_core.PgSchema)) {
18477
18523
  schemas.push(t2);
18478
18524
  }
18525
+ if ((0, import_pg_core.isPgView)(t2)) {
18526
+ views.push(t2);
18527
+ }
18528
+ if ((0, import_pg_core.isPgMaterializedView)(t2)) {
18529
+ matViews.push(t2);
18530
+ }
18479
18531
  if ((0, import_pg_core.isPgSequence)(t2)) {
18480
18532
  sequences.push(t2);
18481
18533
  }
18482
18534
  });
18483
- return { tables, enums, schemas, sequences };
18535
+ return { tables, enums, schemas, sequences, views, matViews };
18484
18536
  };
18485
18537
  prepareFromPgImports = async (imports) => {
18486
- let tables = [];
18487
- let enums = [];
18488
- let schemas = [];
18489
- let sequences = [];
18538
+ const tables = [];
18539
+ const enums = [];
18540
+ const schemas = [];
18541
+ const sequences = [];
18542
+ const views = [];
18543
+ const matViews = [];
18490
18544
  const { unregister } = await safeRegister();
18491
18545
  for (let i2 = 0; i2 < imports.length; i2++) {
18492
18546
  const it = imports[i2];
@@ -18496,9 +18550,11 @@ var init_pgImports = __esm({
18496
18550
  enums.push(...prepared.enums);
18497
18551
  schemas.push(...prepared.schemas);
18498
18552
  sequences.push(...prepared.sequences);
18553
+ views.push(...prepared.views);
18554
+ matViews.push(...prepared.matViews);
18499
18555
  }
18500
18556
  unregister();
18501
- return { tables: Array.from(new Set(tables)), enums, schemas, sequences };
18557
+ return { tables: Array.from(new Set(tables)), enums, schemas, sequences, views, matViews };
18502
18558
  };
18503
18559
  }
18504
18560
  });
@@ -18562,9 +18618,10 @@ var init_pgSerializer = __esm({
18562
18618
  indexName2 = (tableName, columns) => {
18563
18619
  return `${tableName}_${columns.join("_")}_index`;
18564
18620
  };
18565
- generatePgSnapshot = (tables, enums, schemas, sequences, schemaFilter) => {
18566
- var _a, _b, _c, _d, _e, _f;
18621
+ generatePgSnapshot = (tables, enums, schemas, sequences, views, matViews, schemaFilter) => {
18622
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
18567
18623
  const result = {};
18624
+ const resultViews = {};
18568
18625
  const sequencesToReturn = {};
18569
18626
  const indexesInSchema = {};
18570
18627
  for (const table4 of tables) {
@@ -18863,6 +18920,149 @@ ${withStyle.errorWarning(
18863
18920
  } else {
18864
18921
  }
18865
18922
  }
18923
+ const combinedViews = [...views, ...matViews];
18924
+ for (const view2 of combinedViews) {
18925
+ let viewName;
18926
+ let schema5;
18927
+ let query;
18928
+ let selectedFields;
18929
+ let isExisting;
18930
+ let withOption;
18931
+ let tablespace;
18932
+ let using;
18933
+ let withNoData;
18934
+ let materialized = false;
18935
+ if ((0, import_drizzle_orm5.is)(view2, import_pg_core2.PgView)) {
18936
+ ({ name: viewName, schema: schema5, query, selectedFields, isExisting, with: withOption } = (0, import_pg_core2.getViewConfig)(view2));
18937
+ } else {
18938
+ ({ name: viewName, schema: schema5, query, selectedFields, isExisting, with: withOption, tablespace, using, withNoData } = (0, import_pg_core2.getMaterializedViewConfig)(
18939
+ view2
18940
+ ));
18941
+ materialized = true;
18942
+ }
18943
+ const viewSchema = schema5 ?? "public";
18944
+ const viewKey = `${viewSchema}.${viewName}`;
18945
+ const columnsObject = {};
18946
+ const uniqueConstraintObject = {};
18947
+ const existingView = resultViews[viewKey];
18948
+ if (typeof existingView !== "undefined") {
18949
+ console.log(
18950
+ `
18951
+ ${withStyle.errorWarning(
18952
+ `We've found duplicated view name across ${source_default.underline.blue(
18953
+ schema5 ?? "public"
18954
+ )} schema. Please rename your view`
18955
+ )}`
18956
+ );
18957
+ process.exit(1);
18958
+ }
18959
+ for (const key in selectedFields) {
18960
+ if ((0, import_drizzle_orm5.is)(selectedFields[key], import_pg_core2.PgColumn)) {
18961
+ const column7 = selectedFields[key];
18962
+ const notNull = column7.notNull;
18963
+ const primaryKey = column7.primary;
18964
+ const sqlTypeLowered = column7.getSQLType().toLowerCase();
18965
+ const typeSchema = (0, import_drizzle_orm5.is)(column7, import_pg_core2.PgEnumColumn) ? column7.enum.schema || "public" : void 0;
18966
+ const generated = column7.generated;
18967
+ const identity = column7.generatedIdentity;
18968
+ const increment = stringFromIdentityProperty((_g = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _g.increment) ?? "1";
18969
+ const minValue = stringFromIdentityProperty((_h = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _h.minValue) ?? (parseFloat(increment) < 0 ? minRangeForIdentityBasedOn(column7.columnType) : "1");
18970
+ const maxValue = stringFromIdentityProperty((_i = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _i.maxValue) ?? (parseFloat(increment) < 0 ? "-1" : maxRangeForIdentityBasedOn(column7.getSQLType()));
18971
+ const startWith = stringFromIdentityProperty((_j = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _j.startWith) ?? (parseFloat(increment) < 0 ? maxValue : minValue);
18972
+ const cache = stringFromIdentityProperty((_k = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _k.cache) ?? "1";
18973
+ const columnToSet = {
18974
+ name: column7.name,
18975
+ type: column7.getSQLType(),
18976
+ typeSchema,
18977
+ primaryKey,
18978
+ notNull,
18979
+ generated: generated ? {
18980
+ as: (0, import_drizzle_orm5.is)(generated.as, import_drizzle_orm5.SQL) ? dialect5.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect5.sqlToQuery(generated.as()).sql : generated.as,
18981
+ type: "stored"
18982
+ } : void 0,
18983
+ identity: identity ? {
18984
+ type: identity.type,
18985
+ name: identity.sequenceName ?? `${viewName}_${column7.name}_seq`,
18986
+ schema: schema5 ?? "public",
18987
+ increment,
18988
+ startWith,
18989
+ minValue,
18990
+ maxValue,
18991
+ cache,
18992
+ cycle: ((_l = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _l.cycle) ?? false
18993
+ } : void 0
18994
+ };
18995
+ if (column7.isUnique) {
18996
+ const existingUnique = uniqueConstraintObject[column7.uniqueName];
18997
+ if (typeof existingUnique !== "undefined") {
18998
+ console.log(
18999
+ `
19000
+ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
19001
+ viewName
19002
+ )} table.
19003
+ The unique constraint ${source_default.underline.blue(
19004
+ column7.uniqueName
19005
+ )} on the ${source_default.underline.blue(
19006
+ column7.name
19007
+ )} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
19008
+ existingUnique.columns.join(",")
19009
+ )} columns
19010
+ `)}`
19011
+ );
19012
+ process.exit(1);
19013
+ }
19014
+ uniqueConstraintObject[column7.uniqueName] = {
19015
+ name: column7.uniqueName,
19016
+ nullsNotDistinct: column7.uniqueType === "not distinct",
19017
+ columns: [columnToSet.name]
19018
+ };
19019
+ }
19020
+ if (column7.default !== void 0) {
19021
+ if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
19022
+ columnToSet.default = sqlToStr(column7.default);
19023
+ } else {
19024
+ if (typeof column7.default === "string") {
19025
+ columnToSet.default = `'${column7.default}'`;
19026
+ } else {
19027
+ if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
19028
+ columnToSet.default = `'${JSON.stringify(
19029
+ column7.default
19030
+ )}'::${sqlTypeLowered}`;
19031
+ } else if (column7.default instanceof Date) {
19032
+ if (sqlTypeLowered === "date") {
19033
+ columnToSet.default = `'${column7.default.toISOString().split("T")[0]}'`;
19034
+ } else if (sqlTypeLowered === "timestamp") {
19035
+ columnToSet.default = `'${column7.default.toISOString().replace("T", " ").slice(0, 23)}'`;
19036
+ } else {
19037
+ columnToSet.default = `'${column7.default.toISOString()}'`;
19038
+ }
19039
+ } else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column7.default)) {
19040
+ columnToSet.default = `'${buildArrayString(
19041
+ column7.default,
19042
+ sqlTypeLowered
19043
+ )}'`;
19044
+ } else {
19045
+ columnToSet.default = column7.default;
19046
+ }
19047
+ }
19048
+ }
19049
+ }
19050
+ columnsObject[column7.name] = columnToSet;
19051
+ }
19052
+ }
19053
+ resultViews[viewKey] = {
19054
+ columns: columnsObject,
19055
+ definition: isExisting ? void 0 : dialect5.sqlToQuery(query).sql,
19056
+ name: viewName,
19057
+ schema: viewSchema,
19058
+ isExisting,
19059
+ with: withOption,
19060
+ withNoData,
19061
+ materialized,
19062
+ tablespace,
19063
+ using
19064
+ };
19065
+ }
18866
19066
  const enumsToReturn = enums.reduce((map, obj) => {
18867
19067
  const enumSchema3 = obj.schema || "public";
18868
19068
  const key = `${enumSchema3}.${obj.enumName}`;
@@ -18889,6 +19089,7 @@ ${withStyle.errorWarning(
18889
19089
  enums: enumsToReturn,
18890
19090
  schemas: schemasObject,
18891
19091
  sequences: sequencesToReturn,
19092
+ views: resultViews,
18892
19093
  _meta: {
18893
19094
  schemas: {},
18894
19095
  tables: {},
@@ -18907,10 +19108,25 @@ ${withStyle.errorWarning(
18907
19108
  };
18908
19109
  fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
18909
19110
  const result = {};
19111
+ const views = {};
18910
19112
  const internals = { tables: {} };
18911
- const where = schemaFilters.map((t2) => `table_schema = '${t2}'`).join(" or ");
19113
+ const where = schemaFilters.map((t2) => `n.nspname = '${t2}'`).join(" or ");
18912
19114
  const allTables = await db.query(
18913
- `SELECT table_schema, table_name FROM information_schema.tables${where === "" ? "" : ` WHERE ${where}`};`
19115
+ `SELECT
19116
+ n.nspname AS table_schema,
19117
+ c.relname AS table_name,
19118
+ CASE
19119
+ WHEN c.relkind = 'r' THEN 'table'
19120
+ WHEN c.relkind = 'v' THEN 'view'
19121
+ WHEN c.relkind = 'm' THEN 'materialized_view'
19122
+ END AS type
19123
+ FROM
19124
+ pg_catalog.pg_class c
19125
+ JOIN
19126
+ pg_catalog.pg_namespace n ON n.oid = c.relnamespace
19127
+ WHERE
19128
+ c.relkind IN ('r', 'v', 'm')
19129
+ ${where === "" ? "" : ` AND ${where}`};`
18914
19130
  );
18915
19131
  const schemas = new Set(allTables.map((it) => it.table_schema));
18916
19132
  schemas.delete("public");
@@ -18988,7 +19204,7 @@ ${withStyle.errorWarning(
18988
19204
  progressCallback("enums", Object.keys(enumsToReturn).length, "done");
18989
19205
  }
18990
19206
  const sequencesInColumns = [];
18991
- const all = allTables.map((row) => {
19207
+ const all = allTables.filter((it) => it.type === "table").map((row) => {
18992
19208
  return new Promise(async (res, rej) => {
18993
19209
  var _a, _b, _c, _d, _e, _f;
18994
19210
  const tableName = row.table_name;
@@ -19397,6 +19613,336 @@ ${withStyle.errorWarning(
19397
19613
  }
19398
19614
  for await (const _2 of all) {
19399
19615
  }
19616
+ const allViews = allTables.filter((it) => it.type === "view" || it.type === "materialized_view").map((row) => {
19617
+ return new Promise(async (res, rej) => {
19618
+ var _a, _b, _c, _d;
19619
+ const viewName = row.table_name;
19620
+ if (!tablesFilter(viewName))
19621
+ return res("");
19622
+ tableCount += 1;
19623
+ const viewSchema = row.table_schema;
19624
+ try {
19625
+ const columnToReturn = {};
19626
+ const viewResponses = await db.query(`WITH view_columns AS (
19627
+ SELECT DISTINCT
19628
+ nv.nspname::information_schema.sql_identifier AS view_schema,
19629
+ v.relname::information_schema.sql_identifier AS view_name,
19630
+ nt.nspname::information_schema.sql_identifier AS table_schema,
19631
+ t.relname::information_schema.sql_identifier AS table_name,
19632
+ a.attname::information_schema.sql_identifier AS column_name
19633
+ FROM pg_namespace nv
19634
+ JOIN pg_class v ON nv.oid = v.relnamespace
19635
+ JOIN pg_depend dv ON v.oid = dv.refobjid
19636
+ JOIN pg_depend dt ON dv.objid = dt.objid
19637
+ JOIN pg_class t ON dt.refobjid = t.oid
19638
+ JOIN pg_namespace nt ON t.relnamespace = nt.oid
19639
+ JOIN pg_attribute a ON t.oid = a.attrelid
19640
+ WHERE (v.relkind = 'v'::"char" OR v.relkind = 'm'::"char")
19641
+ AND dv.refclassid = 'pg_class'::regclass::oid
19642
+ AND dv.classid = 'pg_rewrite'::regclass::oid
19643
+ AND dv.deptype = 'i'::"char"
19644
+ AND dv.objid = dt.objid
19645
+ AND dv.refobjid <> dt.refobjid
19646
+ AND dt.classid = 'pg_rewrite'::regclass::oid
19647
+ AND dt.refclassid = 'pg_class'::regclass::oid
19648
+ AND t.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])
19649
+ AND dt.refobjsubid = a.attnum
19650
+ AND pg_has_role(t.relowner, 'USAGE'::text)
19651
+ AND nv.nspname::information_schema.sql_identifier = '${viewSchema}'
19652
+ AND v.relname::information_schema.sql_identifier = '${viewName}'
19653
+ ),
19654
+ column_descriptions AS (
19655
+ SELECT DISTINCT
19656
+ a.attrelid::regclass::text AS table_name,
19657
+ a.attname AS column_name,
19658
+ c.is_nullable,
19659
+ a.attndims AS array_dimensions,
19660
+ CASE
19661
+ WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
19662
+ SELECT FROM pg_attrdef ad
19663
+ WHERE ad.adrelid = a.attrelid
19664
+ AND ad.adnum = a.attnum
19665
+ AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
19666
+ )
19667
+ THEN CASE a.atttypid
19668
+ WHEN 'int'::regtype THEN 'serial'
19669
+ WHEN 'int8'::regtype THEN 'bigserial'
19670
+ WHEN 'int2'::regtype THEN 'smallserial'
19671
+ END
19672
+ ELSE format_type(a.atttypid, a.atttypmod)
19673
+ END AS data_type,
19674
+ pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
19675
+ c.column_default,
19676
+ c.data_type AS additional_dt,
19677
+ c.udt_name AS enum_name,
19678
+ c.is_generated,
19679
+ c.generation_expression,
19680
+ c.is_identity,
19681
+ c.identity_generation,
19682
+ c.identity_start,
19683
+ c.identity_increment,
19684
+ c.identity_maximum,
19685
+ c.identity_minimum,
19686
+ c.identity_cycle
19687
+ FROM pg_attribute a
19688
+ JOIN information_schema.columns c ON c.column_name = a.attname
19689
+ JOIN pg_type t ON t.oid = a.atttypid
19690
+ LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
19691
+ WHERE a.attnum > 0
19692
+ AND NOT a.attisdropped
19693
+ ),
19694
+ table_constraints AS (
19695
+ SELECT DISTINCT ON (ccu.column_name)
19696
+ ccu.column_name,
19697
+ c.data_type,
19698
+ tc.constraint_type,
19699
+ tc.constraint_name,
19700
+ tc.constraint_schema,
19701
+ tc.table_name
19702
+ FROM information_schema.table_constraints tc
19703
+ JOIN information_schema.constraint_column_usage ccu USING (constraint_schema, constraint_name)
19704
+ JOIN information_schema.columns c ON c.table_schema = tc.constraint_schema
19705
+ AND tc.table_name = c.table_name
19706
+ AND ccu.column_name = c.column_name
19707
+ ),
19708
+ additional_column_info AS (
19709
+ SELECT DISTINCT
19710
+ a.attrelid::regclass::text AS table_name,
19711
+ a.attname AS column_name,
19712
+ is_nullable,
19713
+ a.attndims AS array_dimensions,
19714
+ CASE
19715
+ WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
19716
+ SELECT FROM pg_attrdef ad
19717
+ WHERE ad.adrelid = a.attrelid
19718
+ AND ad.adnum = a.attnum
19719
+ AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
19720
+ )
19721
+ THEN CASE a.atttypid
19722
+ WHEN 'int'::regtype THEN 'serial'
19723
+ WHEN 'int8'::regtype THEN 'bigserial'
19724
+ WHEN 'int2'::regtype THEN 'smallserial'
19725
+ END
19726
+ ELSE format_type(a.atttypid, a.atttypmod)
19727
+ END AS data_type,
19728
+ pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
19729
+ c.column_default,
19730
+ c.data_type AS additional_dt,
19731
+ c.udt_name AS enum_name,
19732
+ c.is_generated,
19733
+ generation_expression,
19734
+ is_identity,
19735
+ identity_generation,
19736
+ identity_start,
19737
+ identity_increment,
19738
+ identity_maximum,
19739
+ identity_minimum,
19740
+ identity_cycle
19741
+ FROM pg_attribute a
19742
+ JOIN information_schema.columns c ON c.column_name = a.attname
19743
+ LEFT JOIN pg_type t ON t.oid = a.atttypid
19744
+ LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
19745
+ WHERE a.attnum > 0
19746
+ AND NOT a.attisdropped
19747
+ )
19748
+ SELECT DISTINCT ON (vc.table_name, vc.column_name)
19749
+ vc.view_schema,
19750
+ vc.view_name,
19751
+ vc.table_schema,
19752
+ vc.table_name,
19753
+ vc.column_name,
19754
+ COALESCE(cd.data_type, aci.data_type) AS data_type,
19755
+ tc.constraint_type,
19756
+ tc.constraint_name,
19757
+ aci.is_nullable,
19758
+ aci.array_dimensions,
19759
+ aci.seq_name,
19760
+ aci.column_default,
19761
+ aci.additional_dt,
19762
+ aci.enum_name,
19763
+ aci.is_generated,
19764
+ aci.generation_expression,
19765
+ aci.is_identity,
19766
+ aci.identity_generation,
19767
+ aci.identity_start,
19768
+ aci.identity_increment,
19769
+ aci.identity_maximum,
19770
+ aci.identity_minimum,
19771
+ aci.identity_cycle
19772
+ FROM view_columns vc
19773
+ LEFT JOIN column_descriptions cd ON vc.table_name = cd.table_name AND vc.column_name = cd.column_name
19774
+ LEFT JOIN table_constraints tc ON vc.table_name = tc.table_name AND vc.column_name = tc.column_name
19775
+ LEFT JOIN additional_column_info aci ON vc.table_name = aci.table_name AND vc.column_name = aci.column_name
19776
+ ORDER BY vc.table_name, vc.column_name;`);
19777
+ for (const viewResponse of viewResponses) {
19778
+ const columnName = viewResponse.column_name;
19779
+ const columnAdditionalDT = viewResponse.additional_dt;
19780
+ const columnDimensions = viewResponse.array_dimensions;
19781
+ const enumType2 = viewResponse.enum_name;
19782
+ let columnType = viewResponse.data_type;
19783
+ const typeSchema = viewResponse.type_schema;
19784
+ const isGenerated = viewResponse.is_generated === "ALWAYS";
19785
+ const generationExpression = viewResponse.generation_expression;
19786
+ const isIdentity = viewResponse.is_identity === "YES";
19787
+ const identityGeneration = viewResponse.identity_generation === "ALWAYS" ? "always" : "byDefault";
19788
+ const identityStart = viewResponse.identity_start;
19789
+ const identityIncrement = viewResponse.identity_increment;
19790
+ const identityMaximum = viewResponse.identity_maximum;
19791
+ const identityMinimum = viewResponse.identity_minimum;
19792
+ const identityCycle = viewResponse.identity_cycle === "YES";
19793
+ const identityName = viewResponse.seq_name;
19794
+ const defaultValueRes = viewResponse.column_default;
19795
+ const primaryKey = viewResponse.constraint_type === "PRIMARY KEY";
19796
+ let columnTypeMapped = columnType;
19797
+ if (columnAdditionalDT === "ARRAY") {
19798
+ if (typeof internals.tables[viewName] === "undefined") {
19799
+ internals.tables[viewName] = {
19800
+ columns: {
19801
+ [columnName]: {
19802
+ isArray: true,
19803
+ dimensions: columnDimensions,
19804
+ rawType: columnTypeMapped.substring(
19805
+ 0,
19806
+ columnTypeMapped.length - 2
19807
+ )
19808
+ }
19809
+ }
19810
+ };
19811
+ } else {
19812
+ if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
19813
+ internals.tables[viewName].columns[columnName] = {
19814
+ isArray: true,
19815
+ dimensions: columnDimensions,
19816
+ rawType: columnTypeMapped.substring(
19817
+ 0,
19818
+ columnTypeMapped.length - 2
19819
+ )
19820
+ };
19821
+ }
19822
+ }
19823
+ }
19824
+ const defaultValue = defaultForColumn(
19825
+ viewResponse,
19826
+ internals,
19827
+ viewName
19828
+ );
19829
+ if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
19830
+ if (typeof internals.tables[viewName] === "undefined") {
19831
+ internals.tables[viewName] = {
19832
+ columns: {
19833
+ [columnName]: {
19834
+ isDefaultAnExpression: true
19835
+ }
19836
+ }
19837
+ };
19838
+ } else {
19839
+ if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
19840
+ internals.tables[viewName].columns[columnName] = {
19841
+ isDefaultAnExpression: true
19842
+ };
19843
+ } else {
19844
+ internals.tables[viewName].columns[columnName].isDefaultAnExpression = true;
19845
+ }
19846
+ }
19847
+ }
19848
+ const isSerial = columnType === "serial";
19849
+ if (columnTypeMapped.startsWith("numeric(")) {
19850
+ columnTypeMapped = columnTypeMapped.replace(",", ", ");
19851
+ }
19852
+ if (columnAdditionalDT === "ARRAY") {
19853
+ for (let i2 = 1; i2 < Number(columnDimensions); i2++) {
19854
+ columnTypeMapped += "[]";
19855
+ }
19856
+ }
19857
+ columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
19858
+ columnTypeMapped = trimChar(columnTypeMapped, '"');
19859
+ columnToReturn[columnName] = {
19860
+ name: columnName,
19861
+ type: (
19862
+ // filter vectors, but in future we should filter any extension that was installed by user
19863
+ columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
19864
+ ),
19865
+ typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
19866
+ primaryKey,
19867
+ notNull: viewResponse.is_nullable === "NO",
19868
+ generated: isGenerated ? { as: generationExpression, type: "stored" } : void 0,
19869
+ identity: isIdentity ? {
19870
+ type: identityGeneration,
19871
+ name: identityName,
19872
+ increment: stringFromDatabaseIdentityProperty(identityIncrement),
19873
+ minValue: stringFromDatabaseIdentityProperty(identityMinimum),
19874
+ maxValue: stringFromDatabaseIdentityProperty(identityMaximum),
19875
+ startWith: stringFromDatabaseIdentityProperty(identityStart),
19876
+ cache: ((_a = sequencesToReturn[identityName]) == null ? void 0 : _a.cache) ? (_b = sequencesToReturn[identityName]) == null ? void 0 : _b.cache : ((_c = sequencesToReturn[`${viewSchema}.${identityName}`]) == null ? void 0 : _c.cache) ? (_d = sequencesToReturn[`${viewSchema}.${identityName}`]) == null ? void 0 : _d.cache : void 0,
19877
+ cycle: identityCycle,
19878
+ schema: viewSchema
19879
+ } : void 0
19880
+ };
19881
+ if (identityName) {
19882
+ delete sequencesToReturn[`${viewSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
19883
+ delete sequencesToReturn[identityName];
19884
+ }
19885
+ if (!isSerial && typeof defaultValue !== "undefined") {
19886
+ columnToReturn[columnName].default = defaultValue;
19887
+ }
19888
+ }
19889
+ const [viewInfo] = await db.query(`
19890
+ SELECT
19891
+ c.relname AS view_name,
19892
+ n.nspname AS schema_name,
19893
+ pg_get_viewdef(c.oid, true) AS definition,
19894
+ ts.spcname AS tablespace_name,
19895
+ c.reloptions AS options,
19896
+ pg_tablespace_location(ts.oid) AS location
19897
+ FROM
19898
+ pg_class c
19899
+ JOIN
19900
+ pg_namespace n ON c.relnamespace = n.oid
19901
+ LEFT JOIN
19902
+ pg_tablespace ts ON c.reltablespace = ts.oid
19903
+ WHERE
19904
+ (c.relkind = 'm' OR c.relkind = 'v')
19905
+ AND n.nspname = '${viewSchema}'
19906
+ AND c.relname = '${viewName}';`);
19907
+ const resultWith = {};
19908
+ if (viewInfo.options) {
19909
+ viewInfo.options.forEach((pair) => {
19910
+ const splitted = pair.split("=");
19911
+ const key = splitted[0];
19912
+ const value = splitted[1];
19913
+ if (value === "true") {
19914
+ resultWith[key] = true;
19915
+ } else if (value === "false") {
19916
+ resultWith[key] = false;
19917
+ } else if (!isNaN(Number(value))) {
19918
+ resultWith[key] = Number(value);
19919
+ } else {
19920
+ resultWith[key] = value;
19921
+ }
19922
+ });
19923
+ }
19924
+ const definition = viewInfo.definition.replace(/\s+/g, " ").replace(";", "").trim();
19925
+ const withOption = Object.values(resultWith).length ? Object.fromEntries(Object.entries(resultWith).map(([key, value]) => [key.camelCase(), value])) : void 0;
19926
+ const materialized = row.type === "materialized_view";
19927
+ views[`${viewSchema}.${viewName}`] = {
19928
+ name: viewName,
19929
+ schema: viewSchema,
19930
+ columns: columnToReturn,
19931
+ isExisting: false,
19932
+ definition,
19933
+ materialized,
19934
+ with: withOption,
19935
+ tablespace: viewInfo.tablespace_name ?? void 0
19936
+ };
19937
+ } catch (e2) {
19938
+ rej(e2);
19939
+ return;
19940
+ }
19941
+ res("");
19942
+ });
19943
+ });
19944
+ for await (const _2 of allViews) {
19945
+ }
19400
19946
  if (progressCallback) {
19401
19947
  progressCallback("columns", columnsCount, "done");
19402
19948
  progressCallback("indexes", indexesCount, "done");
@@ -19410,6 +19956,7 @@ ${withStyle.errorWarning(
19410
19956
  enums: enumsToReturn,
19411
19957
  schemas: schemasObject,
19412
19958
  sequences: sequencesToReturn,
19959
+ views,
19413
19960
  _meta: {
19414
19961
  schemas: {},
19415
19962
  tables: {},
@@ -20052,10 +20599,10 @@ ${filenames.join("\n")}
20052
20599
  const filenames = prepareFilenames(path5);
20053
20600
  const { prepareFromPgImports: prepareFromPgImports2 } = await Promise.resolve().then(() => (init_pgImports(), pgImports_exports));
20054
20601
  const { generatePgSnapshot: generatePgSnapshot2 } = await Promise.resolve().then(() => (init_pgSerializer(), pgSerializer_exports));
20055
- const { tables, enums, schemas, sequences } = await prepareFromPgImports2(
20602
+ const { tables, enums, schemas, sequences, views, matViews } = await prepareFromPgImports2(
20056
20603
  filenames
20057
20604
  );
20058
- return generatePgSnapshot2(tables, enums, schemas, sequences, schemaFilter);
20605
+ return generatePgSnapshot2(tables, enums, schemas, sequences, views, matViews, schemaFilter);
20059
20606
  };
20060
20607
  serializeSQLite = async (path5) => {
20061
20608
  const filenames = prepareFilenames(path5);
@@ -22571,6 +23118,7 @@ function applyJsonDiff(json1, json2) {
22571
23118
  difference.tables = difference.tables || {};
22572
23119
  difference.enums = difference.enums || {};
22573
23120
  difference.sequences = difference.sequences || {};
23121
+ difference.views = difference.views || {};
22574
23122
  const schemaKeys = Object.keys(difference.schemas);
22575
23123
  for (let key of schemaKeys) {
22576
23124
  if (key.endsWith("__added") || key.endsWith("__deleted")) {
@@ -22626,6 +23174,71 @@ function applyJsonDiff(json1, json2) {
22626
23174
  const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
22627
23175
  return json2.sequences[it[0]];
22628
23176
  });
23177
+ const viewsEntries = Object.entries(difference.views);
23178
+ const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
23179
+ ([nameWithSchema, view2]) => {
23180
+ const deletedWithOption = view2.with__deleted;
23181
+ const addedWithOption = view2.with__added;
23182
+ const deletedWith = Object.fromEntries(
23183
+ Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__deleted")).map(([key, value]) => {
23184
+ return [key.replace("__deleted", ""), value];
23185
+ })
23186
+ );
23187
+ const addedWith = Object.fromEntries(
23188
+ Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__added")).map(([key, value]) => {
23189
+ return [key.replace("__added", ""), value];
23190
+ })
23191
+ );
23192
+ const alterWith = Object.fromEntries(
23193
+ Object.entries(view2.with || {}).filter(
23194
+ (it) => typeof it[1].__old !== "undefined" && typeof it[1].__new !== "undefined"
23195
+ ).map(
23196
+ (it) => {
23197
+ return [it[0], it[1].__new];
23198
+ }
23199
+ )
23200
+ );
23201
+ const alteredSchema = view2.schema;
23202
+ const alteredDefinition = view2.definition;
23203
+ const alteredExisting = view2.isExisting;
23204
+ const addedTablespace = view2.tablespace__added;
23205
+ const droppedTablespace = view2.tablespace__deleted;
23206
+ const alterTablespaceTo = view2.tablespace;
23207
+ let alteredTablespace;
23208
+ if (addedTablespace)
23209
+ alteredTablespace = { __new: addedTablespace, __old: "pg_default" };
23210
+ if (droppedTablespace)
23211
+ alteredTablespace = { __new: "pg_default", __old: droppedTablespace };
23212
+ if (alterTablespaceTo)
23213
+ alteredTablespace = alterTablespaceTo;
23214
+ const addedUsing = view2.using__added;
23215
+ const droppedUsing = view2.using__deleted;
23216
+ const alterUsingTo = view2.using;
23217
+ let alteredUsing;
23218
+ if (addedUsing)
23219
+ alteredUsing = { __new: addedUsing, __old: "heap" };
23220
+ if (droppedUsing)
23221
+ alteredUsing = { __new: "heap", __old: droppedUsing };
23222
+ if (alterUsingTo)
23223
+ alteredUsing = alterUsingTo;
23224
+ return {
23225
+ name: json2.views[nameWithSchema].name,
23226
+ schema: json2.views[nameWithSchema].schema,
23227
+ deletedWithOption,
23228
+ addedWithOption,
23229
+ alteredWith: {
23230
+ deletedWith: Object.keys(deletedWith).length ? deletedWith : void 0,
23231
+ addedWith: Object.keys(addedWith).length ? addedWith : void 0,
23232
+ alterWith: Object.keys(alterWith).length ? alterWith : void 0
23233
+ },
23234
+ alteredSchema,
23235
+ alteredDefinition,
23236
+ alteredExisting,
23237
+ alteredTablespace,
23238
+ alteredUsing
23239
+ };
23240
+ }
23241
+ );
22629
23242
  const alteredTablesWithColumns = Object.values(difference.tables).map(
22630
23243
  (table4) => {
22631
23244
  return findAlternationsInTable(table4);
@@ -22634,7 +23247,8 @@ function applyJsonDiff(json1, json2) {
22634
23247
  return {
22635
23248
  alteredTablesWithColumns,
22636
23249
  alteredEnums,
22637
- alteredSequences
23250
+ alteredSequences,
23251
+ alteredViews
22638
23252
  };
22639
23253
  }
22640
23254
  var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
@@ -23029,7 +23643,7 @@ function fromJson(statements, dialect7, action, json2) {
23029
23643
  }).filter((it) => it !== "");
23030
23644
  return result;
23031
23645
  }
23032
- 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;
23646
+ 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;
23033
23647
  var init_sqlgenerator = __esm({
23034
23648
  "src/sqlgenerator.ts"() {
23035
23649
  "use strict";
@@ -23245,6 +23859,118 @@ var init_sqlgenerator = __esm({
23245
23859
  return statement;
23246
23860
  }
23247
23861
  };
23862
+ PgCreateViewConvertor = class extends Convertor {
23863
+ can(statement, dialect7) {
23864
+ return statement.type === "create_view" && dialect7 === "postgresql";
23865
+ }
23866
+ convert(st) {
23867
+ const { definition, name: viewName, schema: schema5, with: withOption, materialized, withNoData, tablespace, using } = st;
23868
+ const name = schema5 ? `"${schema5}"."${viewName}"` : `"${viewName}"`;
23869
+ let statement = materialized ? `CREATE MATERIALIZED VIEW ${name}` : `CREATE VIEW ${name}`;
23870
+ if (using)
23871
+ statement += ` USING "${using}"`;
23872
+ const options = [];
23873
+ if (withOption) {
23874
+ statement += ` WITH (`;
23875
+ Object.entries(withOption).forEach(([key, value]) => {
23876
+ if (typeof value === "undefined")
23877
+ return;
23878
+ options.push(`${key.snake_case()} = ${value}`);
23879
+ });
23880
+ statement += options.join(", ");
23881
+ statement += `)`;
23882
+ }
23883
+ if (tablespace)
23884
+ statement += ` TABLESPACE ${tablespace}`;
23885
+ statement += ` AS (${definition})`;
23886
+ if (withNoData)
23887
+ statement += ` WITH NO DATA`;
23888
+ statement += `;`;
23889
+ return statement;
23890
+ }
23891
+ };
23892
+ PgDropViewConvertor = class extends Convertor {
23893
+ can(statement, dialect7) {
23894
+ return statement.type === "drop_view" && dialect7 === "postgresql";
23895
+ }
23896
+ convert(st) {
23897
+ const { name: viewName, schema: schema5, materialized } = st;
23898
+ const name = schema5 ? `"${schema5}"."${viewName}"` : `"${viewName}"`;
23899
+ return `DROP${materialized ? " MATERIALIZED" : ""} VIEW ${name};`;
23900
+ }
23901
+ };
23902
+ PgRenameViewConvertor = class extends Convertor {
23903
+ can(statement, dialect7) {
23904
+ return statement.type === "rename_view" && dialect7 === "postgresql";
23905
+ }
23906
+ convert(st) {
23907
+ const { nameFrom: from, nameTo: to, schema: schema5, materialized } = st;
23908
+ const nameFrom = `"${schema5}"."${from}"`;
23909
+ return `ALTER${materialized ? " MATERIALIZED" : ""} VIEW ${nameFrom} RENAME TO "${to}";`;
23910
+ }
23911
+ };
23912
+ PgAlterViewSchemaConvertor = class extends Convertor {
23913
+ can(statement, dialect7) {
23914
+ return statement.type === "alter_view_alter_schema" && dialect7 === "postgresql";
23915
+ }
23916
+ convert(st) {
23917
+ const { fromSchema, toSchema, name, materialized } = st;
23918
+ const statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${fromSchema}"."${name}" SET SCHEMA "${toSchema}";`;
23919
+ return statement;
23920
+ }
23921
+ };
23922
+ PgAlterViewAddWithOptionConvertor = class extends Convertor {
23923
+ can(statement, dialect7) {
23924
+ return statement.type === "alter_view_add_with_option" && dialect7 === "postgresql";
23925
+ }
23926
+ convert(st) {
23927
+ const { schema: schema5, with: withOption, name, materialized } = st;
23928
+ let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema5}"."${name}" SET (`;
23929
+ const options = [];
23930
+ Object.entries(withOption).forEach(([key, value]) => {
23931
+ options.push(`${key.snake_case()} = ${value}`);
23932
+ });
23933
+ statement += options.join(", ");
23934
+ statement += `);`;
23935
+ return statement;
23936
+ }
23937
+ };
23938
+ PgAlterViewDropWithOptionConvertor = class extends Convertor {
23939
+ can(statement, dialect7) {
23940
+ return statement.type === "alter_view_drop_with_option" && dialect7 === "postgresql";
23941
+ }
23942
+ convert(st) {
23943
+ const { schema: schema5, name, materialized, with: withOptions } = st;
23944
+ let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema5}"."${name}" RESET (`;
23945
+ const options = [];
23946
+ Object.entries(withOptions).forEach(([key, value]) => {
23947
+ options.push(`${key.snake_case()}`);
23948
+ });
23949
+ statement += options.join(", ");
23950
+ statement += ");";
23951
+ return statement;
23952
+ }
23953
+ };
23954
+ PgAlterViewAlterTablespaceConvertor = class extends Convertor {
23955
+ can(statement, dialect7) {
23956
+ return statement.type === "alter_view_alter_tablespace" && dialect7 === "postgresql";
23957
+ }
23958
+ convert(st) {
23959
+ const { schema: schema5, name, toTablespace } = st;
23960
+ const statement = `ALTER MATERIALIZED VIEW "${schema5}"."${name}" SET TABLESPACE ${toTablespace};`;
23961
+ return statement;
23962
+ }
23963
+ };
23964
+ PgAlterViewAlterUsingConvertor = class extends Convertor {
23965
+ can(statement, dialect7) {
23966
+ return statement.type === "alter_view_alter_using" && dialect7 === "postgresql";
23967
+ }
23968
+ convert(st) {
23969
+ const { schema: schema5, name, toUsing } = st;
23970
+ const statement = `ALTER MATERIALIZED VIEW "${schema5}"."${name}" SET ACCESS METHOD "${toUsing}";`;
23971
+ return statement;
23972
+ }
23973
+ };
23248
23974
  PgAlterTableAlterColumnSetGenerated = class extends Convertor {
23249
23975
  can(statement, dialect7) {
23250
23976
  return statement.type === "alter_table_alter_column_set_identity" && dialect7 === "postgresql";
@@ -24583,6 +25309,14 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24583
25309
  convertors.push(new SQLiteCreateTableConvertor());
24584
25310
  convertors.push(new SQLiteRecreateTableConvertor());
24585
25311
  convertors.push(new LibSQLRecreateTableConvertor());
25312
+ convertors.push(new PgCreateViewConvertor());
25313
+ convertors.push(new PgDropViewConvertor());
25314
+ convertors.push(new PgRenameViewConvertor());
25315
+ convertors.push(new PgAlterViewSchemaConvertor());
25316
+ convertors.push(new PgAlterViewAddWithOptionConvertor());
25317
+ convertors.push(new PgAlterViewDropWithOptionConvertor());
25318
+ convertors.push(new PgAlterViewAlterTablespaceConvertor());
25319
+ convertors.push(new PgAlterViewAlterUsingConvertor());
24586
25320
  convertors.push(new CreateTypeEnumConvertor());
24587
25321
  convertors.push(new CreatePgSequenceConvertor());
24588
25322
  convertors.push(new DropPgSequenceConvertor());
@@ -24917,7 +25651,7 @@ var init_sqlitePushUtils = __esm({
24917
25651
  });
24918
25652
 
24919
25653
  // src/jsonStatements.ts
24920
- 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;
25654
+ 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;
24921
25655
  var init_jsonStatements = __esm({
24922
25656
  "src/jsonStatements.ts"() {
24923
25657
  "use strict";
@@ -26256,6 +26990,81 @@ var init_jsonStatements = __esm({
26256
26990
  };
26257
26991
  });
26258
26992
  };
26993
+ preparePgCreateViewJson = (name, schema5, definition, materialized, withNoData = false, withOption, using, tablespace) => {
26994
+ return {
26995
+ type: "create_view",
26996
+ name,
26997
+ schema: schema5,
26998
+ definition,
26999
+ with: withOption,
27000
+ materialized,
27001
+ withNoData,
27002
+ using,
27003
+ tablespace
27004
+ };
27005
+ };
27006
+ preparePgDropViewJson = (name, schema5, materialized) => {
27007
+ return {
27008
+ type: "drop_view",
27009
+ name,
27010
+ schema: schema5,
27011
+ materialized
27012
+ };
27013
+ };
27014
+ preparePgRenameViewJson = (to, from, schema5, materialized) => {
27015
+ return {
27016
+ type: "rename_view",
27017
+ nameTo: to,
27018
+ nameFrom: from,
27019
+ schema: schema5,
27020
+ materialized
27021
+ };
27022
+ };
27023
+ preparePgAlterViewAlterSchemaJson = (to, from, name, materialized) => {
27024
+ return {
27025
+ type: "alter_view_alter_schema",
27026
+ fromSchema: from,
27027
+ toSchema: to,
27028
+ name,
27029
+ materialized
27030
+ };
27031
+ };
27032
+ preparePgAlterViewAddWithOptionJson = (name, schema5, materialized, withOption) => {
27033
+ return {
27034
+ type: "alter_view_add_with_option",
27035
+ name,
27036
+ schema: schema5,
27037
+ materialized,
27038
+ with: withOption
27039
+ };
27040
+ };
27041
+ preparePgAlterViewDropWithOptionJson = (name, schema5, materialized, withOption) => {
27042
+ return {
27043
+ type: "alter_view_drop_with_option",
27044
+ name,
27045
+ schema: schema5,
27046
+ materialized,
27047
+ with: withOption
27048
+ };
27049
+ };
27050
+ preparePgAlterViewAlterTablespaceJson = (name, schema5, materialized, to) => {
27051
+ return {
27052
+ type: "alter_view_alter_tablespace",
27053
+ name,
27054
+ schema: schema5,
27055
+ materialized,
27056
+ toTablespace: to
27057
+ };
27058
+ };
27059
+ preparePgAlterViewAlterUsingJson = (name, schema5, materialized, to) => {
27060
+ return {
27061
+ type: "alter_view_alter_using",
27062
+ name,
27063
+ schema: schema5,
27064
+ materialized,
27065
+ toUsing: to
27066
+ };
27067
+ };
26259
27068
  }
26260
27069
  });
26261
27070
 
@@ -26541,7 +27350,7 @@ var init_statementCombiner = __esm({
26541
27350
  });
26542
27351
 
26543
27352
  // src/snapshotsDiffer.ts
26544
- var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
27353
+ var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, alteredViewSchema, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
26545
27354
  var init_snapshotsDiffer = __esm({
26546
27355
  "src/snapshotsDiffer.ts"() {
26547
27356
  "use strict";
@@ -26689,10 +27498,42 @@ var init_snapshotsDiffer = __esm({
26689
27498
  })
26690
27499
  )
26691
27500
  }).strict();
27501
+ alteredViewSchema = objectType({
27502
+ name: stringType(),
27503
+ schema: stringType(),
27504
+ deletedWithOption: mergedViewWithOption.optional(),
27505
+ addedWithOption: mergedViewWithOption.optional(),
27506
+ alteredWith: objectType({
27507
+ addedWith: mergedViewWithOption.optional(),
27508
+ deletedWith: mergedViewWithOption.optional(),
27509
+ alterWith: mergedViewWithOption.optional()
27510
+ }).strict(),
27511
+ alteredSchema: objectType({
27512
+ __old: stringType(),
27513
+ __new: stringType()
27514
+ }).strict().optional(),
27515
+ alteredDefinition: objectType({
27516
+ __old: stringType(),
27517
+ __new: stringType()
27518
+ }).strict().optional(),
27519
+ alteredExisting: objectType({
27520
+ __old: booleanType(),
27521
+ __new: booleanType()
27522
+ }).strict().optional(),
27523
+ alteredTablespace: objectType({
27524
+ __old: stringType(),
27525
+ __new: stringType()
27526
+ }).strict().optional(),
27527
+ alteredUsing: objectType({
27528
+ __old: stringType(),
27529
+ __new: stringType()
27530
+ }).strict().optional()
27531
+ }).strict();
26692
27532
  diffResultScheme = objectType({
26693
27533
  alteredTablesWithColumns: alteredTableScheme.array(),
26694
27534
  alteredEnums: changedEnumSchema.array(),
26695
- alteredSequences: sequenceSquashed.array()
27535
+ alteredSequences: sequenceSquashed.array(),
27536
+ alteredViews: alteredViewSchema.array()
26696
27537
  }).strict();
26697
27538
  diffResultSchemeMysql = objectType({
26698
27539
  alteredTablesWithColumns: alteredTableScheme.array(),
@@ -26747,7 +27588,7 @@ var init_snapshotsDiffer = __esm({
26747
27588
  }
26748
27589
  return column7;
26749
27590
  };
26750
- applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
27591
+ applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
26751
27592
  const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);
26752
27593
  const {
26753
27594
  created: createdSchemas,
@@ -26975,7 +27816,40 @@ var init_snapshotsDiffer = __esm({
26975
27816
  return [tableKey2, tableValue];
26976
27817
  }
26977
27818
  );
26978
- const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
27819
+ const viewsDiff = diffSchemasOrTables(json1.views, json2.views);
27820
+ const {
27821
+ created: createdViews,
27822
+ deleted: deletedViews,
27823
+ renamed: renamedViews,
27824
+ moved: movedViews
27825
+ } = await viewsResolver2({
27826
+ created: viewsDiff.added,
27827
+ deleted: viewsDiff.deleted
27828
+ });
27829
+ const renamesViewDic = {};
27830
+ renamedViews.forEach((it) => {
27831
+ renamesViewDic[`${it.from.schema}.${it.from.name}`] = { to: it.to.name, from: it.from.name };
27832
+ });
27833
+ const movedViewDic = {};
27834
+ movedViews.forEach((it) => {
27835
+ movedViewDic[`${it.schemaFrom}.${it.name}`] = { to: it.schemaTo, from: it.schemaFrom };
27836
+ });
27837
+ const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
27838
+ viewsPatchedSnap1.views = mapEntries(
27839
+ viewsPatchedSnap1.views,
27840
+ (viewKey, viewValue) => {
27841
+ const rename = renamesViewDic[`${viewValue.schema}.${viewValue.name}`];
27842
+ const moved = movedViewDic[`${viewValue.schema}.${viewValue.name}`];
27843
+ if (rename) {
27844
+ viewValue.name = rename.to;
27845
+ viewKey = `${viewValue.schema}.${viewValue.name}`;
27846
+ }
27847
+ if (moved)
27848
+ viewKey = `${moved.to}.${viewValue.name}`;
27849
+ return [viewKey, viewValue];
27850
+ }
27851
+ );
27852
+ const diffResult = applyJsonDiff(viewsPatchedSnap1, json2);
26979
27853
  const typedResult = diffResultScheme.parse(diffResult);
26980
27854
  const jsonStatements = [];
26981
27855
  const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
@@ -27227,6 +28101,137 @@ var init_snapshotsDiffer = __esm({
27227
28101
  const createTables = createdTables.map((it) => {
27228
28102
  return preparePgCreateTableJson(it, curFull);
27229
28103
  });
28104
+ const createViews = [];
28105
+ const dropViews = [];
28106
+ const renameViews = [];
28107
+ const alterViews = [];
28108
+ createViews.push(
28109
+ ...createdViews.filter((it) => !it.isExisting).map((it) => {
28110
+ return preparePgCreateViewJson(
28111
+ it.name,
28112
+ it.schema,
28113
+ it.definition,
28114
+ it.materialized,
28115
+ it.withNoData,
28116
+ it.with,
28117
+ it.using,
28118
+ it.tablespace
28119
+ );
28120
+ })
28121
+ );
28122
+ dropViews.push(
28123
+ ...deletedViews.filter((it) => !it.isExisting).map((it) => {
28124
+ return preparePgDropViewJson(it.name, it.schema, it.materialized);
28125
+ })
28126
+ );
28127
+ renameViews.push(
28128
+ ...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
28129
+ return preparePgRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
28130
+ })
28131
+ );
28132
+ alterViews.push(
28133
+ ...movedViews.filter((it) => !json2.views[`${it.schemaTo}.${it.name}`].isExisting).map((it) => {
28134
+ return preparePgAlterViewAlterSchemaJson(
28135
+ it.schemaTo,
28136
+ it.schemaFrom,
28137
+ it.name,
28138
+ json2.views[`${it.schemaTo}.${it.name}`].materialized
28139
+ );
28140
+ })
28141
+ );
28142
+ const alteredViews = typedResult.alteredViews.filter((it) => !json2.views[`${it.schema}.${it.name}`].isExisting);
28143
+ for (const alteredView of alteredViews) {
28144
+ const viewKey = `${alteredView.schema}.${alteredView.name}`;
28145
+ const { materialized, with: withOption, definition, withNoData, using, tablespace } = json2.views[viewKey];
28146
+ if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
28147
+ dropViews.push(preparePgDropViewJson(alteredView.name, alteredView.schema, materialized));
28148
+ createViews.push(
28149
+ preparePgCreateViewJson(
28150
+ alteredView.name,
28151
+ alteredView.schema,
28152
+ definition,
28153
+ materialized,
28154
+ withNoData,
28155
+ withOption,
28156
+ using,
28157
+ tablespace
28158
+ )
28159
+ );
28160
+ continue;
28161
+ }
28162
+ if (alteredView.addedWithOption) {
28163
+ alterViews.push(
28164
+ preparePgAlterViewAddWithOptionJson(
28165
+ alteredView.name,
28166
+ alteredView.schema,
28167
+ materialized,
28168
+ alteredView.addedWithOption
28169
+ )
28170
+ );
28171
+ }
28172
+ if (alteredView.deletedWithOption) {
28173
+ alterViews.push(
28174
+ preparePgAlterViewDropWithOptionJson(
28175
+ alteredView.name,
28176
+ alteredView.schema,
28177
+ materialized,
28178
+ alteredView.deletedWithOption
28179
+ )
28180
+ );
28181
+ }
28182
+ if (alteredView.alteredWith) {
28183
+ if (alteredView.alteredWith.addedWith) {
28184
+ alterViews.push(
28185
+ preparePgAlterViewAddWithOptionJson(
28186
+ alteredView.name,
28187
+ alteredView.schema,
28188
+ materialized,
28189
+ alteredView.alteredWith.addedWith
28190
+ )
28191
+ );
28192
+ }
28193
+ if (alteredView.alteredWith.deletedWith) {
28194
+ alterViews.push(
28195
+ preparePgAlterViewDropWithOptionJson(
28196
+ alteredView.name,
28197
+ alteredView.schema,
28198
+ materialized,
28199
+ alteredView.alteredWith.deletedWith
28200
+ )
28201
+ );
28202
+ }
28203
+ if (alteredView.alteredWith.alterWith) {
28204
+ alterViews.push(
28205
+ preparePgAlterViewAddWithOptionJson(
28206
+ alteredView.name,
28207
+ alteredView.schema,
28208
+ materialized,
28209
+ alteredView.alteredWith.alterWith
28210
+ )
28211
+ );
28212
+ }
28213
+ }
28214
+ if (alteredView.alteredTablespace) {
28215
+ alterViews.push(
28216
+ preparePgAlterViewAlterTablespaceJson(
28217
+ alteredView.name,
28218
+ alteredView.schema,
28219
+ materialized,
28220
+ alteredView.alteredTablespace.__new
28221
+ )
28222
+ );
28223
+ }
28224
+ if (alteredView.alteredUsing) {
28225
+ alterViews.push(
28226
+ preparePgAlterViewAlterUsingJson(
28227
+ alteredView.name,
28228
+ alteredView.schema,
28229
+ materialized,
28230
+ alteredView.alteredUsing.__new
28231
+ )
28232
+ );
28233
+ }
28234
+ }
27230
28235
  jsonStatements.push(...createSchemas);
27231
28236
  jsonStatements.push(...renameSchemas);
27232
28237
  jsonStatements.push(...createEnums);
@@ -27238,6 +28243,9 @@ var init_snapshotsDiffer = __esm({
27238
28243
  jsonStatements.push(...renameSequences);
27239
28244
  jsonStatements.push(...jsonAlterSequences);
27240
28245
  jsonStatements.push(...createTables);
28246
+ jsonStatements.push(...dropViews);
28247
+ jsonStatements.push(...renameViews);
28248
+ jsonStatements.push(...alterViews);
27241
28249
  jsonStatements.push(...jsonDropTables);
27242
28250
  jsonStatements.push(...jsonSetTableSchemas);
27243
28251
  jsonStatements.push(...jsonRenameTables);
@@ -27257,6 +28265,7 @@ var init_snapshotsDiffer = __esm({
27257
28265
  jsonStatements.push(...jsonAlteredCompositePKs);
27258
28266
  jsonStatements.push(...jsonAddedUniqueConstraints);
27259
28267
  jsonStatements.push(...jsonAlteredUniqueConstraints);
28268
+ jsonStatements.push(...createViews);
27260
28269
  jsonStatements.push(...dropEnums);
27261
28270
  jsonStatements.push(...dropSequences);
27262
28271
  jsonStatements.push(...dropSchemas);
@@ -29535,9 +30544,10 @@ __export(migrate_exports, {
29535
30544
  schemasResolver: () => schemasResolver,
29536
30545
  sequencesResolver: () => sequencesResolver,
29537
30546
  tablesResolver: () => tablesResolver,
30547
+ viewsResolver: () => viewsResolver,
29538
30548
  writeResult: () => writeResult
29539
30549
  });
29540
- var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
30550
+ var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, viewsResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
29541
30551
  var init_migrate = __esm({
29542
30552
  "src/cli/commands/migrate.ts"() {
29543
30553
  "use strict";
@@ -29584,6 +30594,24 @@ var init_migrate = __esm({
29584
30594
  throw e2;
29585
30595
  }
29586
30596
  };
30597
+ viewsResolver = async (input) => {
30598
+ try {
30599
+ const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
30600
+ input.created,
30601
+ input.deleted,
30602
+ "view"
30603
+ );
30604
+ return {
30605
+ created,
30606
+ deleted,
30607
+ moved,
30608
+ renamed
30609
+ };
30610
+ } catch (e2) {
30611
+ console.error(e2);
30612
+ throw e2;
30613
+ }
30614
+ };
29587
30615
  sequencesResolver = async (input) => {
29588
30616
  try {
29589
30617
  const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
@@ -29672,6 +30700,7 @@ var init_migrate = __esm({
29672
30700
  sequencesResolver,
29673
30701
  tablesResolver,
29674
30702
  columnsResolver,
30703
+ viewsResolver,
29675
30704
  validatedPrev,
29676
30705
  validatedCur
29677
30706
  );
@@ -29706,6 +30735,7 @@ var init_migrate = __esm({
29706
30735
  sequencesResolver,
29707
30736
  tablesResolver,
29708
30737
  columnsResolver,
30738
+ viewsResolver,
29709
30739
  validatedPrev,
29710
30740
  validatedCur,
29711
30741
  "push"
@@ -34527,20 +35557,20 @@ var require_ponyfill_es2018 = __commonJS({
34527
35557
  ;
34528
35558
  ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
34529
35559
  }
34530
- respondWithNewView(view) {
35560
+ respondWithNewView(view2) {
34531
35561
  if (!IsReadableStreamBYOBRequest(this)) {
34532
35562
  throw byobRequestBrandCheckException("respondWithNewView");
34533
35563
  }
34534
- assertRequiredArgument(view, 1, "respondWithNewView");
34535
- if (!ArrayBuffer.isView(view)) {
35564
+ assertRequiredArgument(view2, 1, "respondWithNewView");
35565
+ if (!ArrayBuffer.isView(view2)) {
34536
35566
  throw new TypeError("You can only respond with array buffer views");
34537
35567
  }
34538
35568
  if (this._associatedReadableByteStreamController === void 0) {
34539
35569
  throw new TypeError("This BYOB request has been invalidated");
34540
35570
  }
34541
- if (IsDetachedBuffer(view.buffer))
35571
+ if (IsDetachedBuffer(view2.buffer))
34542
35572
  ;
34543
- ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
35573
+ ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view2);
34544
35574
  }
34545
35575
  }
34546
35576
  Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
@@ -34641,8 +35671,8 @@ var require_ponyfill_es2018 = __commonJS({
34641
35671
  const entry = this._queue.shift();
34642
35672
  this._queueTotalSize -= entry.byteLength;
34643
35673
  ReadableByteStreamControllerHandleQueueDrain(this);
34644
- const view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
34645
- readRequest._chunkSteps(view);
35674
+ const view2 = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
35675
+ readRequest._chunkSteps(view2);
34646
35676
  return;
34647
35677
  }
34648
35678
  const autoAllocateChunkSize = this._autoAllocateChunkSize;
@@ -34808,19 +35838,19 @@ var require_ponyfill_es2018 = __commonJS({
34808
35838
  }
34809
35839
  }
34810
35840
  }
34811
- function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest) {
35841
+ function ReadableByteStreamControllerPullInto(controller, view2, readIntoRequest) {
34812
35842
  const stream = controller._controlledReadableByteStream;
34813
35843
  let elementSize = 1;
34814
- if (view.constructor !== DataView) {
34815
- elementSize = view.constructor.BYTES_PER_ELEMENT;
35844
+ if (view2.constructor !== DataView) {
35845
+ elementSize = view2.constructor.BYTES_PER_ELEMENT;
34816
35846
  }
34817
- const ctor = view.constructor;
34818
- const buffer = TransferArrayBuffer(view.buffer);
35847
+ const ctor = view2.constructor;
35848
+ const buffer = TransferArrayBuffer(view2.buffer);
34819
35849
  const pullIntoDescriptor = {
34820
35850
  buffer,
34821
35851
  bufferByteLength: buffer.byteLength,
34822
- byteOffset: view.byteOffset,
34823
- byteLength: view.byteLength,
35852
+ byteOffset: view2.byteOffset,
35853
+ byteLength: view2.byteLength,
34824
35854
  bytesFilled: 0,
34825
35855
  elementSize,
34826
35856
  viewConstructor: ctor,
@@ -34988,9 +36018,9 @@ var require_ponyfill_es2018 = __commonJS({
34988
36018
  function ReadableByteStreamControllerGetBYOBRequest(controller) {
34989
36019
  if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
34990
36020
  const firstDescriptor = controller._pendingPullIntos.peek();
34991
- const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
36021
+ const view2 = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
34992
36022
  const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
34993
- SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
36023
+ SetUpReadableStreamBYOBRequest(byobRequest, controller, view2);
34994
36024
  controller._byobRequest = byobRequest;
34995
36025
  }
34996
36026
  return controller._byobRequest;
@@ -35023,29 +36053,29 @@ var require_ponyfill_es2018 = __commonJS({
35023
36053
  firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
35024
36054
  ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
35025
36055
  }
35026
- function ReadableByteStreamControllerRespondWithNewView(controller, view) {
36056
+ function ReadableByteStreamControllerRespondWithNewView(controller, view2) {
35027
36057
  const firstDescriptor = controller._pendingPullIntos.peek();
35028
36058
  const state = controller._controlledReadableByteStream._state;
35029
36059
  if (state === "closed") {
35030
- if (view.byteLength !== 0) {
36060
+ if (view2.byteLength !== 0) {
35031
36061
  throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
35032
36062
  }
35033
36063
  } else {
35034
- if (view.byteLength === 0) {
36064
+ if (view2.byteLength === 0) {
35035
36065
  throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
35036
36066
  }
35037
36067
  }
35038
- if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
36068
+ if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view2.byteOffset) {
35039
36069
  throw new RangeError("The region specified by view does not match byobRequest");
35040
36070
  }
35041
- if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
36071
+ if (firstDescriptor.bufferByteLength !== view2.buffer.byteLength) {
35042
36072
  throw new RangeError("The buffer of view has different capacity than byobRequest");
35043
36073
  }
35044
- if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
36074
+ if (firstDescriptor.bytesFilled + view2.byteLength > firstDescriptor.byteLength) {
35045
36075
  throw new RangeError("The region specified by view is larger than byobRequest");
35046
36076
  }
35047
- const viewByteLength = view.byteLength;
35048
- firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
36077
+ const viewByteLength = view2.byteLength;
36078
+ firstDescriptor.buffer = TransferArrayBuffer(view2.buffer);
35049
36079
  ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
35050
36080
  }
35051
36081
  function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
@@ -35091,9 +36121,9 @@ var require_ponyfill_es2018 = __commonJS({
35091
36121
  }
35092
36122
  SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
35093
36123
  }
35094
- function SetUpReadableStreamBYOBRequest(request, controller, view) {
36124
+ function SetUpReadableStreamBYOBRequest(request, controller, view2) {
35095
36125
  request._associatedReadableByteStreamController = controller;
35096
- request._view = view;
36126
+ request._view = view2;
35097
36127
  }
35098
36128
  function byobRequestBrandCheckException(name) {
35099
36129
  return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
@@ -35169,20 +36199,20 @@ var require_ponyfill_es2018 = __commonJS({
35169
36199
  *
35170
36200
  * If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
35171
36201
  */
35172
- read(view) {
36202
+ read(view2) {
35173
36203
  if (!IsReadableStreamBYOBReader(this)) {
35174
36204
  return promiseRejectedWith(byobReaderBrandCheckException("read"));
35175
36205
  }
35176
- if (!ArrayBuffer.isView(view)) {
36206
+ if (!ArrayBuffer.isView(view2)) {
35177
36207
  return promiseRejectedWith(new TypeError("view must be an array buffer view"));
35178
36208
  }
35179
- if (view.byteLength === 0) {
36209
+ if (view2.byteLength === 0) {
35180
36210
  return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
35181
36211
  }
35182
- if (view.buffer.byteLength === 0) {
36212
+ if (view2.buffer.byteLength === 0) {
35183
36213
  return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
35184
36214
  }
35185
- if (IsDetachedBuffer(view.buffer))
36215
+ if (IsDetachedBuffer(view2.buffer))
35186
36216
  ;
35187
36217
  if (this._ownerReadableStream === void 0) {
35188
36218
  return promiseRejectedWith(readerLockException("read from"));
@@ -35198,7 +36228,7 @@ var require_ponyfill_es2018 = __commonJS({
35198
36228
  _closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
35199
36229
  _errorSteps: (e2) => rejectPromise(e2)
35200
36230
  };
35201
- ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
36231
+ ReadableStreamBYOBReaderRead(this, view2, readIntoRequest);
35202
36232
  return promise;
35203
36233
  }
35204
36234
  /**
@@ -35244,13 +36274,13 @@ var require_ponyfill_es2018 = __commonJS({
35244
36274
  }
35245
36275
  return x2 instanceof ReadableStreamBYOBReader;
35246
36276
  }
35247
- function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
36277
+ function ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest) {
35248
36278
  const stream = reader._ownerReadableStream;
35249
36279
  stream._disturbed = true;
35250
36280
  if (stream._state === "errored") {
35251
36281
  readIntoRequest._errorSteps(stream._storedError);
35252
36282
  } else {
35253
- ReadableByteStreamControllerPullInto(stream._readableStreamController, view, readIntoRequest);
36283
+ ReadableByteStreamControllerPullInto(stream._readableStreamController, view2, readIntoRequest);
35254
36284
  }
35255
36285
  }
35256
36286
  function byobReaderBrandCheckException(name) {
@@ -36799,7 +37829,7 @@ var require_ponyfill_es2018 = __commonJS({
36799
37829
  };
36800
37830
  ReadableStreamDefaultReaderRead(reader, readRequest);
36801
37831
  }
36802
- function pullWithBYOBReader(view, forBranch2) {
37832
+ function pullWithBYOBReader(view2, forBranch2) {
36803
37833
  if (IsReadableStreamDefaultReader(reader)) {
36804
37834
  ReadableStreamReaderGenericRelease(reader);
36805
37835
  reader = AcquireReadableStreamBYOBReader(stream);
@@ -36865,7 +37895,7 @@ var require_ponyfill_es2018 = __commonJS({
36865
37895
  reading = false;
36866
37896
  }
36867
37897
  };
36868
- ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
37898
+ ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest);
36869
37899
  }
36870
37900
  function pull1Algorithm() {
36871
37901
  if (reading) {
@@ -51724,15 +52754,15 @@ var require_dist_cjs36 = __commonJS({
51724
52754
  throw new Error("Int64 buffers must be exactly 8 bytes");
51725
52755
  }
51726
52756
  }
51727
- static fromNumber(number3) {
51728
- if (number3 > 9223372036854776e3 || number3 < -9223372036854776e3) {
51729
- throw new Error(`${number3} is too large (or, if negative, too small) to represent as an Int64`);
52757
+ static fromNumber(number2) {
52758
+ if (number2 > 9223372036854776e3 || number2 < -9223372036854776e3) {
52759
+ throw new Error(`${number2} is too large (or, if negative, too small) to represent as an Int64`);
51730
52760
  }
51731
52761
  const bytes = new Uint8Array(8);
51732
- for (let i2 = 7, remaining = Math.abs(Math.round(number3)); i2 > -1 && remaining > 0; i2--, remaining /= 256) {
52762
+ for (let i2 = 7, remaining = Math.abs(Math.round(number2)); i2 > -1 && remaining > 0; i2--, remaining /= 256) {
51733
52763
  bytes[i2] = remaining;
51734
52764
  }
51735
- if (number3 < 0) {
52765
+ if (number2 < 0) {
51736
52766
  negate(bytes);
51737
52767
  }
51738
52768
  return new _Int642(bytes);
@@ -63163,16 +64193,16 @@ var require_map_stream = __commonJS({
63163
64193
  var writeQueue = {};
63164
64194
  stream.writable = true;
63165
64195
  stream.readable = true;
63166
- function queueData(data, number3) {
64196
+ function queueData(data, number2) {
63167
64197
  var nextToWrite = lastWritten + 1;
63168
- if (number3 === nextToWrite) {
64198
+ if (number2 === nextToWrite) {
63169
64199
  if (data !== void 0) {
63170
64200
  stream.emit.apply(stream, ["data", data]);
63171
64201
  }
63172
64202
  lastWritten++;
63173
64203
  nextToWrite++;
63174
64204
  } else {
63175
- writeQueue[number3] = data;
64205
+ writeQueue[number2] = data;
63176
64206
  }
63177
64207
  if (writeQueue.hasOwnProperty(nextToWrite)) {
63178
64208
  var dataToWrite = writeQueue[nextToWrite];
@@ -63187,21 +64217,21 @@ var require_map_stream = __commonJS({
63187
64217
  end();
63188
64218
  }
63189
64219
  }
63190
- function next(err2, data, number3) {
64220
+ function next(err2, data, number2) {
63191
64221
  if (destroyed)
63192
64222
  return;
63193
64223
  inNext = true;
63194
64224
  if (!err2 || self2.opts.failures) {
63195
- queueData(data, number3);
64225
+ queueData(data, number2);
63196
64226
  }
63197
64227
  if (err2) {
63198
64228
  stream.emit.apply(stream, [errorEventName, err2]);
63199
64229
  }
63200
64230
  inNext = false;
63201
64231
  }
63202
- function wrappedMapper(input, number3, callback) {
64232
+ function wrappedMapper(input, number2, callback) {
63203
64233
  return mapper.call(null, input, function(err2, data) {
63204
- callback(err2, data, number3);
64234
+ callback(err2, data, number2);
63205
64235
  });
63206
64236
  }
63207
64237
  stream.write = function(data) {
@@ -77033,7 +78063,7 @@ var init_selector_ui = __esm({
77033
78063
  });
77034
78064
 
77035
78065
  // src/cli/commands/libSqlPushUtils.ts
77036
- var getOldTableName3, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
78066
+ var getOldTableName2, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
77037
78067
  var init_libSqlPushUtils = __esm({
77038
78068
  "src/cli/commands/libSqlPushUtils.ts"() {
77039
78069
  "use strict";
@@ -77041,7 +78071,7 @@ var init_libSqlPushUtils = __esm({
77041
78071
  init_utils();
77042
78072
  init_sqliteSchema();
77043
78073
  init_sqlgenerator();
77044
- getOldTableName3 = (tableName, meta) => {
78074
+ getOldTableName2 = (tableName, meta) => {
77045
78075
  for (const key of Object.keys(meta.tables)) {
77046
78076
  const value = meta.tables[key];
77047
78077
  if (`"${tableName}"` === value) {
@@ -77196,7 +78226,7 @@ var init_libSqlPushUtils = __esm({
77196
78226
  } else if (statement.type === "recreate_table") {
77197
78227
  const tableName = statement.tableName;
77198
78228
  let dataLoss = false;
77199
- const oldTableName = getOldTableName3(tableName, meta);
78229
+ const oldTableName = getOldTableName2(tableName, meta);
77200
78230
  const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
77201
78231
  const currentColumnNames = Object.keys(json2.tables[tableName].columns);
77202
78232
  const { removedColumns, addedColumns } = findAddedAndRemoved(
@@ -80874,6 +81904,30 @@ var init_introspect_pg = __esm({
80874
81904
  },
80875
81905
  { pg: [] }
80876
81906
  );
81907
+ Object.values(schema5.views).forEach((it) => {
81908
+ if (it.schema && it.schema !== "public" && it.schema !== "") {
81909
+ imports.pg.push("pgSchema");
81910
+ } else if (it.schema === "public") {
81911
+ it.materialized ? imports.pg.push("pgMaterializedView") : imports.pg.push("pgView");
81912
+ }
81913
+ Object.values(it.columns).forEach(() => {
81914
+ const columnImports = Object.values(it.columns).map((col) => {
81915
+ let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
81916
+ patched = patched === "double precision" ? "doublePrecision" : patched;
81917
+ patched = patched.startsWith("varchar(") ? "varchar" : patched;
81918
+ patched = patched.startsWith("char(") ? "char" : patched;
81919
+ patched = patched.startsWith("numeric(") ? "numeric" : patched;
81920
+ patched = patched.startsWith("time(") ? "time" : patched;
81921
+ patched = patched.startsWith("timestamp(") ? "timestamp" : patched;
81922
+ patched = patched.startsWith("vector(") ? "vector" : patched;
81923
+ patched = patched.startsWith("geometry(") ? "geometry" : patched;
81924
+ return patched;
81925
+ }).filter((type) => {
81926
+ return pgImportsList.has(type);
81927
+ });
81928
+ imports.pg.push(...columnImports);
81929
+ });
81930
+ });
80877
81931
  Object.values(schema5.sequences).forEach((it) => {
80878
81932
  if (it.schema && it.schema !== "public" && it.schema !== "") {
80879
81933
  imports.pg.push("pgSchema");
@@ -80968,6 +82022,28 @@ var init_introspect_pg = __esm({
80968
82022
  statement += ");";
80969
82023
  return statement;
80970
82024
  });
82025
+ const viewsStatements = Object.values(schema5.views).map((it) => {
82026
+ const viewSchema = schemas[it.schema];
82027
+ const paramName = paramNameFor(it.name, viewSchema);
82028
+ const func = viewSchema ? it.materialized ? `${viewSchema}.materializedView` : `${viewSchema}.view` : it.materialized ? "pgMaterializedView" : "pgView";
82029
+ const withOption = it.with ?? "";
82030
+ const as = `sql\`${it.definition}\``;
82031
+ const tablespace = it.tablespace ?? "";
82032
+ const columns = createTableColumns3(
82033
+ "",
82034
+ Object.values(it.columns),
82035
+ [],
82036
+ enumTypes,
82037
+ schemas,
82038
+ casing2,
82039
+ schema5.internal
82040
+ );
82041
+ let statement = `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}", {${columns}})`;
82042
+ statement += tablespace ? `.tablespace("${tablespace}")` : "";
82043
+ statement += withOption ? `.with(${JSON.stringify(withOption)})` : "";
82044
+ statement += `.as(${as});`;
82045
+ return statement;
82046
+ }).join("\n\n");
80971
82047
  const uniquePgImports = ["pgTable", ...new Set(imports.pg)];
80972
82048
  const importsTs = `import { ${uniquePgImports.join(
80973
82049
  ", "
@@ -80980,6 +82056,8 @@ var init_introspect_pg = __esm({
80980
82056
  decalrations += sequencesStatements;
80981
82057
  decalrations += "\n";
80982
82058
  decalrations += tableStatements.join("\n\n");
82059
+ decalrations += "\n";
82060
+ decalrations += viewsStatements;
80983
82061
  const file = importsTs + decalrations;
80984
82062
  const schemaEntry = `
80985
82063
  {
@@ -81538,6 +82616,7 @@ var init_introspect = __esm({
81538
82616
  sequencesResolver,
81539
82617
  tablesResolver,
81540
82618
  columnsResolver,
82619
+ viewsResolver,
81541
82620
  dryPg,
81542
82621
  schema5
81543
82622
  );
@@ -85259,7 +86338,7 @@ init_utils2();
85259
86338
  var version2 = async () => {
85260
86339
  const { npmVersion } = await ormCoreVersions();
85261
86340
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
85262
- const envVersion = "0.25.0-d1da3b8";
86341
+ const envVersion = "0.25.0-f5f3e49";
85263
86342
  const kitVersion = envVersion ? `v${envVersion}` : "--";
85264
86343
  const versions = `drizzle-kit: ${kitVersion}
85265
86344
  ${ormVersion}`;