drizzle-kit 0.27.2 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
package/api.js CHANGED
@@ -7525,30 +7525,11 @@ var init_mysqlSchema = __esm({
7525
7525
  }
7526
7526
  });
7527
7527
 
7528
- // src/extensions/vector.ts
7529
- var vectorOps;
7530
- var init_vector = __esm({
7531
- "src/extensions/vector.ts"() {
7532
- "use strict";
7533
- vectorOps = [
7534
- "vector_l2_ops",
7535
- "vector_ip_ops",
7536
- "vector_cosine_ops",
7537
- "vector_l1_ops",
7538
- "bit_hamming_ops",
7539
- "bit_jaccard_ops",
7540
- "halfvec_l2_ops",
7541
- "sparsevec_l2_ops"
7542
- ];
7543
- }
7544
- });
7545
-
7546
7528
  // src/serializer/pgSchema.ts
7547
7529
  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;
7548
7530
  var init_pgSchema = __esm({
7549
7531
  "src/serializer/pgSchema.ts"() {
7550
7532
  "use strict";
7551
- init_vector();
7552
7533
  init_global();
7553
7534
  init_lib();
7554
7535
  indexV2 = objectType({
@@ -8008,7 +7989,7 @@ var init_pgSchema = __esm({
8008
7989
  squashIdx: (idx) => {
8009
7990
  index2.parse(idx);
8010
7991
  return `${idx.name};${idx.columns.map(
8011
- (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
7992
+ (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass ? c.opclass : ""}`
8012
7993
  ).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
8013
7994
  },
8014
7995
  unsquashIdx: (input) => {
@@ -8074,11 +8055,11 @@ var init_pgSchema = __esm({
8074
8055
  squashFK: (fk4) => {
8075
8056
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
8076
8057
  },
8077
- squashPolicy: (policy4) => {
8078
- return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.using}--${policy4.withCheck}--${policy4.on}`;
8058
+ squashPolicy: (policy3) => {
8059
+ return `${policy3.name}--${policy3.as}--${policy3.for}--${policy3.to?.join(",")}--${policy3.using}--${policy3.withCheck}--${policy3.on}`;
8079
8060
  },
8080
- unsquashPolicy: (policy4) => {
8081
- const splitted = policy4.split("--");
8061
+ unsquashPolicy: (policy3) => {
8062
+ const splitted = policy3.split("--");
8082
8063
  return {
8083
8064
  name: splitted[0],
8084
8065
  as: splitted[1],
@@ -8089,11 +8070,11 @@ var init_pgSchema = __esm({
8089
8070
  on: splitted[6] !== "undefined" ? splitted[6] : void 0
8090
8071
  };
8091
8072
  },
8092
- squashPolicyPush: (policy4) => {
8093
- return `${policy4.name}--${policy4.as}--${policy4.for}--${policy4.to?.join(",")}--${policy4.on}`;
8073
+ squashPolicyPush: (policy3) => {
8074
+ return `${policy3.name}--${policy3.as}--${policy3.for}--${policy3.to?.join(",")}--${policy3.on}`;
8094
8075
  },
8095
- unsquashPolicyPush: (policy4) => {
8096
- const splitted = policy4.split("--");
8076
+ unsquashPolicyPush: (policy3) => {
8077
+ const splitted = policy3.split("--");
8097
8078
  return {
8098
8079
  name: splitted[0],
8099
8080
  as: splitted[1],
@@ -8214,8 +8195,8 @@ var init_pgSchema = __esm({
8214
8195
  return PgSquasher.squashUnique(unq);
8215
8196
  }
8216
8197
  );
8217
- const squashedPolicies = mapValues(it[1].policies, (policy4) => {
8218
- return action === "push" ? PgSquasher.squashPolicyPush(policy4) : PgSquasher.squashPolicy(policy4);
8198
+ const squashedPolicies = mapValues(it[1].policies, (policy3) => {
8199
+ return action === "push" ? PgSquasher.squashPolicyPush(policy3) : PgSquasher.squashPolicy(policy3);
8219
8200
  });
8220
8201
  const squashedChecksContraints = mapValues(
8221
8202
  it[1].checkConstraints,
@@ -8603,6 +8584,9 @@ function findAddedAndRemoved(columnNames1, columnNames2) {
8603
8584
  const removedColumns = columnNames1.filter((it) => !set2.has(it));
8604
8585
  return { addedColumns, removedColumns };
8605
8586
  }
8587
+ function escapeSingleQuotes(str) {
8588
+ return str.replace(/'/g, "''");
8589
+ }
8606
8590
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8607
8591
  var init_utils = __esm({
8608
8592
  "src/utils.ts"() {
@@ -11938,7 +11922,7 @@ function fromJson(statements, dialect4, action, json22) {
11938
11922
  }).filter((it) => it !== "");
11939
11923
  return result;
11940
11924
  }
11941
- 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;
11925
+ 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;
11942
11926
  var init_sqlgenerator = __esm({
11943
11927
  "src/sqlgenerator.ts"() {
11944
11928
  "use strict";
@@ -11946,51 +11930,56 @@ var init_sqlgenerator = __esm({
11946
11930
  init_mysqlSchema();
11947
11931
  init_pgSchema();
11948
11932
  init_sqliteSchema();
11949
- pgNativeTypes = /* @__PURE__ */ new Set([
11950
- "uuid",
11951
- "smallint",
11952
- "integer",
11953
- "bigint",
11954
- "boolean",
11955
- "text",
11956
- "varchar",
11957
- "serial",
11958
- "bigserial",
11959
- "decimal",
11960
- "numeric",
11961
- "real",
11962
- "json",
11963
- "jsonb",
11964
- "time",
11965
- "time with time zone",
11966
- "time without time zone",
11967
- "time",
11968
- "timestamp",
11969
- "timestamp with time zone",
11970
- "timestamp without time zone",
11971
- "date",
11972
- "interval",
11973
- "bigint",
11974
- "bigserial",
11975
- "double precision",
11976
- "interval year",
11977
- "interval month",
11978
- "interval day",
11979
- "interval hour",
11980
- "interval minute",
11981
- "interval second",
11982
- "interval year to month",
11983
- "interval day to hour",
11984
- "interval day to minute",
11985
- "interval day to second",
11986
- "interval hour to minute",
11987
- "interval hour to second",
11988
- "interval minute to second"
11989
- ]);
11990
- isPgNativeType = (it) => {
11991
- if (pgNativeTypes.has(it)) return true;
11992
- const toCheck = it.replace(/ /g, "");
11993
- 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);
11933
+ init_utils();
11934
+ parseType = (schemaPrefix, type) => {
11935
+ const pgNativeTypes = [
11936
+ "uuid",
11937
+ "smallint",
11938
+ "integer",
11939
+ "bigint",
11940
+ "boolean",
11941
+ "text",
11942
+ "varchar",
11943
+ "serial",
11944
+ "bigserial",
11945
+ "decimal",
11946
+ "numeric",
11947
+ "real",
11948
+ "json",
11949
+ "jsonb",
11950
+ "time",
11951
+ "time with time zone",
11952
+ "time without time zone",
11953
+ "time",
11954
+ "timestamp",
11955
+ "timestamp with time zone",
11956
+ "timestamp without time zone",
11957
+ "date",
11958
+ "interval",
11959
+ "bigint",
11960
+ "bigserial",
11961
+ "double precision",
11962
+ "interval year",
11963
+ "interval month",
11964
+ "interval day",
11965
+ "interval hour",
11966
+ "interval minute",
11967
+ "interval second",
11968
+ "interval year to month",
11969
+ "interval day to hour",
11970
+ "interval day to minute",
11971
+ "interval day to second",
11972
+ "interval hour to minute",
11973
+ "interval hour to second",
11974
+ "interval minute to second",
11975
+ "char",
11976
+ "vector",
11977
+ "geometry"
11978
+ ];
11979
+ const arrayDefinitionRegex = /\[\d*(?:\[\d*\])*\]/g;
11980
+ const arrayDefinition = (type.match(arrayDefinitionRegex) ?? []).join("");
11981
+ const withoutArrayDefinition = type.replace(arrayDefinitionRegex, "");
11982
+ return pgNativeTypes.some((it) => type.startsWith(it)) ? `${withoutArrayDefinition}${arrayDefinition}` : `${schemaPrefix}"${withoutArrayDefinition}"${arrayDefinition}`;
11994
11983
  };
11995
11984
  Convertor = class {
11996
11985
  };
@@ -12031,14 +12020,14 @@ var init_sqlgenerator = __esm({
12031
12020
  return statement.type === "create_policy" && dialect4 === "postgresql";
12032
12021
  }
12033
12022
  convert(statement) {
12034
- const policy4 = statement.data;
12023
+ const policy3 = statement.data;
12035
12024
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12036
- const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12037
- const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12038
- const policyToPart = policy4.to?.map(
12025
+ const usingPart = policy3.using ? ` USING (${policy3.using})` : "";
12026
+ const withCheckPart = policy3.withCheck ? ` WITH CHECK (${policy3.withCheck})` : "";
12027
+ const policyToPart = policy3.to?.map(
12039
12028
  (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12040
12029
  ).join(", ");
12041
- return `CREATE POLICY "${policy4.name}" ON ${tableNameWithSchema} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12030
+ return `CREATE POLICY "${policy3.name}" ON ${tableNameWithSchema} AS ${policy3.as?.toUpperCase()} FOR ${policy3.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12042
12031
  }
12043
12032
  };
12044
12033
  PgDropPolicyConvertor = class extends Convertor {
@@ -12046,9 +12035,9 @@ var init_sqlgenerator = __esm({
12046
12035
  return statement.type === "drop_policy" && dialect4 === "postgresql";
12047
12036
  }
12048
12037
  convert(statement) {
12049
- const policy4 = statement.data;
12038
+ const policy3 = statement.data;
12050
12039
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
12051
- return `DROP POLICY "${policy4.name}" ON ${tableNameWithSchema} CASCADE;`;
12040
+ return `DROP POLICY "${policy3.name}" ON ${tableNameWithSchema} CASCADE;`;
12052
12041
  }
12053
12042
  };
12054
12043
  PgRenamePolicyConvertor = class extends Convertor {
@@ -12078,13 +12067,13 @@ var init_sqlgenerator = __esm({
12078
12067
  return statement.type === "create_ind_policy" && dialect4 === "postgresql";
12079
12068
  }
12080
12069
  convert(statement) {
12081
- const policy4 = statement.data;
12082
- const usingPart = policy4.using ? ` USING (${policy4.using})` : "";
12083
- const withCheckPart = policy4.withCheck ? ` WITH CHECK (${policy4.withCheck})` : "";
12084
- const policyToPart = policy4.to?.map(
12070
+ const policy3 = statement.data;
12071
+ const usingPart = policy3.using ? ` USING (${policy3.using})` : "";
12072
+ const withCheckPart = policy3.withCheck ? ` WITH CHECK (${policy3.withCheck})` : "";
12073
+ const policyToPart = policy3.to?.map(
12085
12074
  (v) => ["current_user", "current_role", "session_user", "public"].includes(v) ? v : `"${v}"`
12086
12075
  ).join(", ");
12087
- return `CREATE POLICY "${policy4.name}" ON ${policy4.on} AS ${policy4.as?.toUpperCase()} FOR ${policy4.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12076
+ return `CREATE POLICY "${policy3.name}" ON ${policy3.on} AS ${policy3.as?.toUpperCase()} FOR ${policy3.for?.toUpperCase()} TO ${policyToPart}${usingPart}${withCheckPart};`;
12088
12077
  }
12089
12078
  };
12090
12079
  PgDropIndPolicyConvertor = class extends Convertor {
@@ -12092,8 +12081,8 @@ var init_sqlgenerator = __esm({
12092
12081
  return statement.type === "drop_ind_policy" && dialect4 === "postgresql";
12093
12082
  }
12094
12083
  convert(statement) {
12095
- const policy4 = statement.data;
12096
- return `DROP POLICY "${policy4.name}" ON ${policy4.on} CASCADE;`;
12084
+ const policy3 = statement.data;
12085
+ return `DROP POLICY "${policy3.name}" ON ${policy3.on} CASCADE;`;
12097
12086
  }
12098
12087
  };
12099
12088
  PgRenameIndPolicyConvertor = class extends Convertor {
@@ -12151,7 +12140,7 @@ var init_sqlgenerator = __esm({
12151
12140
  const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
12152
12141
  const uniqueConstraint4 = column4.isUnique ? ` CONSTRAINT "${column4.uniqueName}" UNIQUE${column4.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
12153
12142
  const schemaPrefix = column4.typeSchema && column4.typeSchema !== "public" ? `"${column4.typeSchema}".` : "";
12154
- const type = isPgNativeType(column4.type) ? column4.type : `${schemaPrefix}"${column4.type}"`;
12143
+ const type = parseType(schemaPrefix, column4.type);
12155
12144
  const generated = column4.generated;
12156
12145
  const generatedStatement = generated ? ` GENERATED ALWAYS AS (${generated?.as}) STORED` : "";
12157
12146
  const unsquashedIdentity = column4.identity ? PgSquasher.unsquashIdentity(column4.identity) : void 0;
@@ -12708,7 +12697,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12708
12697
  const { name: name2, values, schema: schema4 } = st;
12709
12698
  const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12710
12699
  let valuesStatement = "(";
12711
- valuesStatement += values.map((it) => `'${it}'`).join(", ");
12700
+ valuesStatement += values.map((it) => `'${escapeSingleQuotes(it)}'`).join(", ");
12712
12701
  valuesStatement += ")";
12713
12702
  let statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
12714
12703
  return statement;
@@ -12918,7 +12907,7 @@ WITH ${withCheckOption} CHECK OPTION` : "";
12918
12907
  const tableNameWithSchema = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
12919
12908
  const defaultStatement = `${column4.default !== void 0 ? ` DEFAULT ${column4.default}` : ""}`;
12920
12909
  const schemaPrefix = column4.typeSchema && column4.typeSchema !== "public" ? `"${column4.typeSchema}".` : "";
12921
- const fixedType = isPgNativeType(column4.type) ? column4.type : `${schemaPrefix}"${column4.type}"`;
12910
+ const fixedType = parseType(schemaPrefix, column4.type);
12922
12911
  const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
12923
12912
  const unsquashedIdentity = identity ? PgSquasher.unsquashIdentity(identity) : void 0;
12924
12913
  const identityWithSchema = schema4 ? `"${schema4}"."${unsquashedIdentity?.name}"` : `"${unsquashedIdentity?.name}"`;
@@ -13488,8 +13477,9 @@ WITH ${withCheckOption} CHECK OPTION` : "";
13488
13477
  statement.new
13489
13478
  );
13490
13479
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
13491
- return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT ${statement.oldConstraintName};
13492
- ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newConstraintName} PRIMARY KEY(${newColumns.join(",")});`;
13480
+ console.log(statement.oldConstraintName, statement.newConstraintName);
13481
+ return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.oldConstraintName}";
13482
+ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${statement.newConstraintName}" PRIMARY KEY("${newColumns.join('","')}");`;
13493
13483
  }
13494
13484
  };
13495
13485
  MySqlAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
@@ -15692,30 +15682,29 @@ var init_jsonStatements = __esm({
15692
15682
  };
15693
15683
  });
15694
15684
  };
15695
- prepareAddCompositePrimaryKeyPg = (tableName, schema4, pks, json22) => {
15685
+ prepareAddCompositePrimaryKeyPg = (tableName, schema4, pks) => {
15696
15686
  return Object.values(pks).map((it) => {
15697
- const unsquashed = PgSquasher.unsquashPK(it);
15698
15687
  return {
15699
15688
  type: "create_composite_pk",
15700
15689
  tableName,
15701
15690
  data: it,
15702
15691
  schema: schema4,
15703
- constraintName: json22.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[unsquashed.name].name
15692
+ constraintName: PgSquasher.unsquashPK(it).name
15704
15693
  };
15705
15694
  });
15706
15695
  };
15707
- prepareDeleteCompositePrimaryKeyPg = (tableName, schema4, pks, json1) => {
15696
+ prepareDeleteCompositePrimaryKeyPg = (tableName, schema4, pks) => {
15708
15697
  return Object.values(pks).map((it) => {
15709
15698
  return {
15710
15699
  type: "delete_composite_pk",
15711
15700
  tableName,
15712
15701
  data: it,
15713
15702
  schema: schema4,
15714
- constraintName: json1.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it).name].name
15703
+ constraintName: PgSquasher.unsquashPK(it).name
15715
15704
  };
15716
15705
  });
15717
15706
  };
15718
- prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks, json1, json22) => {
15707
+ prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks) => {
15719
15708
  return Object.values(pks).map((it) => {
15720
15709
  return {
15721
15710
  type: "alter_composite_pk",
@@ -15723,8 +15712,8 @@ var init_jsonStatements = __esm({
15723
15712
  old: it.__old,
15724
15713
  new: it.__new,
15725
15714
  schema: schema4,
15726
- oldConstraintName: json1.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it.__old).name].name,
15727
- newConstraintName: json22.tables[`${schema4 || "public"}.${tableName}`].compositePrimaryKeys[PgSquasher.unsquashPK(it.__new).name].name
15715
+ oldConstraintName: PgSquasher.unsquashPK(it.__old).name,
15716
+ newConstraintName: PgSquasher.unsquashPK(it.__new).name
15728
15717
  };
15729
15718
  });
15730
15719
  };
@@ -15779,18 +15768,19 @@ var init_jsonStatements = __esm({
15779
15768
  type: "create_composite_pk",
15780
15769
  tableName,
15781
15770
  data: it,
15782
- constraintName: json22.tables[tableName].compositePrimaryKeys[unsquashed.name].name
15771
+ constraintName: unsquashed.name
15783
15772
  });
15784
15773
  }
15785
15774
  return res;
15786
15775
  };
15787
15776
  prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
15788
15777
  return Object.values(pks).map((it) => {
15778
+ const unsquashed = MySqlSquasher.unsquashPK(it);
15789
15779
  return {
15790
15780
  type: "delete_composite_pk",
15791
15781
  tableName,
15792
15782
  data: it,
15793
- constraintName: json1.tables[tableName].compositePrimaryKeys[MySqlSquasher.unsquashPK(it).name].name
15783
+ constraintName: unsquashed.name
15794
15784
  };
15795
15785
  });
15796
15786
  };
@@ -16821,12 +16811,12 @@ var init_snapshotsDiffer = __esm({
16821
16811
  (tableKey2, tableValue) => {
16822
16812
  const patchedPolicies = mapKeys(
16823
16813
  tableValue.policies,
16824
- (policyKey, policy4) => {
16814
+ (policyKey, policy3) => {
16825
16815
  const rens = policyRenamesDict[`${tableValue.schema || "public"}.${tableValue.name}`] || [];
16826
16816
  const newName = columnChangeFor(policyKey, rens);
16827
- const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy4) : PgSquasher.unsquashPolicy(policy4);
16817
+ const unsquashedPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(policy3) : PgSquasher.unsquashPolicy(policy3);
16828
16818
  unsquashedPolicy.name = newName;
16829
- policy4 = PgSquasher.squashPolicy(unsquashedPolicy);
16819
+ policy3 = PgSquasher.squashPolicy(unsquashedPolicy);
16830
16820
  return newName;
16831
16821
  }
16832
16822
  );
@@ -16966,17 +16956,17 @@ var init_snapshotsDiffer = __esm({
16966
16956
  const jsonDeletedCheckConstraints = [];
16967
16957
  const jsonCreatedCheckConstraints = [];
16968
16958
  for (let it of alteredTables) {
16969
- let addedColumns = [];
16959
+ let addedColumns;
16970
16960
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
16971
16961
  const addedPkColumns = it.addedCompositePKs[addedPkName];
16972
- addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
16962
+ addedColumns = PgSquasher.unsquashPK(addedPkColumns);
16973
16963
  }
16974
- let deletedColumns = [];
16964
+ let deletedColumns;
16975
16965
  for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
16976
16966
  const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
16977
- deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
16967
+ deletedColumns = PgSquasher.unsquashPK(deletedPkColumns);
16978
16968
  }
16979
- const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
16969
+ const doPerformDeleteAndCreate = JSON.stringify(addedColumns ?? {}) !== JSON.stringify(deletedColumns ?? {});
16980
16970
  let addedCompositePKs = [];
16981
16971
  let deletedCompositePKs = [];
16982
16972
  let alteredCompositePKs = [];
@@ -16984,22 +16974,18 @@ var init_snapshotsDiffer = __esm({
16984
16974
  addedCompositePKs = prepareAddCompositePrimaryKeyPg(
16985
16975
  it.name,
16986
16976
  it.schema,
16987
- it.addedCompositePKs,
16988
- curFull
16977
+ it.addedCompositePKs
16989
16978
  );
16990
16979
  deletedCompositePKs = prepareDeleteCompositePrimaryKeyPg(
16991
16980
  it.name,
16992
16981
  it.schema,
16993
- it.deletedCompositePKs,
16994
- prevFull
16982
+ it.deletedCompositePKs
16995
16983
  );
16996
16984
  }
16997
16985
  alteredCompositePKs = prepareAlterCompositePrimaryKeyPg(
16998
16986
  it.name,
16999
16987
  it.schema,
17000
- it.alteredCompositePKs,
17001
- prevFull,
17002
- curFull
16988
+ it.alteredCompositePKs
17003
16989
  );
17004
16990
  let addedUniqueConstraints = [];
17005
16991
  let deletedUniqueConstraints = [];
@@ -17118,9 +17104,9 @@ var init_snapshotsDiffer = __esm({
17118
17104
  );
17119
17105
  }
17120
17106
  typedResult.alteredPolicies.forEach(({ values }) => {
17121
- const policy4 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
17122
- const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json22.policies[policy4.name].values);
17123
- const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy4.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy4.name].values);
17107
+ const policy3 = action === "push" ? PgSquasher.unsquashPolicyPush(values) : PgSquasher.unsquashPolicy(values);
17108
+ const newPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy3.name].values) : PgSquasher.unsquashPolicy(json22.policies[policy3.name].values);
17109
+ const oldPolicy = action === "push" ? PgSquasher.unsquashPolicyPush(json22.policies[policy3.name].values) : PgSquasher.unsquashPolicy(json1.policies[policy3.name].values);
17124
17110
  if (newPolicy.as !== oldPolicy.as) {
17125
17111
  jsonDropIndPoliciesStatements.push(
17126
17112
  ...prepareDropIndPolicyJsons(
@@ -17998,9 +17984,9 @@ var init_snapshotsDiffer = __esm({
17998
17984
  jsonStatements.push(...jsonDeletedCompositePKs);
17999
17985
  jsonStatements.push(...jsonTableAlternations);
18000
17986
  jsonStatements.push(...jsonAddedCompositePKs);
17987
+ jsonStatements.push(...jsonAddColumnsStatemets);
18001
17988
  jsonStatements.push(...jsonAddedUniqueConstraints);
18002
17989
  jsonStatements.push(...jsonDeletedUniqueConstraints);
18003
- jsonStatements.push(...jsonAddColumnsStatemets);
18004
17990
  jsonStatements.push(...jsonCreateReferencesForCreatedTables);
18005
17991
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
18006
17992
  jsonStatements.push(...jsonCreatedCheckConstraints);
@@ -21135,7 +21121,7 @@ var version;
21135
21121
  var init_version = __esm({
21136
21122
  "../drizzle-orm/dist/version.js"() {
21137
21123
  "use strict";
21138
- version = "0.36.0";
21124
+ version = "0.36.1";
21139
21125
  }
21140
21126
  });
21141
21127
 
@@ -23754,7 +23740,7 @@ function vector(a, b) {
23754
23740
  return new PgVectorBuilder(name2, config);
23755
23741
  }
23756
23742
  var _a113, _b92, PgVectorBuilder, _a114, _b93, PgVector;
23757
- var init_vector2 = __esm({
23743
+ var init_vector = __esm({
23758
23744
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
23759
23745
  "use strict";
23760
23746
  init_entity();
@@ -23861,7 +23847,7 @@ var init_all = __esm({
23861
23847
  init_bit();
23862
23848
  init_halfvec();
23863
23849
  init_sparsevec();
23864
- init_vector2();
23850
+ init_vector();
23865
23851
  }
23866
23852
  });
23867
23853
 
@@ -24333,7 +24319,7 @@ function jaccardDistance(column4, value) {
24333
24319
  }
24334
24320
  return sql`${column4} <%> ${value}`;
24335
24321
  }
24336
- var init_vector3 = __esm({
24322
+ var init_vector2 = __esm({
24337
24323
  "../drizzle-orm/dist/sql/functions/vector.js"() {
24338
24324
  "use strict";
24339
24325
  init_sql();
@@ -24345,7 +24331,7 @@ var init_functions = __esm({
24345
24331
  "../drizzle-orm/dist/sql/functions/index.js"() {
24346
24332
  "use strict";
24347
24333
  init_aggregate();
24348
- init_vector3();
24334
+ init_vector2();
24349
24335
  }
24350
24336
  });
24351
24337
 
@@ -24575,7 +24561,7 @@ var init_columns = __esm({
24575
24561
  init_bit();
24576
24562
  init_halfvec();
24577
24563
  init_sparsevec();
24578
- init_vector2();
24564
+ init_vector();
24579
24565
  }
24580
24566
  });
24581
24567
 
@@ -28321,6 +28307,24 @@ var init_pg_core = __esm({
28321
28307
  }
28322
28308
  });
28323
28309
 
28310
+ // src/extensions/vector.ts
28311
+ var vectorOps;
28312
+ var init_vector3 = __esm({
28313
+ "src/extensions/vector.ts"() {
28314
+ "use strict";
28315
+ vectorOps = [
28316
+ "vector_l2_ops",
28317
+ "vector_ip_ops",
28318
+ "vector_cosine_ops",
28319
+ "vector_l1_ops",
28320
+ "bit_hamming_ops",
28321
+ "bit_jaccard_ops",
28322
+ "halfvec_l2_ops",
28323
+ "sparsevec_l2_ops"
28324
+ ];
28325
+ }
28326
+ });
28327
+
28324
28328
  // src/serializer/utils.ts
28325
28329
  function getColumnCasing(column4, casing2) {
28326
28330
  if (!column4.name) return "";
@@ -28426,7 +28430,7 @@ var init_pgSerializer = __esm({
28426
28430
  init_source();
28427
28431
  init_dist();
28428
28432
  init_pg_core();
28429
- init_vector();
28433
+ init_vector3();
28430
28434
  init_outputs();
28431
28435
  init_utils();
28432
28436
  init_utils6();
@@ -28530,7 +28534,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
28530
28534
  columnToSet.default = sqlToStr(column4.default, casing2);
28531
28535
  } else {
28532
28536
  if (typeof column4.default === "string") {
28533
- columnToSet.default = `'${column4.default}'`;
28537
+ columnToSet.default = `'${escapeSingleQuotes(column4.default)}'`;
28534
28538
  } else {
28535
28539
  if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
28536
28540
  columnToSet.default = `'${JSON.stringify(column4.default)}'::${sqlTypeLowered}`;
@@ -28712,17 +28716,17 @@ ${withStyle.errorWarning(
28712
28716
  with: value.config.with ?? {}
28713
28717
  };
28714
28718
  });
28715
- policies2.forEach((policy4) => {
28719
+ policies2.forEach((policy3) => {
28716
28720
  const mappedTo = [];
28717
- if (!policy4.to) {
28721
+ if (!policy3.to) {
28718
28722
  mappedTo.push("public");
28719
28723
  } else {
28720
- if (policy4.to && typeof policy4.to === "string") {
28721
- mappedTo.push(policy4.to);
28722
- } else if (policy4.to && is(policy4.to, PgRole)) {
28723
- mappedTo.push(policy4.to.name);
28724
- } else if (policy4.to && Array.isArray(policy4.to)) {
28725
- policy4.to.forEach((it) => {
28724
+ if (policy3.to && typeof policy3.to === "string") {
28725
+ mappedTo.push(policy3.to);
28726
+ } else if (policy3.to && is(policy3.to, PgRole)) {
28727
+ mappedTo.push(policy3.to.name);
28728
+ } else if (policy3.to && Array.isArray(policy3.to)) {
28729
+ policy3.to.forEach((it) => {
28726
28730
  if (typeof it === "string") {
28727
28731
  mappedTo.push(it);
28728
28732
  } else if (is(it, PgRole)) {
@@ -28731,24 +28735,24 @@ ${withStyle.errorWarning(
28731
28735
  });
28732
28736
  }
28733
28737
  }
28734
- if (policiesObject[policy4.name] !== void 0) {
28738
+ if (policiesObject[policy3.name] !== void 0) {
28735
28739
  console.log(
28736
28740
  `
28737
28741
  ${withStyle.errorWarning(
28738
28742
  `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28739
- policy4.name
28743
+ policy3.name
28740
28744
  )} name`
28741
28745
  )}`
28742
28746
  );
28743
28747
  process.exit(1);
28744
28748
  }
28745
- policiesObject[policy4.name] = {
28746
- name: policy4.name,
28747
- as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28748
- for: policy4.for?.toUpperCase() ?? "ALL",
28749
+ policiesObject[policy3.name] = {
28750
+ name: policy3.name,
28751
+ as: policy3.as?.toUpperCase() ?? "PERMISSIVE",
28752
+ for: policy3.for?.toUpperCase() ?? "ALL",
28749
28753
  to: mappedTo.sort(),
28750
- using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28751
- withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28754
+ using: is(policy3.using, SQL) ? dialect4.sqlToQuery(policy3.using).sql : void 0,
28755
+ withCheck: is(policy3.withCheck, SQL) ? dialect4.sqlToQuery(policy3.withCheck).sql : void 0
28752
28756
  };
28753
28757
  });
28754
28758
  checks.forEach((check) => {
@@ -28792,28 +28796,28 @@ ${withStyle.errorWarning(
28792
28796
  isRLSEnabled: enableRLS
28793
28797
  };
28794
28798
  }
28795
- for (const policy4 of policies) {
28796
- if (!policy4._linkedTable) {
28799
+ for (const policy3 of policies) {
28800
+ if (!policy3._linkedTable) {
28797
28801
  console.log(
28798
28802
  `
28799
28803
  ${withStyle.errorWarning(
28800
- `"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:`
28804
+ `"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:`
28801
28805
  )}`
28802
28806
  );
28803
28807
  continue;
28804
28808
  }
28805
- const tableConfig = getTableConfig(policy4._linkedTable);
28809
+ const tableConfig = getTableConfig(policy3._linkedTable);
28806
28810
  const tableKey2 = `${tableConfig.schema ?? "public"}.${tableConfig.name}`;
28807
28811
  const mappedTo = [];
28808
- if (!policy4.to) {
28812
+ if (!policy3.to) {
28809
28813
  mappedTo.push("public");
28810
28814
  } else {
28811
- if (policy4.to && typeof policy4.to === "string") {
28812
- mappedTo.push(policy4.to);
28813
- } else if (policy4.to && is(policy4.to, PgRole)) {
28814
- mappedTo.push(policy4.to.name);
28815
- } else if (policy4.to && Array.isArray(policy4.to)) {
28816
- policy4.to.forEach((it) => {
28815
+ if (policy3.to && typeof policy3.to === "string") {
28816
+ mappedTo.push(policy3.to);
28817
+ } else if (policy3.to && is(policy3.to, PgRole)) {
28818
+ mappedTo.push(policy3.to.name);
28819
+ } else if (policy3.to && Array.isArray(policy3.to)) {
28820
+ policy3.to.forEach((it) => {
28817
28821
  if (typeof it === "string") {
28818
28822
  mappedTo.push(it);
28819
28823
  } else if (is(it, PgRole)) {
@@ -28822,29 +28826,29 @@ ${withStyle.errorWarning(
28822
28826
  });
28823
28827
  }
28824
28828
  }
28825
- if (result[tableKey2]?.policies[policy4.name] !== void 0 || policiesToReturn[policy4.name] !== void 0) {
28829
+ if (result[tableKey2]?.policies[policy3.name] !== void 0 || policiesToReturn[policy3.name] !== void 0) {
28826
28830
  console.log(
28827
28831
  `
28828
28832
  ${withStyle.errorWarning(
28829
28833
  `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
28830
- policy4.name
28834
+ policy3.name
28831
28835
  )} name`
28832
28836
  )}`
28833
28837
  );
28834
28838
  process.exit(1);
28835
28839
  }
28836
28840
  const mappedPolicy = {
28837
- name: policy4.name,
28838
- as: policy4.as?.toUpperCase() ?? "PERMISSIVE",
28839
- for: policy4.for?.toUpperCase() ?? "ALL",
28841
+ name: policy3.name,
28842
+ as: policy3.as?.toUpperCase() ?? "PERMISSIVE",
28843
+ for: policy3.for?.toUpperCase() ?? "ALL",
28840
28844
  to: mappedTo.sort(),
28841
- using: is(policy4.using, SQL) ? dialect4.sqlToQuery(policy4.using).sql : void 0,
28842
- withCheck: is(policy4.withCheck, SQL) ? dialect4.sqlToQuery(policy4.withCheck).sql : void 0
28845
+ using: is(policy3.using, SQL) ? dialect4.sqlToQuery(policy3.using).sql : void 0,
28846
+ withCheck: is(policy3.withCheck, SQL) ? dialect4.sqlToQuery(policy3.withCheck).sql : void 0
28843
28847
  };
28844
28848
  if (result[tableKey2]) {
28845
- result[tableKey2].policies[policy4.name] = mappedPolicy;
28849
+ result[tableKey2].policies[policy3.name] = mappedPolicy;
28846
28850
  } else {
28847
- policiesToReturn[policy4.name] = {
28851
+ policiesToReturn[policy3.name] = {
28848
28852
  ...mappedPolicy,
28849
28853
  schema: tableConfig.schema ?? "public",
28850
28854
  on: `"${tableConfig.schema ?? "public"}"."${tableConfig.name}"`
@@ -29815,10 +29819,7 @@ WHERE
29815
29819
  defaultForColumn = (column4, internals, tableName) => {
29816
29820
  const columnName = column4.column_name;
29817
29821
  const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
29818
- if (column4.column_default === null) {
29819
- return void 0;
29820
- }
29821
- if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
29822
+ if (column4.column_default === null || column4.column_default === void 0 || column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
29822
29823
  return void 0;
29823
29824
  }
29824
29825
  if (column4.column_default.endsWith("[]")) {
@@ -30246,7 +30247,7 @@ var init_blob = __esm({
30246
30247
  return "blob";
30247
30248
  }
30248
30249
  mapFromDriverValue(value) {
30249
- return BigInt(value.toString());
30250
+ return BigInt(Buffer.isBuffer(value) ? value.toString() : String.fromCodePoint(...value));
30250
30251
  }
30251
30252
  mapToDriverValue(value) {
30252
30253
  return Buffer.from(value.toString());
@@ -30271,7 +30272,7 @@ var init_blob = __esm({
30271
30272
  return "blob";
30272
30273
  }
30273
30274
  mapFromDriverValue(value) {
30274
- return JSON.parse(value.toString());
30275
+ return JSON.parse(Buffer.isBuffer(value) ? value.toString() : String.fromCodePoint(...value));
30275
30276
  }
30276
30277
  mapToDriverValue(value) {
30277
30278
  return Buffer.from(JSON.stringify(value));
@@ -33497,6 +33498,7 @@ var init_sqliteSerializer = __esm({
33497
33498
  init_dist();
33498
33499
  init_sqlite_core();
33499
33500
  init_outputs();
33501
+ init_utils();
33500
33502
  init_utils6();
33501
33503
  generateSqliteSnapshot = (tables, views, casing2) => {
33502
33504
  const dialect4 = new SQLiteSyncDialect({ casing: casing2 });
@@ -33540,7 +33542,7 @@ var init_sqliteSerializer = __esm({
33540
33542
  if (is(column4.default, SQL)) {
33541
33543
  columnToSet.default = sqlToStr(column4.default, casing2);
33542
33544
  } else {
33543
- columnToSet.default = typeof column4.default === "string" ? `'${column4.default}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
33545
+ columnToSet.default = typeof column4.default === "string" ? `'${escapeSingleQuotes(column4.default)}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
33544
33546
  }
33545
33547
  }
33546
33548
  columnsObject[name2] = columnToSet;
@@ -34091,6 +34093,25 @@ WHERE
34091
34093
  }
34092
34094
  });
34093
34095
 
34096
+ // src/extensions/getTablesFilterByExtensions.ts
34097
+ var getTablesFilterByExtensions;
34098
+ var init_getTablesFilterByExtensions = __esm({
34099
+ "src/extensions/getTablesFilterByExtensions.ts"() {
34100
+ "use strict";
34101
+ getTablesFilterByExtensions = ({
34102
+ extensionsFilters,
34103
+ dialect: dialect4
34104
+ }) => {
34105
+ if (extensionsFilters) {
34106
+ if (extensionsFilters.includes("postgis") && dialect4 === "postgresql") {
34107
+ return ["!geography_columns", "!geometry_columns", "!spatial_ref_sys"];
34108
+ }
34109
+ }
34110
+ return [];
34111
+ };
34112
+ }
34113
+ });
34114
+
34094
34115
  // ../drizzle-orm/dist/mysql-core/alias.js
34095
34116
  var init_alias4 = __esm({
34096
34117
  "../drizzle-orm/dist/mysql-core/alias.js"() {
@@ -34713,7 +34734,7 @@ var init_datetime = __esm({
34713
34734
  // ../drizzle-orm/dist/mysql-core/columns/decimal.js
34714
34735
  function decimal(a, b = {}) {
34715
34736
  const { name: name2, config } = getColumnNameAndConfig(a, b);
34716
- return new MySqlDecimalBuilder(name2, config.precision, config.scale);
34737
+ return new MySqlDecimalBuilder(name2, config);
34717
34738
  }
34718
34739
  var _a259, _b182, MySqlDecimalBuilder, _a260, _b183, MySqlDecimal;
34719
34740
  var init_decimal = __esm({
@@ -34723,10 +34744,11 @@ var init_decimal = __esm({
34723
34744
  init_utils2();
34724
34745
  init_common4();
34725
34746
  MySqlDecimalBuilder = class extends (_b182 = MySqlColumnBuilderWithAutoIncrement, _a259 = entityKind, _b182) {
34726
- constructor(name2, precision, scale) {
34747
+ constructor(name2, config) {
34727
34748
  super(name2, "string", "MySqlDecimal");
34728
- this.config.precision = precision;
34729
- this.config.scale = scale;
34749
+ this.config.precision = config?.precision;
34750
+ this.config.scale = config?.scale;
34751
+ this.config.unsigned = config?.unsigned;
34730
34752
  }
34731
34753
  /** @internal */
34732
34754
  build(table4) {
@@ -34742,15 +34764,19 @@ var init_decimal = __esm({
34742
34764
  super(...arguments);
34743
34765
  __publicField(this, "precision", this.config.precision);
34744
34766
  __publicField(this, "scale", this.config.scale);
34767
+ __publicField(this, "unsigned", this.config.unsigned);
34745
34768
  }
34746
34769
  getSQLType() {
34770
+ let type = "";
34747
34771
  if (this.precision !== void 0 && this.scale !== void 0) {
34748
- return `decimal(${this.precision},${this.scale})`;
34772
+ type += `decimal(${this.precision},${this.scale})`;
34749
34773
  } else if (this.precision === void 0) {
34750
- return "decimal";
34774
+ type += "decimal";
34751
34775
  } else {
34752
- return `decimal(${this.precision})`;
34776
+ type += `decimal(${this.precision})`;
34753
34777
  }
34778
+ type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
34779
+ return this.unsigned ? `${type} unsigned` : type;
34754
34780
  }
34755
34781
  };
34756
34782
  __publicField(MySqlDecimal, _a260, "MySqlDecimal");
@@ -34774,6 +34800,7 @@ var init_double = __esm({
34774
34800
  super(name2, "number", "MySqlDouble");
34775
34801
  this.config.precision = config?.precision;
34776
34802
  this.config.scale = config?.scale;
34803
+ this.config.unsigned = config?.unsigned;
34777
34804
  }
34778
34805
  /** @internal */
34779
34806
  build(table4) {
@@ -34786,15 +34813,18 @@ var init_double = __esm({
34786
34813
  super(...arguments);
34787
34814
  __publicField(this, "precision", this.config.precision);
34788
34815
  __publicField(this, "scale", this.config.scale);
34816
+ __publicField(this, "unsigned", this.config.unsigned);
34789
34817
  }
34790
34818
  getSQLType() {
34819
+ let type = "";
34791
34820
  if (this.precision !== void 0 && this.scale !== void 0) {
34792
- return `double(${this.precision},${this.scale})`;
34821
+ type += `double(${this.precision},${this.scale})`;
34793
34822
  } else if (this.precision === void 0) {
34794
- return "double";
34823
+ type += "double";
34795
34824
  } else {
34796
- return `double(${this.precision})`;
34825
+ type += `double(${this.precision})`;
34797
34826
  }
34827
+ return this.unsigned ? `${type} unsigned` : type;
34798
34828
  }
34799
34829
  };
34800
34830
  __publicField(MySqlDouble, _a262, "MySqlDouble");
@@ -34844,18 +34874,23 @@ var init_enum2 = __esm({
34844
34874
  });
34845
34875
 
34846
34876
  // ../drizzle-orm/dist/mysql-core/columns/float.js
34847
- function float(name2) {
34848
- return new MySqlFloatBuilder(name2 ?? "");
34877
+ function float(a, b) {
34878
+ const { name: name2, config } = getColumnNameAndConfig(a, b);
34879
+ return new MySqlFloatBuilder(name2, config);
34849
34880
  }
34850
34881
  var _a265, _b188, MySqlFloatBuilder, _a266, _b189, MySqlFloat;
34851
34882
  var init_float = __esm({
34852
34883
  "../drizzle-orm/dist/mysql-core/columns/float.js"() {
34853
34884
  "use strict";
34854
34885
  init_entity();
34886
+ init_utils2();
34855
34887
  init_common4();
34856
34888
  MySqlFloatBuilder = class extends (_b188 = MySqlColumnBuilderWithAutoIncrement, _a265 = entityKind, _b188) {
34857
- constructor(name2) {
34889
+ constructor(name2, config) {
34858
34890
  super(name2, "number", "MySqlFloat");
34891
+ this.config.precision = config?.precision;
34892
+ this.config.scale = config?.scale;
34893
+ this.config.unsigned = config?.unsigned;
34859
34894
  }
34860
34895
  /** @internal */
34861
34896
  build(table4) {
@@ -34864,8 +34899,22 @@ var init_float = __esm({
34864
34899
  };
34865
34900
  __publicField(MySqlFloatBuilder, _a265, "MySqlFloatBuilder");
34866
34901
  MySqlFloat = class extends (_b189 = MySqlColumnWithAutoIncrement, _a266 = entityKind, _b189) {
34902
+ constructor() {
34903
+ super(...arguments);
34904
+ __publicField(this, "precision", this.config.precision);
34905
+ __publicField(this, "scale", this.config.scale);
34906
+ __publicField(this, "unsigned", this.config.unsigned);
34907
+ }
34867
34908
  getSQLType() {
34868
- return "float";
34909
+ let type = "";
34910
+ if (this.precision !== void 0 && this.scale !== void 0) {
34911
+ type += `float(${this.precision},${this.scale})`;
34912
+ } else if (this.precision === void 0) {
34913
+ type += "float";
34914
+ } else {
34915
+ type += `float(${this.precision})`;
34916
+ }
34917
+ return this.unsigned ? `${type} unsigned` : type;
34869
34918
  }
34870
34919
  };
34871
34920
  __publicField(MySqlFloat, _a266, "MySqlFloat");
@@ -38393,15 +38442,15 @@ function clearDefaults(defaultValue, collate) {
38393
38442
  if (defaultValue.startsWith(collate)) {
38394
38443
  resultDefault = resultDefault.substring(collate.length, defaultValue.length).replace(/\\/g, "");
38395
38444
  if (resultDefault.startsWith("'") && resultDefault.endsWith("'")) {
38396
- return `('${resultDefault.substring(1, resultDefault.length - 1)}')`;
38445
+ return `('${escapeSingleQuotes(resultDefault.substring(1, resultDefault.length - 1))}')`;
38397
38446
  } else {
38398
- return `'${resultDefault}'`;
38447
+ return `'${escapeSingleQuotes(resultDefault.substring(1, resultDefault.length - 1))}'`;
38399
38448
  }
38400
38449
  } else {
38401
38450
  return `(${resultDefault})`;
38402
38451
  }
38403
38452
  }
38404
- var generateMySqlSnapshot, fromDatabase3;
38453
+ var handleEnumType, generateMySqlSnapshot, fromDatabase3;
38405
38454
  var init_mysqlSerializer = __esm({
38406
38455
  "src/serializer/mysqlSerializer.ts"() {
38407
38456
  "use strict";
@@ -38409,7 +38458,14 @@ var init_mysqlSerializer = __esm({
38409
38458
  init_dist();
38410
38459
  init_mysql_core();
38411
38460
  init_outputs();
38461
+ init_utils();
38412
38462
  init_utils6();
38463
+ handleEnumType = (type) => {
38464
+ let str = type.split("(")[1];
38465
+ str = str.substring(0, str.length - 1);
38466
+ const values = str.split(",").map((v) => `'${escapeSingleQuotes(v.substring(1, v.length - 1))}'`);
38467
+ return `enum(${values.join(",")})`;
38468
+ };
38413
38469
  generateMySqlSnapshot = (tables, views, casing2) => {
38414
38470
  const dialect4 = new MySqlDialect({ casing: casing2 });
38415
38471
  const result = {};
@@ -38436,12 +38492,13 @@ var init_mysqlSerializer = __esm({
38436
38492
  columns.forEach((column4) => {
38437
38493
  const name2 = getColumnCasing(column4, casing2);
38438
38494
  const notNull = column4.notNull;
38439
- const sqlTypeLowered = column4.getSQLType().toLowerCase();
38495
+ const sqlType = column4.getSQLType();
38496
+ const sqlTypeLowered = sqlType.toLowerCase();
38440
38497
  const autoIncrement = typeof column4.autoIncrement === "undefined" ? false : column4.autoIncrement;
38441
38498
  const generated = column4.generated;
38442
38499
  const columnToSet = {
38443
38500
  name: name2,
38444
- type: column4.getSQLType(),
38501
+ type: sqlType.startsWith("enum") ? handleEnumType(sqlType) : sqlType,
38445
38502
  primaryKey: false,
38446
38503
  // If field is autoincrement it's notNull by default
38447
38504
  // notNull: autoIncrement ? true : notNull,
@@ -38488,7 +38545,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
38488
38545
  columnToSet.default = sqlToStr(column4.default, casing2);
38489
38546
  } else {
38490
38547
  if (typeof column4.default === "string") {
38491
- columnToSet.default = `'${column4.default}'`;
38548
+ columnToSet.default = `'${escapeSingleQuotes(column4.default)}'`;
38492
38549
  } else {
38493
38550
  if (sqlTypeLowered === "json") {
38494
38551
  columnToSet.default = `'${JSON.stringify(column4.default)}'`;
@@ -38857,15 +38914,15 @@ ${withStyle.errorWarning(
38857
38914
  changedType = columnType.replace("bigint unsigned", "serial");
38858
38915
  }
38859
38916
  }
38860
- if (columnType.startsWith("tinyint")) {
38861
- changedType = "tinyint";
38917
+ if (columnType.includes("decimal(10,0)")) {
38918
+ changedType = columnType.replace("decimal(10,0)", "decimal");
38862
38919
  }
38863
38920
  let onUpdate = void 0;
38864
38921
  if (columnType.startsWith("timestamp") && typeof columnExtra !== "undefined" && columnExtra.includes("on update CURRENT_TIMESTAMP")) {
38865
38922
  onUpdate = true;
38866
38923
  }
38867
38924
  const newColumn = {
38868
- 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}'`,
38925
+ 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)}'`,
38869
38926
  autoincrement: isAutoincrement,
38870
38927
  name: columnName,
38871
38928
  type: changedType,
@@ -39380,6 +39437,7 @@ var init_utils9 = __esm({
39380
39437
  "use strict";
39381
39438
  import_hanji7 = __toESM(require_hanji());
39382
39439
  init_lib();
39440
+ init_getTablesFilterByExtensions();
39383
39441
  init_global();
39384
39442
  init_schemaValidator();
39385
39443
  init_serializer();
@@ -40336,6 +40394,7 @@ var sqlitePushIntrospect = async (db, filters) => {
40336
40394
 
40337
40395
  // src/api.ts
40338
40396
  init_sqlitePushUtils();
40397
+ init_getTablesFilterByExtensions();
40339
40398
  init_global();
40340
40399
  init_migrationPreparator();
40341
40400
  init_mysqlSchema();
@@ -40389,9 +40448,12 @@ var generateMigration = async (prev, cur) => {
40389
40448
  );
40390
40449
  return sqlStatements;
40391
40450
  };
40392
- var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40451
+ var pushSchema = async (imports, drizzleInstance, schemaFilters, tablesFilter, extensionsFilters) => {
40393
40452
  const { applyPgSnapshotsDiff: applyPgSnapshotsDiff2 } = await Promise.resolve().then(() => (init_snapshotsDiffer(), snapshotsDiffer_exports));
40394
40453
  const { sql: sql2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
40454
+ const filters = (tablesFilter ?? []).concat(
40455
+ getTablesFilterByExtensions({ extensionsFilters, dialect: "postgresql" })
40456
+ );
40395
40457
  const db = {
40396
40458
  query: async (query, params) => {
40397
40459
  const res = await drizzleInstance.execute(sql2.raw(query));
@@ -40401,7 +40463,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
40401
40463
  const cur = generateDrizzleJson(imports);
40402
40464
  const { schema: prev } = await pgPushIntrospect(
40403
40465
  db,
40404
- [],
40466
+ filters,
40405
40467
  schemaFilters ?? ["public"],
40406
40468
  void 0
40407
40469
  );