drizzle-kit 0.27.2 → 0.28.0-2cb427f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,11 @@ 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
+ const schemaName = chunk.table[Table2.Symbol.Schema];
21416
+ return {
21417
+ sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName),
21418
+ params: []
21419
+ };
21430
21420
  }
21431
21421
  if (is(chunk, View3)) {
21432
21422
  const schemaName = chunk[ViewBaseConfig].schema;
@@ -23759,7 +23749,7 @@ function vector(a, b) {
23759
23749
  return new PgVectorBuilder(name2, config);
23760
23750
  }
23761
23751
  var _a113, _b92, PgVectorBuilder, _a114, _b93, PgVector;
23762
- var init_vector2 = __esm({
23752
+ var init_vector = __esm({
23763
23753
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
23764
23754
  "use strict";
23765
23755
  init_entity();
@@ -23866,7 +23856,7 @@ var init_all = __esm({
23866
23856
  init_bit();
23867
23857
  init_halfvec();
23868
23858
  init_sparsevec();
23869
- init_vector2();
23859
+ init_vector();
23870
23860
  }
23871
23861
  });
23872
23862
 
@@ -24338,7 +24328,7 @@ function jaccardDistance(column4, value) {
24338
24328
  }
24339
24329
  return sql`${column4} <%> ${value}`;
24340
24330
  }
24341
- var init_vector3 = __esm({
24331
+ var init_vector2 = __esm({
24342
24332
  "../drizzle-orm/dist/sql/functions/vector.js"() {
24343
24333
  "use strict";
24344
24334
  init_sql();
@@ -24350,7 +24340,7 @@ var init_functions = __esm({
24350
24340
  "../drizzle-orm/dist/sql/functions/index.js"() {
24351
24341
  "use strict";
24352
24342
  init_aggregate();
24353
- init_vector3();
24343
+ init_vector2();
24354
24344
  }
24355
24345
  });
24356
24346
 
@@ -24580,7 +24570,7 @@ var init_columns = __esm({
24580
24570
  init_bit();
24581
24571
  init_halfvec();
24582
24572
  init_sparsevec();
24583
- init_vector2();
24573
+ init_vector();
24584
24574
  }
24585
24575
  });
24586
24576
 
@@ -28326,6 +28316,24 @@ var init_pg_core = __esm({
28326
28316
  }
28327
28317
  });
28328
28318
 
28319
+ // src/extensions/vector.ts
28320
+ var vectorOps;
28321
+ var init_vector3 = __esm({
28322
+ "src/extensions/vector.ts"() {
28323
+ "use strict";
28324
+ vectorOps = [
28325
+ "vector_l2_ops",
28326
+ "vector_ip_ops",
28327
+ "vector_cosine_ops",
28328
+ "vector_l1_ops",
28329
+ "bit_hamming_ops",
28330
+ "bit_jaccard_ops",
28331
+ "halfvec_l2_ops",
28332
+ "sparsevec_l2_ops"
28333
+ ];
28334
+ }
28335
+ });
28336
+
28329
28337
  // src/serializer/utils.ts
28330
28338
  function getColumnCasing(column4, casing2) {
28331
28339
  if (!column4.name) return "";
@@ -28431,7 +28439,7 @@ var init_pgSerializer = __esm({
28431
28439
  init_source();
28432
28440
  init_dist();
28433
28441
  init_pg_core();
28434
- init_vector();
28442
+ init_vector3();
28435
28443
  init_outputs();
28436
28444
  init_utils();
28437
28445
  init_utils6();
@@ -28535,7 +28543,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
28535
28543
  columnToSet.default = sqlToStr(column4.default, casing2);
28536
28544
  } else {
28537
28545
  if (typeof column4.default === "string") {
28538
- columnToSet.default = `'${column4.default}'`;
28546
+ columnToSet.default = `'${escapeSingleQuotes(column4.default)}'`;
28539
28547
  } else {
28540
28548
  if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
28541
28549
  columnToSet.default = `'${JSON.stringify(column4.default)}'::${sqlTypeLowered}`;
@@ -28717,17 +28725,17 @@ ${withStyle.errorWarning(
28717
28725
  with: value.config.with ?? {}
28718
28726
  };
28719
28727
  });
28720
- policies2.forEach((policy4) => {
28728
+ policies2.forEach((policy3) => {
28721
28729
  const mappedTo = [];
28722
- if (!policy4.to) {
28730
+ if (!policy3.to) {
28723
28731
  mappedTo.push("public");
28724
28732
  } 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) => {
28733
+ if (policy3.to && typeof policy3.to === "string") {
28734
+ mappedTo.push(policy3.to);
28735
+ } else if (policy3.to && is(policy3.to, PgRole)) {
28736
+ mappedTo.push(policy3.to.name);
28737
+ } else if (policy3.to && Array.isArray(policy3.to)) {
28738
+ policy3.to.forEach((it) => {
28731
28739
  if (typeof it === "string") {
28732
28740
  mappedTo.push(it);
28733
28741
  } else if (is(it, PgRole)) {
@@ -28736,24 +28744,24 @@ ${withStyle.errorWarning(
28736
28744
  });
28737
28745
  }
28738
28746
  }
28739
- if (policiesObject[policy4.name] !== void 0) {
28747
+ if (policiesObject[policy3.name] !== void 0) {
28740
28748
  console.log(
28741
28749
  `
28742
28750
  ${withStyle.errorWarning(
28743
28751
  `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
28752
+ policy3.name
28745
28753
  )} name`
28746
28754
  )}`
28747
28755
  );
28748
28756
  process.exit(1);
28749
28757
  }
28750
- policiesObject[policy4.name] = {
28751
- name: policy4.name,
28752
- as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28753
- for: policy4.for?.toUpperCase() ?? "ALL",
28758
+ policiesObject[policy3.name] = {
28759
+ name: policy3.name,
28760
+ as: policy3.as?.toUpperCase() ?? "PERMISSIVE",
28761
+ for: policy3.for?.toUpperCase() ?? "ALL",
28754
28762
  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
28763
+ using: is(policy3.using, SQL) ? dialect4.sqlToQuery(policy3.using).sql : void 0,
28764
+ withCheck: is(policy3.withCheck, SQL) ? dialect4.sqlToQuery(policy3.withCheck).sql : void 0
28757
28765
  };
28758
28766
  });
28759
28767
  checks.forEach((check) => {
@@ -28797,28 +28805,28 @@ ${withStyle.errorWarning(
28797
28805
  isRLSEnabled: enableRLS
28798
28806
  };
28799
28807
  }
28800
- for (const policy4 of policies) {
28801
- if (!policy4._linkedTable) {
28808
+ for (const policy3 of policies) {
28809
+ if (!policy3._linkedTable) {
28802
28810
  console.log(
28803
28811
  `
28804
28812
  ${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:`
28813
+ `"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
28814
  )}`
28807
28815
  );
28808
28816
  continue;
28809
28817
  }
28810
- const tableConfig = getTableConfig(policy4._linkedTable);
28818
+ const tableConfig = getTableConfig(policy3._linkedTable);
28811
28819
  const tableKey2 = `${tableConfig.schema ?? "public"}.${tableConfig.name}`;
28812
28820
  const mappedTo = [];
28813
- if (!policy4.to) {
28821
+ if (!policy3.to) {
28814
28822
  mappedTo.push("public");
28815
28823
  } 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) => {
28824
+ if (policy3.to && typeof policy3.to === "string") {
28825
+ mappedTo.push(policy3.to);
28826
+ } else if (policy3.to && is(policy3.to, PgRole)) {
28827
+ mappedTo.push(policy3.to.name);
28828
+ } else if (policy3.to && Array.isArray(policy3.to)) {
28829
+ policy3.to.forEach((it) => {
28822
28830
  if (typeof it === "string") {
28823
28831
  mappedTo.push(it);
28824
28832
  } else if (is(it, PgRole)) {
@@ -28827,29 +28835,29 @@ ${withStyle.errorWarning(
28827
28835
  });
28828
28836
  }
28829
28837
  }
28830
- if (result[tableKey2]?.policies[policy4.name] !== void 0 || policiesToReturn[policy4.name] !== void 0) {
28838
+ if (result[tableKey2]?.policies[policy3.name] !== void 0 || policiesToReturn[policy3.name] !== void 0) {
28831
28839
  console.log(
28832
28840
  `
28833
28841
  ${withStyle.errorWarning(
28834
28842
  `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
28843
+ policy3.name
28836
28844
  )} name`
28837
28845
  )}`
28838
28846
  );
28839
28847
  process.exit(1);
28840
28848
  }
28841
28849
  const mappedPolicy = {
28842
- name: policy4.name,
28843
- as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28844
- for: policy4.for?.toUpperCase() ?? "ALL",
28850
+ name: policy3.name,
28851
+ as: policy3.as?.toUpperCase() ?? "PERMISSIVE",
28852
+ for: policy3.for?.toUpperCase() ?? "ALL",
28845
28853
  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
28854
+ using: is(policy3.using, SQL) ? dialect4.sqlToQuery(policy3.using).sql : void 0,
28855
+ withCheck: is(policy3.withCheck, SQL) ? dialect4.sqlToQuery(policy3.withCheck).sql : void 0
28848
28856
  };
28849
28857
  if (result[tableKey2]) {
28850
- result[tableKey2].policies[policy4.name] = mappedPolicy;
28858
+ result[tableKey2].policies[policy3.name] = mappedPolicy;
28851
28859
  } else {
28852
- policiesToReturn[policy4.name] = {
28860
+ policiesToReturn[policy3.name] = {
28853
28861
  ...mappedPolicy,
28854
28862
  schema: tableConfig.schema ?? "public",
28855
28863
  on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
@@ -29820,10 +29828,7 @@ WHERE
29820
29828
  defaultForColumn = (column4, internals, tableName) => {
29821
29829
  const columnName = column4.column_name;
29822
29830
  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") {
29831
+ if (column4.column_default === null || column4.column_default === void 0 || column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
29827
29832
  return void 0;
29828
29833
  }
29829
29834
  if (column4.column_default.endsWith("[]")) {
@@ -30251,7 +30256,7 @@ var init_blob = __esm({
30251
30256
  return "blob";
30252
30257
  }
30253
30258
  mapFromDriverValue(value) {
30254
- return BigInt(value.toString());
30259
+ return BigInt(Buffer.isBuffer(value) ? value.toString() : String.fromCodePoint(...value));
30255
30260
  }
30256
30261
  mapToDriverValue(value) {
30257
30262
  return Buffer.from(value.toString());
@@ -30276,7 +30281,7 @@ var init_blob = __esm({
30276
30281
  return "blob";
30277
30282
  }
30278
30283
  mapFromDriverValue(value) {
30279
- return JSON.parse(value.toString());
30284
+ return JSON.parse(Buffer.isBuffer(value) ? value.toString() : String.fromCodePoint(...value));
30280
30285
  }
30281
30286
  mapToDriverValue(value) {
30282
30287
  return Buffer.from(JSON.stringify(value));
@@ -33502,6 +33507,7 @@ var init_sqliteSerializer = __esm({
33502
33507
  init_dist();
33503
33508
  init_sqlite_core();
33504
33509
  init_outputs();
33510
+ init_utils();
33505
33511
  init_utils6();
33506
33512
  generateSqliteSnapshot = (tables, views, casing2) => {
33507
33513
  const dialect4 = new SQLiteSyncDialect({ casing: casing2 });
@@ -33545,7 +33551,7 @@ var init_sqliteSerializer = __esm({
33545
33551
  if (is(column4.default, SQL)) {
33546
33552
  columnToSet.default = sqlToStr(column4.default, casing2);
33547
33553
  } else {
33548
- columnToSet.default = typeof column4.default === "string" ? `'${column4.default}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
33554
+ columnToSet.default = typeof column4.default === "string" ? `'${escapeSingleQuotes(column4.default)}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
33549
33555
  }
33550
33556
  }
33551
33557
  columnsObject[name2] = columnToSet;
@@ -34096,6 +34102,25 @@ WHERE
34096
34102
  }
34097
34103
  });
34098
34104
 
34105
+ // src/extensions/getTablesFilterByExtensions.ts
34106
+ var getTablesFilterByExtensions;
34107
+ var init_getTablesFilterByExtensions = __esm({
34108
+ "src/extensions/getTablesFilterByExtensions.ts"() {
34109
+ "use strict";
34110
+ getTablesFilterByExtensions = ({
34111
+ extensionsFilters,
34112
+ dialect: dialect4
34113
+ }) => {
34114
+ if (extensionsFilters) {
34115
+ if (extensionsFilters.includes("postgis") && dialect4 === "postgresql") {
34116
+ return ["!geography_columns", "!geometry_columns", "!spatial_ref_sys"];
34117
+ }
34118
+ }
34119
+ return [];
34120
+ };
34121
+ }
34122
+ });
34123
+
34099
34124
  // ../drizzle-orm/dist/mysql-core/alias.js
34100
34125
  var init_alias4 = __esm({
34101
34126
  "../drizzle-orm/dist/mysql-core/alias.js"() {
@@ -34718,7 +34743,7 @@ var init_datetime = __esm({
34718
34743
  // ../drizzle-orm/dist/mysql-core/columns/decimal.js
34719
34744
  function decimal(a, b = {}) {
34720
34745
  const { name: name2, config } = getColumnNameAndConfig(a, b);
34721
- return new MySqlDecimalBuilder(name2, config.precision, config.scale);
34746
+ return new MySqlDecimalBuilder(name2, config);
34722
34747
  }
34723
34748
  var _a259, _b182, MySqlDecimalBuilder, _a260, _b183, MySqlDecimal;
34724
34749
  var init_decimal = __esm({
@@ -34728,10 +34753,11 @@ var init_decimal = __esm({
34728
34753
  init_utils2();
34729
34754
  init_common4();
34730
34755
  MySqlDecimalBuilder = class extends (_b182 = MySqlColumnBuilderWithAutoIncrement, _a259 = entityKind, _b182) {
34731
- constructor(name2, precision, scale) {
34756
+ constructor(name2, config) {
34732
34757
  super(name2, "string", "MySqlDecimal");
34733
- this.config.precision = precision;
34734
- this.config.scale = scale;
34758
+ this.config.precision = config?.precision;
34759
+ this.config.scale = config?.scale;
34760
+ this.config.unsigned = config?.unsigned;
34735
34761
  }
34736
34762
  /** @internal */
34737
34763
  build(table4) {
@@ -34747,15 +34773,19 @@ var init_decimal = __esm({
34747
34773
  super(...arguments);
34748
34774
  __publicField(this, "precision", this.config.precision);
34749
34775
  __publicField(this, "scale", this.config.scale);
34776
+ __publicField(this, "unsigned", this.config.unsigned);
34750
34777
  }
34751
34778
  getSQLType() {
34779
+ let type = "";
34752
34780
  if (this.precision !== void 0 && this.scale !== void 0) {
34753
- return `decimal(${this.precision},${this.scale})`;
34781
+ type += `decimal(${this.precision},${this.scale})`;
34754
34782
  } else if (this.precision === void 0) {
34755
- return "decimal";
34783
+ type += "decimal";
34756
34784
  } else {
34757
- return `decimal(${this.precision})`;
34785
+ type += `decimal(${this.precision})`;
34758
34786
  }
34787
+ type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
34788
+ return this.unsigned ? `${type} unsigned` : type;
34759
34789
  }
34760
34790
  };
34761
34791
  __publicField(MySqlDecimal, _a260, "MySqlDecimal");
@@ -34779,6 +34809,7 @@ var init_double = __esm({
34779
34809
  super(name2, "number", "MySqlDouble");
34780
34810
  this.config.precision = config?.precision;
34781
34811
  this.config.scale = config?.scale;
34812
+ this.config.unsigned = config?.unsigned;
34782
34813
  }
34783
34814
  /** @internal */
34784
34815
  build(table4) {
@@ -34791,15 +34822,18 @@ var init_double = __esm({
34791
34822
  super(...arguments);
34792
34823
  __publicField(this, "precision", this.config.precision);
34793
34824
  __publicField(this, "scale", this.config.scale);
34825
+ __publicField(this, "unsigned", this.config.unsigned);
34794
34826
  }
34795
34827
  getSQLType() {
34828
+ let type = "";
34796
34829
  if (this.precision !== void 0 && this.scale !== void 0) {
34797
- return `double(${this.precision},${this.scale})`;
34830
+ type += `double(${this.precision},${this.scale})`;
34798
34831
  } else if (this.precision === void 0) {
34799
- return "double";
34832
+ type += "double";
34800
34833
  } else {
34801
- return `double(${this.precision})`;
34834
+ type += `double(${this.precision})`;
34802
34835
  }
34836
+ return this.unsigned ? `${type} unsigned` : type;
34803
34837
  }
34804
34838
  };
34805
34839
  __publicField(MySqlDouble, _a262, "MySqlDouble");
@@ -34849,18 +34883,23 @@ var init_enum2 = __esm({
34849
34883
  });
34850
34884
 
34851
34885
  // ../drizzle-orm/dist/mysql-core/columns/float.js
34852
- function float(name2) {
34853
- return new MySqlFloatBuilder(name2 ?? "");
34886
+ function float(a, b) {
34887
+ const { name: name2, config } = getColumnNameAndConfig(a, b);
34888
+ return new MySqlFloatBuilder(name2, config);
34854
34889
  }
34855
34890
  var _a265, _b188, MySqlFloatBuilder, _a266, _b189, MySqlFloat;
34856
34891
  var init_float = __esm({
34857
34892
  "../drizzle-orm/dist/mysql-core/columns/float.js"() {
34858
34893
  "use strict";
34859
34894
  init_entity();
34895
+ init_utils2();
34860
34896
  init_common4();
34861
34897
  MySqlFloatBuilder = class extends (_b188 = MySqlColumnBuilderWithAutoIncrement, _a265 = entityKind, _b188) {
34862
- constructor(name2) {
34898
+ constructor(name2, config) {
34863
34899
  super(name2, "number", "MySqlFloat");
34900
+ this.config.precision = config?.precision;
34901
+ this.config.scale = config?.scale;
34902
+ this.config.unsigned = config?.unsigned;
34864
34903
  }
34865
34904
  /** @internal */
34866
34905
  build(table4) {
@@ -34869,8 +34908,22 @@ var init_float = __esm({
34869
34908
  };
34870
34909
  __publicField(MySqlFloatBuilder, _a265, "MySqlFloatBuilder");
34871
34910
  MySqlFloat = class extends (_b189 = MySqlColumnWithAutoIncrement, _a266 = entityKind, _b189) {
34911
+ constructor() {
34912
+ super(...arguments);
34913
+ __publicField(this, "precision", this.config.precision);
34914
+ __publicField(this, "scale", this.config.scale);
34915
+ __publicField(this, "unsigned", this.config.unsigned);
34916
+ }
34872
34917
  getSQLType() {
34873
- return "float";
34918
+ let type = "";
34919
+ if (this.precision !== void 0 && this.scale !== void 0) {
34920
+ type += `float(${this.precision},${this.scale})`;
34921
+ } else if (this.precision === void 0) {
34922
+ type += "float";
34923
+ } else {
34924
+ type += `float(${this.precision})`;
34925
+ }
34926
+ return this.unsigned ? `${type} unsigned` : type;
34874
34927
  }
34875
34928
  };
34876
34929
  __publicField(MySqlFloat, _a266, "MySqlFloat");
@@ -35691,7 +35744,7 @@ var init_insert3 = __esm({
35691
35744
  /**
35692
35745
  * Adds an `on duplicate key update` clause to the query.
35693
35746
  *
35694
- * Calling this method will update update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
35747
+ * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
35695
35748
  *
35696
35749
  * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
35697
35750
  *
@@ -35726,7 +35779,7 @@ var init_insert3 = __esm({
35726
35779
  returning.push({ field: value, path: [key] });
35727
35780
  }
35728
35781
  }
35729
- this.config.returning = orderSelectedFields(this.config.table[Table2.Symbol.Columns]);
35782
+ this.config.returning = returning;
35730
35783
  return this;
35731
35784
  }
35732
35785
  /** @internal */
@@ -38398,15 +38451,15 @@ function clearDefaults(defaultValue, collate) {
38398
38451
  if (defaultValue.startsWith(collate)) {
38399
38452
  resultDefault = resultDefault.substring(collate.length, defaultValue.length).replace(/\\/g, "");
38400
38453
  if (resultDefault.startsWith("'") && resultDefault.endsWith("'")) {
38401
- return `('${resultDefault.substring(1, resultDefault.length - 1)}')`;
38454
+ return `('${escapeSingleQuotes(resultDefault.substring(1, resultDefault.length - 1))}')`;
38402
38455
  } else {
38403
- return `'${resultDefault}'`;
38456
+ return `'${escapeSingleQuotes(resultDefault.substring(1, resultDefault.length - 1))}'`;
38404
38457
  }
38405
38458
  } else {
38406
38459
  return `(${resultDefault})`;
38407
38460
  }
38408
38461
  }
38409
- var generateMySqlSnapshot, fromDatabase3;
38462
+ var handleEnumType, generateMySqlSnapshot, fromDatabase3;
38410
38463
  var init_mysqlSerializer = __esm({
38411
38464
  "src/serializer/mysqlSerializer.ts"() {
38412
38465
  "use strict";
@@ -38414,7 +38467,14 @@ var init_mysqlSerializer = __esm({
38414
38467
  init_dist();
38415
38468
  init_mysql_core();
38416
38469
  init_outputs();
38470
+ init_utils();
38417
38471
  init_utils6();
38472
+ handleEnumType = (type) => {
38473
+ let str = type.split("(")[1];
38474
+ str = str.substring(0, str.length - 1);
38475
+ const values = str.split(",").map((v) => `'${escapeSingleQuotes(v.substring(1, v.length - 1))}'`);
38476
+ return `enum(${values.join(",")})`;
38477
+ };
38418
38478
  generateMySqlSnapshot = (tables, views, casing2) => {
38419
38479
  const dialect4 = new MySqlDialect({ casing: casing2 });
38420
38480
  const result = {};
@@ -38441,12 +38501,13 @@ var init_mysqlSerializer = __esm({
38441
38501
  columns.forEach((column4) => {
38442
38502
  const name2 = getColumnCasing(column4, casing2);
38443
38503
  const notNull = column4.notNull;
38444
- const sqlTypeLowered = column4.getSQLType().toLowerCase();
38504
+ const sqlType = column4.getSQLType();
38505
+ const sqlTypeLowered = sqlType.toLowerCase();
38445
38506
  const autoIncrement = typeof column4.autoIncrement === "undefined" ? false : column4.autoIncrement;
38446
38507
  const generated = column4.generated;
38447
38508
  const columnToSet = {
38448
38509
  name: name2,
38449
- type: column4.getSQLType(),
38510
+ type: sqlType.startsWith("enum") ? handleEnumType(sqlType) : sqlType,
38450
38511
  primaryKey: false,
38451
38512
  // If field is autoincrement it's notNull by default
38452
38513
  // notNull: autoIncrement ? true : notNull,
@@ -38493,7 +38554,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
38493
38554
  columnToSet.default = sqlToStr(column4.default, casing2);
38494
38555
  } else {
38495
38556
  if (typeof column4.default === "string") {
38496
- columnToSet.default = `'${column4.default}'`;
38557
+ columnToSet.default = `'${escapeSingleQuotes(column4.default)}'`;
38497
38558
  } else {
38498
38559
  if (sqlTypeLowered === "json") {
38499
38560
  columnToSet.default = `'${JSON.stringify(column4.default)}'`;
@@ -38862,15 +38923,15 @@ ${withStyle.errorWarning(
38862
38923
  changedType = columnType.replace("bigint unsigned", "serial");
38863
38924
  }
38864
38925
  }
38865
- if (columnType.startsWith("tinyint")) {
38866
- changedType = "tinyint";
38926
+ if (columnType.includes("decimal(10,0)")) {
38927
+ changedType = columnType.replace("decimal(10,0)", "decimal");
38867
38928
  }
38868
38929
  let onUpdate = void 0;
38869
38930
  if (columnType.startsWith("timestamp") && typeof columnExtra !== "undefined" && columnExtra.includes("on update CURRENT_TIMESTAMP")) {
38870
38931
  onUpdate = true;
38871
38932
  }
38872
38933
  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}'`,
38934
+ 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
38935
  autoincrement: isAutoincrement,
38875
38936
  name: columnName,
38876
38937
  type: changedType,
@@ -39385,6 +39446,7 @@ var init_utils9 = __esm({
39385
39446
  "use strict";
39386
39447
  import_hanji7 = __toESM(require_hanji());
39387
39448
  init_lib();
39449
+ init_getTablesFilterByExtensions();
39388
39450
  init_global();
39389
39451
  init_schemaValidator();
39390
39452
  init_serializer();
@@ -40327,6 +40389,7 @@ var sqlitePushIntrospect = async (db, filters) => {
40327
40389
 
40328
40390
  // src/api.ts
40329
40391
  init_sqlitePushUtils();
40392
+ init_getTablesFilterByExtensions();
40330
40393
  init_global();
40331
40394
  init_migrationPreparator();
40332
40395
  init_mysqlSchema();
@@ -40380,9 +40443,12 @@ var generateMigration = async (prev, cur) => {
40380
40443
  );
40381
40444
  return sqlStatements;
40382
40445
  };
40383
- var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40446
+ var pushSchema = async (imports, drizzleInstance, schemaFilters, tablesFilter, extensionsFilters) => {
40384
40447
  const { applyPgSnapshotsDiff: applyPgSnapshotsDiff2 } = await Promise.resolve().then(() => (init_snapshotsDiffer(), snapshotsDiffer_exports));
40385
40448
  const { sql: sql2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
40449
+ const filters = (tablesFilter ?? []).concat(
40450
+ getTablesFilterByExtensions({ extensionsFilters, dialect: "postgresql" })
40451
+ );
40386
40452
  const db = {
40387
40453
  query: async (query, params) => {
40388
40454
  const res = await drizzleInstance.execute(sql2.raw(query));
@@ -40392,7 +40458,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40392
40458
  const cur = generateDrizzleJson(imports);
40393
40459
  const { schema: prev } = await pgPushIntrospect(
40394
40460
  db,
40395
- [],
40461
+ filters,
40396
40462
  schemaFilters ?? ["public"],
40397
40463
  void 0
40398
40464
  );