drizzle-kit 0.27.2 → 0.28.0-bc6e8f5

Sign up to get free protection for your applications and to get access to all the features.
package/api.mjs CHANGED
@@ -7530,30 +7530,11 @@ var init_mysqlSchema = __esm({
7530
7530
  }
7531
7531
  });
7532
7532
 
7533
- // src/extensions/vector.ts
7534
- var vectorOps;
7535
- var init_vector = __esm({
7536
- "src/extensions/vector.ts"() {
7537
- "use strict";
7538
- vectorOps = [
7539
- "vector_l2_ops",
7540
- "vector_ip_ops",
7541
- "vector_cosine_ops",
7542
- "vector_l1_ops",
7543
- "bit_hamming_ops",
7544
- "bit_jaccard_ops",
7545
- "halfvec_l2_ops",
7546
- "sparsevec_l2_ops"
7547
- ];
7548
- }
7549
- });
7550
-
7551
7533
  // src/serializer/pgSchema.ts
7552
7534
  var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, roleSchema, sequenceSquashed, columnV7, column2, checkConstraint2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, policy, policySquashed, viewWithOption, matViewWithOption, mergedViewWithOption, view2, 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;
7553
7535
  var init_pgSchema = __esm({
7554
7536
  "src/serializer/pgSchema.ts"() {
7555
7537
  "use strict";
7556
- init_vector();
7557
7538
  init_global();
7558
7539
  init_lib();
7559
7540
  indexV2 = objectType({
@@ -8013,7 +7994,7 @@ var init_pgSchema = __esm({
8013
7994
  squashIdx: (idx) => {
8014
7995
  index2.parse(idx);
8015
7996
  return `${idx.name};${idx.columns.map(
8016
- (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
7997
+ (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass ? c.opclass : ""}`
8017
7998
  ).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
8018
7999
  },
8019
8000
  unsquashIdx: (input) => {
@@ -8079,11 +8060,11 @@ var init_pgSchema = __esm({
8079
8060
  squashFK: (fk4) => {
8080
8061
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
8081
8062
  },
8082
- squashPolicy: (policy4) => {
8083
- return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.using}--${policy4.withCheck}--${policy4.on}`;
8063
+ squashPolicy: (policy3) => {
8064
+ return `${policy3.name}--${policy3.as}--${policy3.for}--${policy3.to?.join(",")}--${policy3.using}--${policy3.withCheck}--${policy3.on}`;
8084
8065
  },
8085
- unsquashPolicy: (policy4) => {
8086
- const splitted = policy4.split("--");
8066
+ unsquashPolicy: (policy3) => {
8067
+ const splitted = policy3.split("--");
8087
8068
  return {
8088
8069
  name: splitted[0],
8089
8070
  as: splitted[1],
@@ -8094,11 +8075,11 @@ var init_pgSchema = __esm({
8094
8075
  on: splitted[6] !== "undefined" ? splitted[6] : void 0
8095
8076
  };
8096
8077
  },
8097
- squashPolicyPush: (policy4) => {
8098
- return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.on}`;
8078
+ squashPolicyPush: (policy3) => {
8079
+ return `${policy3.name}--${policy3.as}--${policy3.for}--${policy3.to?.join(",")}--${policy3.on}`;
8099
8080
  },
8100
- unsquashPolicyPush: (policy4) => {
8101
- const splitted = policy4.split("--");
8081
+ unsquashPolicyPush: (policy3) => {
8082
+ const splitted = policy3.split("--");
8102
8083
  return {
8103
8084
  name: splitted[0],
8104
8085
  as: splitted[1],
@@ -8219,8 +8200,8 @@ var init_pgSchema = __esm({
8219
8200
  return PgSquasher.squashUnique(unq);
8220
8201
  }
8221
8202
  );
8222
- const squashedPolicies = mapValues(it[1].policies, (policy4) => {
8223
- return action === "push" ? PgSquasher.squashPolicyPush(policy4) : PgSquasher.squashPolicy(policy4);
8203
+ const squashedPolicies = mapValues(it[1].policies, (policy3) => {
8204
+ return action === "push" ? PgSquasher.squashPolicyPush(policy3) : PgSquasher.squashPolicy(policy3);
8224
8205
  });
8225
8206
  const squashedChecksContraints = mapValues(
8226
8207
  it[1].checkConstraints,
@@ -8608,6 +8589,9 @@ function findAddedAndRemoved(columnNames1, columnNames2) {
8608
8589
  const removedColumns = columnNames1.filter((it) => !set2.has(it));
8609
8590
  return { addedColumns, removedColumns };
8610
8591
  }
8592
+ function escapeSingleQuotes(str) {
8593
+ return str.replace(/'/g, "''");
8594
+ }
8611
8595
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8612
8596
  var init_utils = __esm({
8613
8597
  "src/utils.ts"() {
@@ -11943,7 +11927,7 @@ function fromJson(statements, dialect4, action, json22) {
11943
11927
  }).filter((it) => it !== "");
11944
11928
  return result;
11945
11929
  }
11946
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, 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;
11930
+ var parseType, Convertor, PgCreateRoleConvertor, PgDropRoleConvertor, PgRenameRoleConvertor, PgAlterRoleConvertor, PgCreatePolicyConvertor, PgDropPolicyConvertor, PgRenamePolicyConvertor, PgAlterPolicyConvertor, PgCreateIndPolicyConvertor, PgDropIndPolicyConvertor, PgRenameIndPolicyConvertor, PgAlterIndPolicyConvertor, PgEnableRlsConvertor, PgDisableRlsConvertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, 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;
11947
11931
  var init_sqlgenerator = __esm({
11948
11932
  "src/sqlgenerator.ts"() {
11949
11933
  "use strict";
@@ -11951,51 +11935,56 @@ var init_sqlgenerator = __esm({
11951
11935
  init_mysqlSchema();
11952
11936
  init_pgSchema();
11953
11937
  init_sqliteSchema();
11954
- pgNativeTypes = /* @__PURE__ */ new Set([
11955
- "uuid",
11956
- "smallint",
11957
- "integer",
11958
- "bigint",
11959
- "boolean",
11960
- "text",
11961
- "varchar",
11962
- "serial",
11963
- "bigserial",
11964
- "decimal",
11965
- "numeric",
11966
- "real",
11967
- "json",
11968
- "jsonb",
11969
- "time",
11970
- "time with time zone",
11971
- "time without time zone",
11972
- "time",
11973
- "timestamp",
11974
- "timestamp with time zone",
11975
- "timestamp without time zone",
11976
- "date",
11977
- "interval",
11978
- "bigint",
11979
- "bigserial",
11980
- "double precision",
11981
- "interval year",
11982
- "interval month",
11983
- "interval day",
11984
- "interval hour",
11985
- "interval minute",
11986
- "interval second",
11987
- "interval year to month",
11988
- "interval day to hour",
11989
- "interval day to minute",
11990
- "interval day to second",
11991
- "interval hour to minute",
11992
- "interval hour to second",
11993
- "interval minute to second"
11994
- ]);
11995
- isPgNativeType = (it) => {
11996
- if (pgNativeTypes.has(it)) return true;
11997
- const toCheck = it.replace(/ /g, "");
11998
- return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("doubleprecision[") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
11938
+ init_utils();
11939
+ parseType = (schemaPrefix, type) => {
11940
+ const pgNativeTypes = [
11941
+ "uuid",
11942
+ "smallint",
11943
+ "integer",
11944
+ "bigint",
11945
+ "boolean",
11946
+ "text",
11947
+ "varchar",
11948
+ "serial",
11949
+ "bigserial",
11950
+ "decimal",
11951
+ "numeric",
11952
+ "real",
11953
+ "json",
11954
+ "jsonb",
11955
+ "time",
11956
+ "time with time zone",
11957
+ "time without time zone",
11958
+ "time",
11959
+ "timestamp",
11960
+ "timestamp with time zone",
11961
+ "timestamp without time zone",
11962
+ "date",
11963
+ "interval",
11964
+ "bigint",
11965
+ "bigserial",
11966
+ "double precision",
11967
+ "interval year",
11968
+ "interval month",
11969
+ "interval day",
11970
+ "interval hour",
11971
+ "interval minute",
11972
+ "interval second",
11973
+ "interval year to month",
11974
+ "interval day to hour",
11975
+ "interval day to minute",
11976
+ "interval day to second",
11977
+ "interval hour to minute",
11978
+ "interval hour to second",
11979
+ "interval minute to second",
11980
+ "char",
11981
+ "vector",
11982
+ "geometry"
11983
+ ];
11984
+ const arrayDefinitionRegex = /\[\d*(?:\[\d*\])*\]/g;
11985
+ const arrayDefinition = (type.match(arrayDefinitionRegex) ?? []).join("");
11986
+ const withoutArrayDefinition = type.replace(arrayDefinitionRegex, "");
11987
+ return pgNativeTypes.some((it) => type.startsWith(it)) ? `${withoutArrayDefinition}${arrayDefinition}` : `${schemaPrefix}"${withoutArrayDefinition}"${arrayDefinition}`;
11999
11988
  };
12000
11989
  Convertor = class {
12001
11990
  };
@@ -12036,14 +12025,14 @@ var init_sqlgenerator = __esm({
12036
12025
  return statement.type === "create_policy" && dialect4 === "postgresql";
12037
12026
  }
12038
12027
  convert(statement) {
12039
- const policy4 = statement.data;
12028
+ const policy3 = statement.data;
12040
12029
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12041
- const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12042
- const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12043
- const policyToPart = policy4.to?.map(
12030
+ const usingPart = policy3.using ? ` USING (${policy3.using})` : "";
12031
+ const withCheckPart = policy3.withCheck ? ` WITH CHECK (${policy3.withCheck})` : "";
12032
+ const policyToPart = policy3.to?.map(
12044
12033
  (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12045
12034
  ).join(", ");
12046
- return `CREATE POLICY "${policy4.name}" ON ${tableNameWithSchema} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12035
+ return `CREATE POLICY "${policy3.name}" ON ${tableNameWithSchema} AS ${policy3.as?.toUpperCase()} FOR ${policy3.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12047
12036
  }
12048
12037
  };
12049
12038
  PgDropPolicyConvertor = class extends Convertor {
@@ -12051,9 +12040,9 @@ var init_sqlgenerator = __esm({
12051
12040
  return statement.type === "drop_policy" && dialect4 === "postgresql";
12052
12041
  }
12053
12042
  convert(statement) {
12054
- const policy4 = statement.data;
12043
+ const policy3 = statement.data;
12055
12044
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12056
- return `DROP POLICY "${policy4.name}" ON ${tableNameWithSchema} CASCADE;`;
12045
+ return `DROP POLICY "${policy3.name}" ON ${tableNameWithSchema} CASCADE;`;
12057
12046
  }
12058
12047
  };
12059
12048
  PgRenamePolicyConvertor = class extends Convertor {
@@ -12083,13 +12072,13 @@ var init_sqlgenerator = __esm({
12083
12072
  return statement.type === "create_ind_policy" && dialect4 === "postgresql";
12084
12073
  }
12085
12074
  convert(statement) {
12086
- const policy4 = statement.data;
12087
- const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12088
- const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12089
- const policyToPart = policy4.to?.map(
12075
+ const policy3 = statement.data;
12076
+ const usingPart = policy3.using ? ` USING (${policy3.using})` : "";
12077
+ const withCheckPart = policy3.withCheck ? ` WITH CHECK (${policy3.withCheck})` : "";
12078
+ const policyToPart = policy3.to?.map(
12090
12079
  (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12091
12080
  ).join(", ");
12092
- return `CREATE POLICY "${policy4.name}" ON ${policy4.on} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12081
+ return `CREATE POLICY "${policy3.name}" ON ${policy3.on} AS ${policy3.as?.toUpperCase()} FOR ${policy3.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12093
12082
  }
12094
12083
  };
12095
12084
  PgDropIndPolicyConvertor = class extends Convertor {
@@ -12097,8 +12086,8 @@ var init_sqlgenerator = __esm({
12097
12086
  return statement.type === "drop_ind_policy" && dialect4 === "postgresql";
12098
12087
  }
12099
12088
  convert(statement) {
12100
- const policy4 = statement.data;
12101
- return `DROP POLICY "${policy4.name}" ON ${policy4.on} CASCADE;`;
12089
+ const policy3 = statement.data;
12090
+ return `DROP POLICY "${policy3.name}" ON ${policy3.on} CASCADE;`;
12102
12091
  }
12103
12092
  };
12104
12093
  PgRenameIndPolicyConvertor = class extends Convertor {
@@ -12156,7 +12145,7 @@ var init_sqlgenerator = __esm({
12156
12145
  const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
12157
12146
  const uniqueConstraint4 = column4.isUnique ? ` CONSTRAINT "${column4.uniqueName}" UNIQUE${column4.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
12158
12147
  const schemaPrefix = column4.typeSchema && column4.typeSchema !== "public" ? `"${column4.typeSchema}".` : "";
12159
- const type = isPgNativeType(column4.type) ? column4.type : `${schemaPrefix}"${column4.type}"`;
12148
+ const type = parseType(schemaPrefix, column4.type);
12160
12149
  const generated = column4.generated;
12161
12150
  const generatedStatement = generated ? ` GENERATED ALWAYS AS (${generated?.as}) STORED` : "";
12162
12151
  const unsquashedIdentity = column4.identity ? PgSquasher.unsquashIdentity(column4.identity) : void 0;
@@ -12713,7 +12702,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12713
12702
  const { name: name2, values, schema: schema4 } = st;
12714
12703
  const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12715
12704
  let valuesStatement = "(";
12716
- valuesStatement += values.map((it) => `'${it}'`).join(", ");
12705
+ valuesStatement += values.map((it) => `'${escapeSingleQuotes(it)}'`).join(", ");
12717
12706
  valuesStatement += ")";
12718
12707
  let statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
12719
12708
  return statement;
@@ -12923,7 +12912,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12923
12912
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
12924
12913
  const defaultStatement = `${column4.default !== void 0 ? ` DEFAULT ${column4.default}` : ""}`;
12925
12914
  const schemaPrefix = column4.typeSchema && column4.typeSchema !== "public" ? `"${column4.typeSchema}".` : "";
12926
- const fixedType = isPgNativeType(column4.type) ? column4.type : `${schemaPrefix}"${column4.type}"`;
12915
+ const fixedType = parseType(schemaPrefix, column4.type);
12927
12916
  const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
12928
12917
  const unsquashedIdentity = identity ? PgSquasher.unsquashIdentity(identity) : void 0;
12929
12918
  const identityWithSchema = schema4 ? `"${schema4}"."${unsquashedIdentity?.name}"` : `"${unsquashedIdentity?.name}"`;
@@ -13493,8 +13482,9 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13493
13482
  statement.new
13494
13483
  );
13495
13484
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
13496
- return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT ${statement.oldConstraintName};
13497
- ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newConstraintName} PRIMARY KEY(${newColumns.join(",")});`;
13485
+ console.log(statement.oldConstraintName, statement.newConstraintName);
13486
+ return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.oldConstraintName}";
13487
+ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newConstraintName}" PRIMARY KEY("${newColumns.join('","')}");`;
13498
13488
  }
13499
13489
  };
13500
13490
  MySqlAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
@@ -15697,30 +15687,29 @@ var init_jsonStatements = __esm({
15697
15687
  };
15698
15688
  });
15699
15689
  };
15700
- prepareAddCompositePrimaryKeyPg = (tableName, schema4, pks, json22) => {
15690
+ prepareAddCompositePrimaryKeyPg = (tableName, schema4, pks) => {
15701
15691
  return Object.values(pks).map((it) => {
15702
- const unsquashed = PgSquasher.unsquashPK(it);
15703
15692
  return {
15704
15693
  type: "create_composite_pk",
15705
15694
  tableName,
15706
15695
  data: it,
15707
15696
  schema: schema4,
15708
- constraintName: json22.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[unsquashed.name].name
15697
+ constraintName: PgSquasher.unsquashPK(it).name
15709
15698
  };
15710
15699
  });
15711
15700
  };
15712
- prepareDeleteCompositePrimaryKeyPg = (tableName, schema4, pks, json1) => {
15701
+ prepareDeleteCompositePrimaryKeyPg = (tableName, schema4, pks) => {
15713
15702
  return Object.values(pks).map((it) => {
15714
15703
  return {
15715
15704
  type: "delete_composite_pk",
15716
15705
  tableName,
15717
15706
  data: it,
15718
15707
  schema: schema4,
15719
- constraintName: json1.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it).name].name
15708
+ constraintName: PgSquasher.unsquashPK(it).name
15720
15709
  };
15721
15710
  });
15722
15711
  };
15723
- prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks, json1, json22) => {
15712
+ prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks) => {
15724
15713
  return Object.values(pks).map((it) => {
15725
15714
  return {
15726
15715
  type: "alter_composite_pk",
@@ -15728,8 +15717,8 @@ var init_jsonStatements = __esm({
15728
15717
  old: it.__old,
15729
15718
  new: it.__new,
15730
15719
  schema: schema4,
15731
- oldConstraintName: json1.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it.__old).name].name,
15732
- newConstraintName: json22.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it.__new).name].name
15720
+ oldConstraintName: PgSquasher.unsquashPK(it.__old).name,
15721
+ newConstraintName: PgSquasher.unsquashPK(it.__new).name
15733
15722
  };
15734
15723
  });
15735
15724
  };
@@ -15784,18 +15773,19 @@ var init_jsonStatements = __esm({
15784
15773
  type: "create_composite_pk",
15785
15774
  tableName,
15786
15775
  data: it,
15787
- constraintName: json22.tables[tableName].compositePrimaryKeys[unsquashed.name].name
15776
+ constraintName: unsquashed.name
15788
15777
  });
15789
15778
  }
15790
15779
  return res;
15791
15780
  };
15792
15781
  prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
15793
15782
  return Object.values(pks).map((it) => {
15783
+ const unsquashed = MySqlSquasher.unsquashPK(it);
15794
15784
  return {
15795
15785
  type: "delete_composite_pk",
15796
15786
  tableName,
15797
15787
  data: it,
15798
- constraintName: json1.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it).name].name
15788
+ constraintName: unsquashed.name
15799
15789
  };
15800
15790
  });
15801
15791
  };
@@ -16826,12 +16816,12 @@ var init_snapshotsDiffer = __esm({
16826
16816
  (tableKey2, tableValue) => {
16827
16817
  const patchedPolicies = mapKeys(
16828
16818
  tableValue.policies,
16829
- (policyKey, policy4) => {
16819
+ (policyKey, policy3) => {
16830
16820
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
16831
16821
  const newName = columnChangeFor(policyKey, rens);
16832
- const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy4) : PgSquasher.unsquashPolicy(policy4);
16822
+ const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy3) : PgSquasher.unsquashPolicy(policy3);
16833
16823
  unsquashedPolicy.name = newName;
16834
- policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
16824
+ policy3 = PgSquasher.squashPolicy(unsquashedPolicy);
16835
16825
  return newName;
16836
16826
  }
16837
16827
  );
@@ -16971,17 +16961,17 @@ var init_snapshotsDiffer = __esm({
16971
16961
  const jsonDeletedCheckConstraints = [];
16972
16962
  const jsonCreatedCheckConstraints = [];
16973
16963
  for (let it of alteredTables) {
16974
- let addedColumns = [];
16964
+ let addedColumns;
16975
16965
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
16976
16966
  const addedPkColumns = it.addedCompositePKs[addedPkName];
16977
- addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
16967
+ addedColumns = PgSquasher.unsquashPK(addedPkColumns);
16978
16968
  }
16979
- let deletedColumns = [];
16969
+ let deletedColumns;
16980
16970
  for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
16981
16971
  const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
16982
- deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
16972
+ deletedColumns = PgSquasher.unsquashPK(deletedPkColumns);
16983
16973
  }
16984
- const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
16974
+ const doPerformDeleteAndCreate = JSON.stringify(addedColumns ?? {}) !== JSON.stringify(deletedColumns ?? {});
16985
16975
  let addedCompositePKs = [];
16986
16976
  let deletedCompositePKs = [];
16987
16977
  let alteredCompositePKs = [];
@@ -16989,22 +16979,18 @@ var init_snapshotsDiffer = __esm({
16989
16979
  addedCompositePKs = prepareAddCompositePrimaryKeyPg(
16990
16980
  it.name,
16991
16981
  it.schema,
16992
- it.addedCompositePKs,
16993
- curFull
16982
+ it.addedCompositePKs
16994
16983
  );
16995
16984
  deletedCompositePKs = prepareDeleteCompositePrimaryKeyPg(
16996
16985
  it.name,
16997
16986
  it.schema,
16998
- it.deletedCompositePKs,
16999
- prevFull
16987
+ it.deletedCompositePKs
17000
16988
  );
17001
16989
  }
17002
16990
  alteredCompositePKs = prepareAlterCompositePrimaryKeyPg(
17003
16991
  it.name,
17004
16992
  it.schema,
17005
- it.alteredCompositePKs,
17006
- prevFull,
17007
- curFull
16993
+ it.alteredCompositePKs
17008
16994
  );
17009
16995
  let addedUniqueConstraints = [];
17010
16996
  let deletedUniqueConstraints = [];
@@ -17123,9 +17109,9 @@ var init_snapshotsDiffer = __esm({
17123
17109
  );
17124
17110
  }
17125
17111
  typedResult.alteredPolicies.forEach(({ values }) => {
17126
- const policy4 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
17127
- const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json22.policies[policy4.name].values);
17128
- const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
17112
+ const policy3 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
17113
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy3.name].values) : PgSquasher.unsquashPolicy(json22.policies[policy3.name].values);
17114
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy3.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy3.name].values);
17129
17115
  if (newPolicy.as !== oldPolicy.as) {
17130
17116
  jsonDropIndPoliciesStatements.push(
17131
17117
  ...prepareDropIndPolicyJsons(
@@ -18003,9 +17989,9 @@ var init_snapshotsDiffer = __esm({
18003
17989
  jsonStatements.push(...jsonDeletedCompositePKs);
18004
17990
  jsonStatements.push(...jsonTableAlternations);
18005
17991
  jsonStatements.push(...jsonAddedCompositePKs);
17992
+ jsonStatements.push(...jsonAddColumnsStatemets);
18006
17993
  jsonStatements.push(...jsonAddedUniqueConstraints);
18007
17994
  jsonStatements.push(...jsonDeletedUniqueConstraints);
18008
- jsonStatements.push(...jsonAddColumnsStatemets);
18009
17995
  jsonStatements.push(...jsonCreateReferencesForCreatedTables);
18010
17996
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
18011
17997
  jsonStatements.push(...jsonCreatedCheckConstraints);
@@ -21140,7 +21126,7 @@ var version;
21140
21126
  var init_version = __esm({
21141
21127
  "../drizzle-orm/dist/version.js"() {
21142
21128
  "use strict";
21143
- version = "0.36.0";
21129
+ version = "0.36.1";
21144
21130
  }
21145
21131
  });
21146
21132
 
@@ -21426,7 +21412,10 @@ var init_sql = __esm({
21426
21412
  if (_config.invokeSource === "indexes") {
21427
21413
  return { sql: escapeName(columnName), params: [] };
21428
21414
  }
21429
- return { sql: escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName), params: [] };
21415
+ return {
21416
+ sql: chunk.table[IsAlias] || chunk.table[Table2.Symbol.Schema] === void 0 ? escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName) : escapeName(chunk.table[Table2.Symbol.Schema]) + "." + escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName),
21417
+ params: []
21418
+ };
21430
21419
  }
21431
21420
  if (is(chunk, View3)) {
21432
21421
  const schemaName = chunk[ViewBaseConfig].schema;
@@ -23759,7 +23748,7 @@ function vector(a, b) {
23759
23748
  return new PgVectorBuilder(name2, config);
23760
23749
  }
23761
23750
  var _a113, _b92, PgVectorBuilder, _a114, _b93, PgVector;
23762
- var init_vector2 = __esm({
23751
+ var init_vector = __esm({
23763
23752
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
23764
23753
  "use strict";
23765
23754
  init_entity();
@@ -23866,7 +23855,7 @@ var init_all = __esm({
23866
23855
  init_bit();
23867
23856
  init_halfvec();
23868
23857
  init_sparsevec();
23869
- init_vector2();
23858
+ init_vector();
23870
23859
  }
23871
23860
  });
23872
23861
 
@@ -24338,7 +24327,7 @@ function jaccardDistance(column4, value) {
24338
24327
  }
24339
24328
  return sql`${column4} <%> ${value}`;
24340
24329
  }
24341
- var init_vector3 = __esm({
24330
+ var init_vector2 = __esm({
24342
24331
  "../drizzle-orm/dist/sql/functions/vector.js"() {
24343
24332
  "use strict";
24344
24333
  init_sql();
@@ -24350,7 +24339,7 @@ var init_functions = __esm({
24350
24339
  "../drizzle-orm/dist/sql/functions/index.js"() {
24351
24340
  "use strict";
24352
24341
  init_aggregate();
24353
- init_vector3();
24342
+ init_vector2();
24354
24343
  }
24355
24344
  });
24356
24345
 
@@ -24580,7 +24569,7 @@ var init_columns = __esm({
24580
24569
  init_bit();
24581
24570
  init_halfvec();
24582
24571
  init_sparsevec();
24583
- init_vector2();
24572
+ init_vector();
24584
24573
  }
24585
24574
  });
24586
24575
 
@@ -28326,6 +28315,24 @@ var init_pg_core = __esm({
28326
28315
  }
28327
28316
  });
28328
28317
 
28318
+ // src/extensions/vector.ts
28319
+ var vectorOps;
28320
+ var init_vector3 = __esm({
28321
+ "src/extensions/vector.ts"() {
28322
+ "use strict";
28323
+ vectorOps = [
28324
+ "vector_l2_ops",
28325
+ "vector_ip_ops",
28326
+ "vector_cosine_ops",
28327
+ "vector_l1_ops",
28328
+ "bit_hamming_ops",
28329
+ "bit_jaccard_ops",
28330
+ "halfvec_l2_ops",
28331
+ "sparsevec_l2_ops"
28332
+ ];
28333
+ }
28334
+ });
28335
+
28329
28336
  // src/serializer/utils.ts
28330
28337
  function getColumnCasing(column4, casing2) {
28331
28338
  if (!column4.name) return "";
@@ -28431,7 +28438,7 @@ var init_pgSerializer = __esm({
28431
28438
  init_source();
28432
28439
  init_dist();
28433
28440
  init_pg_core();
28434
- init_vector();
28441
+ init_vector3();
28435
28442
  init_outputs();
28436
28443
  init_utils();
28437
28444
  init_utils6();
@@ -28535,7 +28542,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
28535
28542
  columnToSet.default = sqlToStr(column4.default, casing2);
28536
28543
  } else {
28537
28544
  if (typeof column4.default === "string") {
28538
- columnToSet.default = `'${column4.default}'`;
28545
+ columnToSet.default = `'${escapeSingleQuotes(column4.default)}'`;
28539
28546
  } else {
28540
28547
  if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
28541
28548
  columnToSet.default = `'${JSON.stringify(column4.default)}'::${sqlTypeLowered}`;
@@ -28717,17 +28724,17 @@ ${withStyle.errorWarning(
28717
28724
  with: value.config.with ?? {}
28718
28725
  };
28719
28726
  });
28720
- policies2.forEach((policy4) => {
28727
+ policies2.forEach((policy3) => {
28721
28728
  const mappedTo = [];
28722
- if (!policy4.to) {
28729
+ if (!policy3.to) {
28723
28730
  mappedTo.push("public");
28724
28731
  } else {
28725
- if (policy4.to && typeof policy4.to === "string") {
28726
- mappedTo.push(policy4.to);
28727
- } else if (policy4.to && is(policy4.to, PgRole)) {
28728
- mappedTo.push(policy4.to.name);
28729
- } else if (policy4.to && Array.isArray(policy4.to)) {
28730
- policy4.to.forEach((it) => {
28732
+ if (policy3.to && typeof policy3.to === "string") {
28733
+ mappedTo.push(policy3.to);
28734
+ } else if (policy3.to && is(policy3.to, PgRole)) {
28735
+ mappedTo.push(policy3.to.name);
28736
+ } else if (policy3.to && Array.isArray(policy3.to)) {
28737
+ policy3.to.forEach((it) => {
28731
28738
  if (typeof it === "string") {
28732
28739
  mappedTo.push(it);
28733
28740
  } else if (is(it, PgRole)) {
@@ -28736,24 +28743,24 @@ ${withStyle.errorWarning(
28736
28743
  });
28737
28744
  }
28738
28745
  }
28739
- if (policiesObject[policy4.name] !== void 0) {
28746
+ if (policiesObject[policy3.name] !== void 0) {
28740
28747
  console.log(
28741
28748
  `
28742
28749
  ${withStyle.errorWarning(
28743
28750
  `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28744
- policy4.name
28751
+ policy3.name
28745
28752
  )} name`
28746
28753
  )}`
28747
28754
  );
28748
28755
  process.exit(1);
28749
28756
  }
28750
- policiesObject[policy4.name] = {
28751
- name: policy4.name,
28752
- as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28753
- for: policy4.for?.toUpperCase() ?? "ALL",
28757
+ policiesObject[policy3.name] = {
28758
+ name: policy3.name,
28759
+ as: policy3.as?.toUpperCase() ?? "PERMISSIVE",
28760
+ for: policy3.for?.toUpperCase() ?? "ALL",
28754
28761
  to: mappedTo.sort(),
28755
- using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28756
- withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28762
+ using: is(policy3.using, SQL) ? dialect4.sqlToQuery(policy3.using).sql : void 0,
28763
+ withCheck: is(policy3.withCheck, SQL) ? dialect4.sqlToQuery(policy3.withCheck).sql : void 0
28757
28764
  };
28758
28765
  });
28759
28766
  checks.forEach((check) => {
@@ -28797,28 +28804,28 @@ ${withStyle.errorWarning(
28797
28804
  isRLSEnabled: enableRLS
28798
28805
  };
28799
28806
  }
28800
- for (const policy4 of policies) {
28801
- if (!policy4._linkedTable) {
28807
+ for (const policy3 of policies) {
28808
+ if (!policy3._linkedTable) {
28802
28809
  console.log(
28803
28810
  `
28804
28811
  ${withStyle.errorWarning(
28805
- `"Policy ${policy4.name} was skipped because it was not linked to any table. You should either include the policy in a table or use .link() on the policy to link it to any table you have. For more information, please check:`
28812
+ `"Policy ${policy3.name} was skipped because it was not linked to any table. You should either include the policy in a table or use .link() on the policy to link it to any table you have. For more information, please check:`
28806
28813
  )}`
28807
28814
  );
28808
28815
  continue;
28809
28816
  }
28810
- const tableConfig = getTableConfig(policy4._linkedTable);
28817
+ const tableConfig = getTableConfig(policy3._linkedTable);
28811
28818
  const tableKey2 = `${tableConfig.schema ?? "public"}.${tableConfig.name}`;
28812
28819
  const mappedTo = [];
28813
- if (!policy4.to) {
28820
+ if (!policy3.to) {
28814
28821
  mappedTo.push("public");
28815
28822
  } else {
28816
- if (policy4.to && typeof policy4.to === "string") {
28817
- mappedTo.push(policy4.to);
28818
- } else if (policy4.to && is(policy4.to, PgRole)) {
28819
- mappedTo.push(policy4.to.name);
28820
- } else if (policy4.to && Array.isArray(policy4.to)) {
28821
- policy4.to.forEach((it) => {
28823
+ if (policy3.to && typeof policy3.to === "string") {
28824
+ mappedTo.push(policy3.to);
28825
+ } else if (policy3.to && is(policy3.to, PgRole)) {
28826
+ mappedTo.push(policy3.to.name);
28827
+ } else if (policy3.to && Array.isArray(policy3.to)) {
28828
+ policy3.to.forEach((it) => {
28822
28829
  if (typeof it === "string") {
28823
28830
  mappedTo.push(it);
28824
28831
  } else if (is(it, PgRole)) {
@@ -28827,29 +28834,29 @@ ${withStyle.errorWarning(
28827
28834
  });
28828
28835
  }
28829
28836
  }
28830
- if (result[tableKey2]?.policies[policy4.name] !== void 0 || policiesToReturn[policy4.name] !== void 0) {
28837
+ if (result[tableKey2]?.policies[policy3.name] !== void 0 || policiesToReturn[policy3.name] !== void 0) {
28831
28838
  console.log(
28832
28839
  `
28833
28840
  ${withStyle.errorWarning(
28834
28841
  `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28835
- policy4.name
28842
+ policy3.name
28836
28843
  )} name`
28837
28844
  )}`
28838
28845
  );
28839
28846
  process.exit(1);
28840
28847
  }
28841
28848
  const mappedPolicy = {
28842
- name: policy4.name,
28843
- as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28844
- for: policy4.for?.toUpperCase() ?? "ALL",
28849
+ name: policy3.name,
28850
+ as: policy3.as?.toUpperCase() ?? "PERMISSIVE",
28851
+ for: policy3.for?.toUpperCase() ?? "ALL",
28845
28852
  to: mappedTo.sort(),
28846
- using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28847
- withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28853
+ using: is(policy3.using, SQL) ? dialect4.sqlToQuery(policy3.using).sql : void 0,
28854
+ withCheck: is(policy3.withCheck, SQL) ? dialect4.sqlToQuery(policy3.withCheck).sql : void 0
28848
28855
  };
28849
28856
  if (result[tableKey2]) {
28850
- result[tableKey2].policies[policy4.name] = mappedPolicy;
28857
+ result[tableKey2].policies[policy3.name] = mappedPolicy;
28851
28858
  } else {
28852
- policiesToReturn[policy4.name] = {
28859
+ policiesToReturn[policy3.name] = {
28853
28860
  ...mappedPolicy,
28854
28861
  schema: tableConfig.schema ?? "public",
28855
28862
  on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
@@ -29820,10 +29827,7 @@ WHERE
29820
29827
  defaultForColumn = (column4, internals, tableName) => {
29821
29828
  const columnName = column4.column_name;
29822
29829
  const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
29823
- if (column4.column_default === null) {
29824
- return void 0;
29825
- }
29826
- if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
29830
+ if (column4.column_default === null || column4.column_default === void 0 || column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
29827
29831
  return void 0;
29828
29832
  }
29829
29833
  if (column4.column_default.endsWith("[]")) {
@@ -30251,7 +30255,7 @@ var init_blob = __esm({
30251
30255
  return "blob";
30252
30256
  }
30253
30257
  mapFromDriverValue(value) {
30254
- return BigInt(value.toString());
30258
+ return BigInt(Buffer.isBuffer(value) ? value.toString() : String.fromCodePoint(...value));
30255
30259
  }
30256
30260
  mapToDriverValue(value) {
30257
30261
  return Buffer.from(value.toString());
@@ -30276,7 +30280,7 @@ var init_blob = __esm({
30276
30280
  return "blob";
30277
30281
  }
30278
30282
  mapFromDriverValue(value) {
30279
- return JSON.parse(value.toString());
30283
+ return JSON.parse(Buffer.isBuffer(value) ? value.toString() : String.fromCodePoint(...value));
30280
30284
  }
30281
30285
  mapToDriverValue(value) {
30282
30286
  return Buffer.from(JSON.stringify(value));
@@ -33502,6 +33506,7 @@ var init_sqliteSerializer = __esm({
33502
33506
  init_dist();
33503
33507
  init_sqlite_core();
33504
33508
  init_outputs();
33509
+ init_utils();
33505
33510
  init_utils6();
33506
33511
  generateSqliteSnapshot = (tables, views, casing2) => {
33507
33512
  const dialect4 = new SQLiteSyncDialect({ casing: casing2 });
@@ -33545,7 +33550,7 @@ var init_sqliteSerializer = __esm({
33545
33550
  if (is(column4.default, SQL)) {
33546
33551
  columnToSet.default = sqlToStr(column4.default, casing2);
33547
33552
  } else {
33548
- columnToSet.default = typeof column4.default === "string" ? `'${column4.default}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
33553
+ columnToSet.default = typeof column4.default === "string" ? `'${escapeSingleQuotes(column4.default)}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
33549
33554
  }
33550
33555
  }
33551
33556
  columnsObject[name2] = columnToSet;
@@ -34096,6 +34101,25 @@ WHERE
34096
34101
  }
34097
34102
  });
34098
34103
 
34104
+ // src/extensions/getTablesFilterByExtensions.ts
34105
+ var getTablesFilterByExtensions;
34106
+ var init_getTablesFilterByExtensions = __esm({
34107
+ "src/extensions/getTablesFilterByExtensions.ts"() {
34108
+ "use strict";
34109
+ getTablesFilterByExtensions = ({
34110
+ extensionsFilters,
34111
+ dialect: dialect4
34112
+ }) => {
34113
+ if (extensionsFilters) {
34114
+ if (extensionsFilters.includes("postgis") && dialect4 === "postgresql") {
34115
+ return ["!geography_columns", "!geometry_columns", "!spatial_ref_sys"];
34116
+ }
34117
+ }
34118
+ return [];
34119
+ };
34120
+ }
34121
+ });
34122
+
34099
34123
  // ../drizzle-orm/dist/mysql-core/alias.js
34100
34124
  var init_alias4 = __esm({
34101
34125
  "../drizzle-orm/dist/mysql-core/alias.js"() {
@@ -34718,7 +34742,7 @@ var init_datetime = __esm({
34718
34742
  // ../drizzle-orm/dist/mysql-core/columns/decimal.js
34719
34743
  function decimal(a, b = {}) {
34720
34744
  const { name: name2, config } = getColumnNameAndConfig(a, b);
34721
- return new MySqlDecimalBuilder(name2, config.precision, config.scale);
34745
+ return new MySqlDecimalBuilder(name2, config);
34722
34746
  }
34723
34747
  var _a259, _b182, MySqlDecimalBuilder, _a260, _b183, MySqlDecimal;
34724
34748
  var init_decimal = __esm({
@@ -34728,10 +34752,11 @@ var init_decimal = __esm({
34728
34752
  init_utils2();
34729
34753
  init_common4();
34730
34754
  MySqlDecimalBuilder = class extends (_b182 = MySqlColumnBuilderWithAutoIncrement, _a259 = entityKind, _b182) {
34731
- constructor(name2, precision, scale) {
34755
+ constructor(name2, config) {
34732
34756
  super(name2, "string", "MySqlDecimal");
34733
- this.config.precision = precision;
34734
- this.config.scale = scale;
34757
+ this.config.precision = config?.precision;
34758
+ this.config.scale = config?.scale;
34759
+ this.config.unsigned = config?.unsigned;
34735
34760
  }
34736
34761
  /** @internal */
34737
34762
  build(table4) {
@@ -34747,15 +34772,19 @@ var init_decimal = __esm({
34747
34772
  super(...arguments);
34748
34773
  __publicField(this, "precision", this.config.precision);
34749
34774
  __publicField(this, "scale", this.config.scale);
34775
+ __publicField(this, "unsigned", this.config.unsigned);
34750
34776
  }
34751
34777
  getSQLType() {
34778
+ let type = "";
34752
34779
  if (this.precision !== void 0 && this.scale !== void 0) {
34753
- return `decimal(${this.precision},${this.scale})`;
34780
+ type += `decimal(${this.precision},${this.scale})`;
34754
34781
  } else if (this.precision === void 0) {
34755
- return "decimal";
34782
+ type += "decimal";
34756
34783
  } else {
34757
- return `decimal(${this.precision})`;
34784
+ type += `decimal(${this.precision})`;
34758
34785
  }
34786
+ type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
34787
+ return this.unsigned ? `${type} unsigned` : type;
34759
34788
  }
34760
34789
  };
34761
34790
  __publicField(MySqlDecimal, _a260, "MySqlDecimal");
@@ -34779,6 +34808,7 @@ var init_double = __esm({
34779
34808
  super(name2, "number", "MySqlDouble");
34780
34809
  this.config.precision = config?.precision;
34781
34810
  this.config.scale = config?.scale;
34811
+ this.config.unsigned = config?.unsigned;
34782
34812
  }
34783
34813
  /** @internal */
34784
34814
  build(table4) {
@@ -34791,15 +34821,18 @@ var init_double = __esm({
34791
34821
  super(...arguments);
34792
34822
  __publicField(this, "precision", this.config.precision);
34793
34823
  __publicField(this, "scale", this.config.scale);
34824
+ __publicField(this, "unsigned", this.config.unsigned);
34794
34825
  }
34795
34826
  getSQLType() {
34827
+ let type = "";
34796
34828
  if (this.precision !== void 0 && this.scale !== void 0) {
34797
- return `double(${this.precision},${this.scale})`;
34829
+ type += `double(${this.precision},${this.scale})`;
34798
34830
  } else if (this.precision === void 0) {
34799
- return "double";
34831
+ type += "double";
34800
34832
  } else {
34801
- return `double(${this.precision})`;
34833
+ type += `double(${this.precision})`;
34802
34834
  }
34835
+ return this.unsigned ? `${type} unsigned` : type;
34803
34836
  }
34804
34837
  };
34805
34838
  __publicField(MySqlDouble, _a262, "MySqlDouble");
@@ -34849,18 +34882,23 @@ var init_enum2 = __esm({
34849
34882
  });
34850
34883
 
34851
34884
  // ../drizzle-orm/dist/mysql-core/columns/float.js
34852
- function float(name2) {
34853
- return new MySqlFloatBuilder(name2 ?? "");
34885
+ function float(a, b) {
34886
+ const { name: name2, config } = getColumnNameAndConfig(a, b);
34887
+ return new MySqlFloatBuilder(name2, config);
34854
34888
  }
34855
34889
  var _a265, _b188, MySqlFloatBuilder, _a266, _b189, MySqlFloat;
34856
34890
  var init_float = __esm({
34857
34891
  "../drizzle-orm/dist/mysql-core/columns/float.js"() {
34858
34892
  "use strict";
34859
34893
  init_entity();
34894
+ init_utils2();
34860
34895
  init_common4();
34861
34896
  MySqlFloatBuilder = class extends (_b188 = MySqlColumnBuilderWithAutoIncrement, _a265 = entityKind, _b188) {
34862
- constructor(name2) {
34897
+ constructor(name2, config) {
34863
34898
  super(name2, "number", "MySqlFloat");
34899
+ this.config.precision = config?.precision;
34900
+ this.config.scale = config?.scale;
34901
+ this.config.unsigned = config?.unsigned;
34864
34902
  }
34865
34903
  /** @internal */
34866
34904
  build(table4) {
@@ -34869,8 +34907,22 @@ var init_float = __esm({
34869
34907
  };
34870
34908
  __publicField(MySqlFloatBuilder, _a265, "MySqlFloatBuilder");
34871
34909
  MySqlFloat = class extends (_b189 = MySqlColumnWithAutoIncrement, _a266 = entityKind, _b189) {
34910
+ constructor() {
34911
+ super(...arguments);
34912
+ __publicField(this, "precision", this.config.precision);
34913
+ __publicField(this, "scale", this.config.scale);
34914
+ __publicField(this, "unsigned", this.config.unsigned);
34915
+ }
34872
34916
  getSQLType() {
34873
- return "float";
34917
+ let type = "";
34918
+ if (this.precision !== void 0 && this.scale !== void 0) {
34919
+ type += `float(${this.precision},${this.scale})`;
34920
+ } else if (this.precision === void 0) {
34921
+ type += "float";
34922
+ } else {
34923
+ type += `float(${this.precision})`;
34924
+ }
34925
+ return this.unsigned ? `${type} unsigned` : type;
34874
34926
  }
34875
34927
  };
34876
34928
  __publicField(MySqlFloat, _a266, "MySqlFloat");
@@ -35726,7 +35778,7 @@ var init_insert3 = __esm({
35726
35778
  returning.push({ field: value, path: [key] });
35727
35779
  }
35728
35780
  }
35729
- this.config.returning = orderSelectedFields(this.config.table[Table2.Symbol.Columns]);
35781
+ this.config.returning = returning;
35730
35782
  return this;
35731
35783
  }
35732
35784
  /** @internal */
@@ -38398,15 +38450,15 @@ function clearDefaults(defaultValue, collate) {
38398
38450
  if (defaultValue.startsWith(collate)) {
38399
38451
  resultDefault = resultDefault.substring(collate.length, defaultValue.length).replace(/\\/g, "");
38400
38452
  if (resultDefault.startsWith("'") && resultDefault.endsWith("'")) {
38401
- return `('${resultDefault.substring(1, resultDefault.length - 1)}')`;
38453
+ return `('${escapeSingleQuotes(resultDefault.substring(1, resultDefault.length - 1))}')`;
38402
38454
  } else {
38403
- return `'${resultDefault}'`;
38455
+ return `'${escapeSingleQuotes(resultDefault.substring(1, resultDefault.length - 1))}'`;
38404
38456
  }
38405
38457
  } else {
38406
38458
  return `(${resultDefault})`;
38407
38459
  }
38408
38460
  }
38409
- var generateMySqlSnapshot, fromDatabase3;
38461
+ var handleEnumType, generateMySqlSnapshot, fromDatabase3;
38410
38462
  var init_mysqlSerializer = __esm({
38411
38463
  "src/serializer/mysqlSerializer.ts"() {
38412
38464
  "use strict";
@@ -38414,7 +38466,14 @@ var init_mysqlSerializer = __esm({
38414
38466
  init_dist();
38415
38467
  init_mysql_core();
38416
38468
  init_outputs();
38469
+ init_utils();
38417
38470
  init_utils6();
38471
+ handleEnumType = (type) => {
38472
+ let str = type.split("(")[1];
38473
+ str = str.substring(0, str.length - 1);
38474
+ const values = str.split(",").map((v) => `'${escapeSingleQuotes(v.substring(1, v.length - 1))}'`);
38475
+ return `enum(${values.join(",")})`;
38476
+ };
38418
38477
  generateMySqlSnapshot = (tables, views, casing2) => {
38419
38478
  const dialect4 = new MySqlDialect({ casing: casing2 });
38420
38479
  const result = {};
@@ -38441,12 +38500,13 @@ var init_mysqlSerializer = __esm({
38441
38500
  columns.forEach((column4) => {
38442
38501
  const name2 = getColumnCasing(column4, casing2);
38443
38502
  const notNull = column4.notNull;
38444
- const sqlTypeLowered = column4.getSQLType().toLowerCase();
38503
+ const sqlType = column4.getSQLType();
38504
+ const sqlTypeLowered = sqlType.toLowerCase();
38445
38505
  const autoIncrement = typeof column4.autoIncrement === "undefined" ? false : column4.autoIncrement;
38446
38506
  const generated = column4.generated;
38447
38507
  const columnToSet = {
38448
38508
  name: name2,
38449
- type: column4.getSQLType(),
38509
+ type: sqlType.startsWith("enum") ? handleEnumType(sqlType) : sqlType,
38450
38510
  primaryKey: false,
38451
38511
  // If field is autoincrement it's notNull by default
38452
38512
  // notNull: autoIncrement ? true : notNull,
@@ -38493,7 +38553,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
38493
38553
  columnToSet.default = sqlToStr(column4.default, casing2);
38494
38554
  } else {
38495
38555
  if (typeof column4.default === "string") {
38496
- columnToSet.default = `'${column4.default}'`;
38556
+ columnToSet.default = `'${escapeSingleQuotes(column4.default)}'`;
38497
38557
  } else {
38498
38558
  if (sqlTypeLowered === "json") {
38499
38559
  columnToSet.default = `'${JSON.stringify(column4.default)}'`;
@@ -38862,15 +38922,15 @@ ${withStyle.errorWarning(
38862
38922
  changedType = columnType.replace("bigint unsigned", "serial");
38863
38923
  }
38864
38924
  }
38865
- if (columnType.startsWith("tinyint")) {
38866
- changedType = "tinyint";
38925
+ if (columnType.includes("decimal(10,0)")) {
38926
+ changedType = columnType.replace("decimal(10,0)", "decimal");
38867
38927
  }
38868
38928
  let onUpdate = void 0;
38869
38929
  if (columnType.startsWith("timestamp") && typeof columnExtra !== "undefined" && columnExtra.includes("on update CURRENT_TIMESTAMP")) {
38870
38930
  onUpdate = true;
38871
38931
  }
38872
38932
  const newColumn = {
38873
- default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
38933
+ default: columnDefault === null || columnDefault === void 0 ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${escapeSingleQuotes(columnDefault)}'`,
38874
38934
  autoincrement: isAutoincrement,
38875
38935
  name: columnName,
38876
38936
  type: changedType,
@@ -39385,6 +39445,7 @@ var init_utils9 = __esm({
39385
39445
  "use strict";
39386
39446
  import_hanji7 = __toESM(require_hanji());
39387
39447
  init_lib();
39448
+ init_getTablesFilterByExtensions();
39388
39449
  init_global();
39389
39450
  init_schemaValidator();
39390
39451
  init_serializer();
@@ -40327,6 +40388,7 @@ var sqlitePushIntrospect = async (db, filters) => {
40327
40388
 
40328
40389
  // src/api.ts
40329
40390
  init_sqlitePushUtils();
40391
+ init_getTablesFilterByExtensions();
40330
40392
  init_global();
40331
40393
  init_migrationPreparator();
40332
40394
  init_mysqlSchema();
@@ -40380,9 +40442,12 @@ var generateMigration = async (prev, cur) => {
40380
40442
  );
40381
40443
  return sqlStatements;
40382
40444
  };
40383
- var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40445
+ var pushSchema = async (imports, drizzleInstance, schemaFilters, tablesFilter, extensionsFilters) => {
40384
40446
  const { applyPgSnapshotsDiff: applyPgSnapshotsDiff2 } = await Promise.resolve().then(() => (init_snapshotsDiffer(), snapshotsDiffer_exports));
40385
40447
  const { sql: sql2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
40448
+ const filters = (tablesFilter ?? []).concat(
40449
+ getTablesFilterByExtensions({ extensionsFilters, dialect: "postgresql" })
40450
+ );
40386
40451
  const db = {
40387
40452
  query: async (query, params) => {
40388
40453
  const res = await drizzleInstance.execute(sql2.raw(query));
@@ -40392,7 +40457,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40392
40457
  const cur = generateDrizzleJson(imports);
40393
40458
  const { schema: prev } = await pgPushIntrospect(
40394
40459
  db,
40395
- [],
40460
+ filters,
40396
40461
  schemaFilters ?? ["public"],
40397
40462
  void 0
40398
40463
  );