drizzle-kit 0.25.0-1f15bfd → 0.25.0-26155b0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. package/api.js +17 -95
  2. package/api.mjs +17 -95
  3. package/bin.cjs +18 -97
  4. package/package.json +1 -1
package/api.js CHANGED
@@ -11675,7 +11675,7 @@ function fromJson(statements, dialect4, action, json22) {
11675
11675
  }).filter((it) => it !== "");
11676
11676
  return result;
11677
11677
  }
11678
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, 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;
11678
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
11679
11679
  var init_sqlgenerator = __esm({
11680
11680
  "src/sqlgenerator.ts"() {
11681
11681
  "use strict";
@@ -12056,22 +12056,20 @@ var init_sqlgenerator = __esm({
12056
12056
  }
12057
12057
  convert(st) {
12058
12058
  const { name: name2, values, schema: schema4 } = st;
12059
- const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12059
+ const tableNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12060
12060
  let valuesStatement = "(";
12061
12061
  valuesStatement += values.map((it) => `'${it}'`).join(", ");
12062
12062
  valuesStatement += ")";
12063
- let statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
12064
- return statement;
12065
- }
12066
- };
12067
- DropTypeEnumConvertor = class extends Convertor {
12068
- can(statement) {
12069
- return statement.type === "drop_type_enum";
12070
- }
12071
- convert(st) {
12072
- const { name: name2, schema: schema4 } = st;
12073
- const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12074
- let statement = `DROP TYPE ${enumNameWithSchema} CASCADE;`;
12063
+ let statement = "DO $$ BEGIN";
12064
+ statement += "\n";
12065
+ statement += ` CREATE TYPE ${tableNameWithSchema} AS ENUM${valuesStatement};`;
12066
+ statement += "\n";
12067
+ statement += "EXCEPTION";
12068
+ statement += "\n";
12069
+ statement += " WHEN duplicate_object THEN null;";
12070
+ statement += "\n";
12071
+ statement += "END $$;";
12072
+ statement += "\n";
12075
12073
  return statement;
12076
12074
  }
12077
12075
  };
@@ -12080,56 +12078,9 @@ var init_sqlgenerator = __esm({
12080
12078
  return statement.type === "alter_type_add_value";
12081
12079
  }
12082
12080
  convert(st) {
12083
- const { name: name2, schema: schema4, value, before } = st;
12084
- const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12085
- return `ALTER TYPE ${enumNameWithSchema} ADD VALUE '${value}'${before.length ? ` BEFORE '${before}'` : ""};`;
12086
- }
12087
- };
12088
- AlterTypeSetSchemaConvertor = class extends Convertor {
12089
- can(statement) {
12090
- return statement.type === "move_type_enum";
12091
- }
12092
- convert(st) {
12093
- const { name: name2, schemaFrom, schemaTo } = st;
12094
- const enumNameWithSchema = schemaFrom ? `"${schemaFrom}"."${name2}"` : `"${name2}"`;
12095
- return `ALTER TYPE ${enumNameWithSchema} SET SCHEMA "${schemaTo}";`;
12096
- }
12097
- };
12098
- AlterRenameTypeConvertor = class extends Convertor {
12099
- can(statement) {
12100
- return statement.type === "rename_type_enum";
12101
- }
12102
- convert(st) {
12103
- const { nameTo, nameFrom, schema: schema4 } = st;
12104
- const enumNameWithSchema = schema4 ? `"${schema4}"."${nameFrom}"` : `"${nameFrom}"`;
12105
- return `ALTER TYPE ${enumNameWithSchema} RENAME TO "${nameTo}";`;
12106
- }
12107
- };
12108
- AlterTypeDropValueConvertor = class extends Convertor {
12109
- can(statement) {
12110
- return statement.type === "alter_type_drop_value";
12111
- }
12112
- convert(st) {
12113
- const { columnsWithEnum, name: name2, newValues, schema: schema4 } = st;
12114
- const statements = [];
12115
- for (const withEnum of columnsWithEnum) {
12116
- statements.push(
12117
- `ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE text;`
12118
- );
12119
- }
12120
- statements.push(new DropTypeEnumConvertor().convert({ name: name2, schema: schema4, type: "drop_type_enum" }));
12121
- statements.push(new CreateTypeEnumConvertor().convert({
12122
- name: name2,
12123
- schema: schema4,
12124
- values: newValues,
12125
- type: "create_type_enum"
12126
- }));
12127
- for (const withEnum of columnsWithEnum) {
12128
- statements.push(
12129
- `ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE "${schema4}"."${name2}" USING "${withEnum.column}"::"${schema4}"."${name2}";`
12130
- );
12131
- }
12132
- return statements;
12081
+ const { name: name2, schema: schema4, value } = st;
12082
+ const schemaPrefix = schema4 && schema4 !== "public" ? `"${schema4}".` : "";
12083
+ return `ALTER TYPE ${schemaPrefix}"${name2}" ADD VALUE '${value}';`;
12133
12084
  }
12134
12085
  };
12135
12086
  PgDropTableConvertor = class extends Convertor {
@@ -13273,11 +13224,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13273
13224
  convertors.push(new SQLiteRecreateTableConvertor());
13274
13225
  convertors.push(new LibSQLRecreateTableConvertor());
13275
13226
  convertors.push(new CreateTypeEnumConvertor());
13276
- convertors.push(new DropTypeEnumConvertor());
13277
- convertors.push(new AlterTypeAddValueConvertor());
13278
- convertors.push(new AlterTypeSetSchemaConvertor());
13279
- convertors.push(new AlterRenameTypeConvertor());
13280
- convertors.push(new AlterTypeDropValueConvertor());
13281
13227
  convertors.push(new CreatePgSequenceConvertor());
13282
13228
  convertors.push(new DropPgSequenceConvertor());
13283
13229
  convertors.push(new RenamePgSequenceConvertor());
@@ -13309,6 +13255,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13309
13255
  convertors.push(new PgDropIndexConvertor());
13310
13256
  convertors.push(new SqliteDropIndexConvertor());
13311
13257
  convertors.push(new MySqlDropIndexConvertor());
13258
+ convertors.push(new AlterTypeAddValueConvertor());
13312
13259
  convertors.push(new PgAlterTableAlterColumnSetPrimaryKeyConvertor());
13313
13260
  convertors.push(new PgAlterTableAlterColumnDropPrimaryKeyConvertor());
13314
13261
  convertors.push(new PgAlterTableAlterColumnSetNotNullConvertor());
@@ -13609,7 +13556,7 @@ var init_sqlitePushUtils = __esm({
13609
13556
  });
13610
13557
 
13611
13558
  // src/jsonStatements.ts
13612
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
13559
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
13613
13560
  var init_jsonStatements = __esm({
13614
13561
  "src/jsonStatements.ts"() {
13615
13562
  "use strict";
@@ -13699,27 +13646,6 @@ var init_jsonStatements = __esm({
13699
13646
  };
13700
13647
  });
13701
13648
  };
13702
- prepareDropEnumValues = (name2, schema4, removedValues, json22) => {
13703
- if (!removedValues.length) return [];
13704
- const affectedColumns = [];
13705
- for (const tableKey2 in json22.tables) {
13706
- const table4 = json22.tables[tableKey2];
13707
- for (const columnKey in table4.columns) {
13708
- const column4 = table4.columns[columnKey];
13709
- if (column4.type === name2 && column4.typeSchema === schema4) {
13710
- affectedColumns.push({ schema: table4.schema || "public", table: table4.name, column: column4.name });
13711
- }
13712
- }
13713
- }
13714
- return [{
13715
- type: "alter_type_drop_value",
13716
- name: name2,
13717
- schema: schema4,
13718
- deletedValues: removedValues,
13719
- newValues: json22.enums[`${schema4}.${name2}`].values,
13720
- columnsWithEnum: affectedColumns
13721
- }];
13722
- };
13723
13649
  prepareDropEnumJson = (name2, schema4) => {
13724
13650
  return {
13725
13651
  type: "drop_type_enum",
@@ -15941,9 +15867,6 @@ var init_snapshotsDiffer = __esm({
15941
15867
  const jsonAlterEnumsWithAddedValues = typedResult.alteredEnums.map((it) => {
15942
15868
  return prepareAddValuesToEnumJson(it.name, it.schema, it.addedValues);
15943
15869
  }).flat() ?? [];
15944
- const jsonAlterEnumsWithDroppedValues = typedResult.alteredEnums.map((it) => {
15945
- return prepareDropEnumValues(it.name, it.schema, it.deletedValues, curFull);
15946
- }).flat() ?? [];
15947
15870
  const createSequences = createdSequences.map((it) => {
15948
15871
  return prepareCreateSequenceJson(it);
15949
15872
  }) ?? [];
@@ -16001,7 +15924,6 @@ var init_snapshotsDiffer = __esm({
16001
15924
  jsonStatements.push(...jsonAlteredCompositePKs);
16002
15925
  jsonStatements.push(...jsonAddedUniqueConstraints);
16003
15926
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16004
- jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
16005
15927
  jsonStatements.push(...dropEnums);
16006
15928
  jsonStatements.push(...dropSequences);
16007
15929
  jsonStatements.push(...dropSchemas);
package/api.mjs CHANGED
@@ -11680,7 +11680,7 @@ function fromJson(statements, dialect4, action, json22) {
11680
11680
  }).filter((it) => it !== "");
11681
11681
  return result;
11682
11682
  }
11683
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, 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;
11683
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
11684
11684
  var init_sqlgenerator = __esm({
11685
11685
  "src/sqlgenerator.ts"() {
11686
11686
  "use strict";
@@ -12061,22 +12061,20 @@ var init_sqlgenerator = __esm({
12061
12061
  }
12062
12062
  convert(st) {
12063
12063
  const { name: name2, values, schema: schema4 } = st;
12064
- const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12064
+ const tableNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12065
12065
  let valuesStatement = "(";
12066
12066
  valuesStatement += values.map((it) => `'${it}'`).join(", ");
12067
12067
  valuesStatement += ")";
12068
- let statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
12069
- return statement;
12070
- }
12071
- };
12072
- DropTypeEnumConvertor = class extends Convertor {
12073
- can(statement) {
12074
- return statement.type === "drop_type_enum";
12075
- }
12076
- convert(st) {
12077
- const { name: name2, schema: schema4 } = st;
12078
- const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12079
- let statement = `DROP TYPE ${enumNameWithSchema} CASCADE;`;
12068
+ let statement = "DO $$ BEGIN";
12069
+ statement += "\n";
12070
+ statement += ` CREATE TYPE ${tableNameWithSchema} AS ENUM${valuesStatement};`;
12071
+ statement += "\n";
12072
+ statement += "EXCEPTION";
12073
+ statement += "\n";
12074
+ statement += " WHEN duplicate_object THEN null;";
12075
+ statement += "\n";
12076
+ statement += "END $$;";
12077
+ statement += "\n";
12080
12078
  return statement;
12081
12079
  }
12082
12080
  };
@@ -12085,56 +12083,9 @@ var init_sqlgenerator = __esm({
12085
12083
  return statement.type === "alter_type_add_value";
12086
12084
  }
12087
12085
  convert(st) {
12088
- const { name: name2, schema: schema4, value, before } = st;
12089
- const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
12090
- return `ALTER TYPE ${enumNameWithSchema} ADD VALUE '${value}'${before.length ? ` BEFORE '${before}'` : ""};`;
12091
- }
12092
- };
12093
- AlterTypeSetSchemaConvertor = class extends Convertor {
12094
- can(statement) {
12095
- return statement.type === "move_type_enum";
12096
- }
12097
- convert(st) {
12098
- const { name: name2, schemaFrom, schemaTo } = st;
12099
- const enumNameWithSchema = schemaFrom ? `"${schemaFrom}"."${name2}"` : `"${name2}"`;
12100
- return `ALTER TYPE ${enumNameWithSchema} SET SCHEMA "${schemaTo}";`;
12101
- }
12102
- };
12103
- AlterRenameTypeConvertor = class extends Convertor {
12104
- can(statement) {
12105
- return statement.type === "rename_type_enum";
12106
- }
12107
- convert(st) {
12108
- const { nameTo, nameFrom, schema: schema4 } = st;
12109
- const enumNameWithSchema = schema4 ? `"${schema4}"."${nameFrom}"` : `"${nameFrom}"`;
12110
- return `ALTER TYPE ${enumNameWithSchema} RENAME TO "${nameTo}";`;
12111
- }
12112
- };
12113
- AlterTypeDropValueConvertor = class extends Convertor {
12114
- can(statement) {
12115
- return statement.type === "alter_type_drop_value";
12116
- }
12117
- convert(st) {
12118
- const { columnsWithEnum, name: name2, newValues, schema: schema4 } = st;
12119
- const statements = [];
12120
- for (const withEnum of columnsWithEnum) {
12121
- statements.push(
12122
- `ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE text;`
12123
- );
12124
- }
12125
- statements.push(new DropTypeEnumConvertor().convert({ name: name2, schema: schema4, type: "drop_type_enum" }));
12126
- statements.push(new CreateTypeEnumConvertor().convert({
12127
- name: name2,
12128
- schema: schema4,
12129
- values: newValues,
12130
- type: "create_type_enum"
12131
- }));
12132
- for (const withEnum of columnsWithEnum) {
12133
- statements.push(
12134
- `ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE "${schema4}"."${name2}" USING "${withEnum.column}"::"${schema4}"."${name2}";`
12135
- );
12136
- }
12137
- return statements;
12086
+ const { name: name2, schema: schema4, value } = st;
12087
+ const schemaPrefix = schema4 && schema4 !== "public" ? `"${schema4}".` : "";
12088
+ return `ALTER TYPE ${schemaPrefix}"${name2}" ADD VALUE '${value}';`;
12138
12089
  }
12139
12090
  };
12140
12091
  PgDropTableConvertor = class extends Convertor {
@@ -13278,11 +13229,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13278
13229
  convertors.push(new SQLiteRecreateTableConvertor());
13279
13230
  convertors.push(new LibSQLRecreateTableConvertor());
13280
13231
  convertors.push(new CreateTypeEnumConvertor());
13281
- convertors.push(new DropTypeEnumConvertor());
13282
- convertors.push(new AlterTypeAddValueConvertor());
13283
- convertors.push(new AlterTypeSetSchemaConvertor());
13284
- convertors.push(new AlterRenameTypeConvertor());
13285
- convertors.push(new AlterTypeDropValueConvertor());
13286
13232
  convertors.push(new CreatePgSequenceConvertor());
13287
13233
  convertors.push(new DropPgSequenceConvertor());
13288
13234
  convertors.push(new RenamePgSequenceConvertor());
@@ -13314,6 +13260,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13314
13260
  convertors.push(new PgDropIndexConvertor());
13315
13261
  convertors.push(new SqliteDropIndexConvertor());
13316
13262
  convertors.push(new MySqlDropIndexConvertor());
13263
+ convertors.push(new AlterTypeAddValueConvertor());
13317
13264
  convertors.push(new PgAlterTableAlterColumnSetPrimaryKeyConvertor());
13318
13265
  convertors.push(new PgAlterTableAlterColumnDropPrimaryKeyConvertor());
13319
13266
  convertors.push(new PgAlterTableAlterColumnSetNotNullConvertor());
@@ -13614,7 +13561,7 @@ var init_sqlitePushUtils = __esm({
13614
13561
  });
13615
13562
 
13616
13563
  // src/jsonStatements.ts
13617
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
13564
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
13618
13565
  var init_jsonStatements = __esm({
13619
13566
  "src/jsonStatements.ts"() {
13620
13567
  "use strict";
@@ -13704,27 +13651,6 @@ var init_jsonStatements = __esm({
13704
13651
  };
13705
13652
  });
13706
13653
  };
13707
- prepareDropEnumValues = (name2, schema4, removedValues, json22) => {
13708
- if (!removedValues.length) return [];
13709
- const affectedColumns = [];
13710
- for (const tableKey2 in json22.tables) {
13711
- const table4 = json22.tables[tableKey2];
13712
- for (const columnKey in table4.columns) {
13713
- const column4 = table4.columns[columnKey];
13714
- if (column4.type === name2 && column4.typeSchema === schema4) {
13715
- affectedColumns.push({ schema: table4.schema || "public", table: table4.name, column: column4.name });
13716
- }
13717
- }
13718
- }
13719
- return [{
13720
- type: "alter_type_drop_value",
13721
- name: name2,
13722
- schema: schema4,
13723
- deletedValues: removedValues,
13724
- newValues: json22.enums[`${schema4}.${name2}`].values,
13725
- columnsWithEnum: affectedColumns
13726
- }];
13727
- };
13728
13654
  prepareDropEnumJson = (name2, schema4) => {
13729
13655
  return {
13730
13656
  type: "drop_type_enum",
@@ -15946,9 +15872,6 @@ var init_snapshotsDiffer = __esm({
15946
15872
  const jsonAlterEnumsWithAddedValues = typedResult.alteredEnums.map((it) => {
15947
15873
  return prepareAddValuesToEnumJson(it.name, it.schema, it.addedValues);
15948
15874
  }).flat() ?? [];
15949
- const jsonAlterEnumsWithDroppedValues = typedResult.alteredEnums.map((it) => {
15950
- return prepareDropEnumValues(it.name, it.schema, it.deletedValues, curFull);
15951
- }).flat() ?? [];
15952
15875
  const createSequences = createdSequences.map((it) => {
15953
15876
  return prepareCreateSequenceJson(it);
15954
15877
  }) ?? [];
@@ -16006,7 +15929,6 @@ var init_snapshotsDiffer = __esm({
16006
15929
  jsonStatements.push(...jsonAlteredCompositePKs);
16007
15930
  jsonStatements.push(...jsonAddedUniqueConstraints);
16008
15931
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16009
- jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
16010
15932
  jsonStatements.push(...dropEnums);
16011
15933
  jsonStatements.push(...dropSequences);
16012
15934
  jsonStatements.push(...dropSchemas);
package/bin.cjs CHANGED
@@ -23105,7 +23105,7 @@ function fromJson(statements, dialect4, action, json2) {
23105
23105
  }).filter((it) => it !== "");
23106
23106
  return result;
23107
23107
  }
23108
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, 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;
23108
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
23109
23109
  var init_sqlgenerator = __esm({
23110
23110
  "src/sqlgenerator.ts"() {
23111
23111
  "use strict";
@@ -23489,22 +23489,20 @@ var init_sqlgenerator = __esm({
23489
23489
  }
23490
23490
  convert(st) {
23491
23491
  const { name, values, schema: schema5 } = st;
23492
- const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
23492
+ const tableNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
23493
23493
  let valuesStatement = "(";
23494
23494
  valuesStatement += values.map((it) => `'${it}'`).join(", ");
23495
23495
  valuesStatement += ")";
23496
- let statement = `CREATE TYPE ${enumNameWithSchema} AS ENUM${valuesStatement};`;
23497
- return statement;
23498
- }
23499
- };
23500
- DropTypeEnumConvertor = class extends Convertor {
23501
- can(statement) {
23502
- return statement.type === "drop_type_enum";
23503
- }
23504
- convert(st) {
23505
- const { name, schema: schema5 } = st;
23506
- const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
23507
- let statement = `DROP TYPE ${enumNameWithSchema} CASCADE;`;
23496
+ let statement = "DO $$ BEGIN";
23497
+ statement += "\n";
23498
+ statement += ` CREATE TYPE ${tableNameWithSchema} AS ENUM${valuesStatement};`;
23499
+ statement += "\n";
23500
+ statement += "EXCEPTION";
23501
+ statement += "\n";
23502
+ statement += " WHEN duplicate_object THEN null;";
23503
+ statement += "\n";
23504
+ statement += "END $$;";
23505
+ statement += "\n";
23508
23506
  return statement;
23509
23507
  }
23510
23508
  };
@@ -23513,56 +23511,9 @@ var init_sqlgenerator = __esm({
23513
23511
  return statement.type === "alter_type_add_value";
23514
23512
  }
23515
23513
  convert(st) {
23516
- const { name, schema: schema5, value, before } = st;
23517
- const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
23518
- return `ALTER TYPE ${enumNameWithSchema} ADD VALUE '${value}'${before.length ? ` BEFORE '${before}'` : ""};`;
23519
- }
23520
- };
23521
- AlterTypeSetSchemaConvertor = class extends Convertor {
23522
- can(statement) {
23523
- return statement.type === "move_type_enum";
23524
- }
23525
- convert(st) {
23526
- const { name, schemaFrom, schemaTo } = st;
23527
- const enumNameWithSchema = schemaFrom ? `"${schemaFrom}"."${name}"` : `"${name}"`;
23528
- return `ALTER TYPE ${enumNameWithSchema} SET SCHEMA "${schemaTo}";`;
23529
- }
23530
- };
23531
- AlterRenameTypeConvertor = class extends Convertor {
23532
- can(statement) {
23533
- return statement.type === "rename_type_enum";
23534
- }
23535
- convert(st) {
23536
- const { nameTo, nameFrom, schema: schema5 } = st;
23537
- const enumNameWithSchema = schema5 ? `"${schema5}"."${nameFrom}"` : `"${nameFrom}"`;
23538
- return `ALTER TYPE ${enumNameWithSchema} RENAME TO "${nameTo}";`;
23539
- }
23540
- };
23541
- AlterTypeDropValueConvertor = class extends Convertor {
23542
- can(statement) {
23543
- return statement.type === "alter_type_drop_value";
23544
- }
23545
- convert(st) {
23546
- const { columnsWithEnum, name, newValues, schema: schema5 } = st;
23547
- const statements = [];
23548
- for (const withEnum of columnsWithEnum) {
23549
- statements.push(
23550
- `ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE text;`
23551
- );
23552
- }
23553
- statements.push(new DropTypeEnumConvertor().convert({ name, schema: schema5, type: "drop_type_enum" }));
23554
- statements.push(new CreateTypeEnumConvertor().convert({
23555
- name,
23556
- schema: schema5,
23557
- values: newValues,
23558
- type: "create_type_enum"
23559
- }));
23560
- for (const withEnum of columnsWithEnum) {
23561
- statements.push(
23562
- `ALTER TABLE "${withEnum.schema}"."${withEnum.table}" ALTER COLUMN "${withEnum.column}" SET DATA TYPE "${schema5}"."${name}" USING "${withEnum.column}"::"${schema5}"."${name}";`
23563
- );
23564
- }
23565
- return statements;
23514
+ const { name, schema: schema5, value } = st;
23515
+ const schemaPrefix = schema5 && schema5 !== "public" ? `"${schema5}".` : "";
23516
+ return `ALTER TYPE ${schemaPrefix}"${name}" ADD VALUE '${value}';`;
23566
23517
  }
23567
23518
  };
23568
23519
  PgDropTableConvertor = class extends Convertor {
@@ -24709,11 +24660,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24709
24660
  convertors.push(new SQLiteRecreateTableConvertor());
24710
24661
  convertors.push(new LibSQLRecreateTableConvertor());
24711
24662
  convertors.push(new CreateTypeEnumConvertor());
24712
- convertors.push(new DropTypeEnumConvertor());
24713
- convertors.push(new AlterTypeAddValueConvertor());
24714
- convertors.push(new AlterTypeSetSchemaConvertor());
24715
- convertors.push(new AlterRenameTypeConvertor());
24716
- convertors.push(new AlterTypeDropValueConvertor());
24717
24663
  convertors.push(new CreatePgSequenceConvertor());
24718
24664
  convertors.push(new DropPgSequenceConvertor());
24719
24665
  convertors.push(new RenamePgSequenceConvertor());
@@ -24745,6 +24691,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24745
24691
  convertors.push(new PgDropIndexConvertor());
24746
24692
  convertors.push(new SqliteDropIndexConvertor());
24747
24693
  convertors.push(new MySqlDropIndexConvertor());
24694
+ convertors.push(new AlterTypeAddValueConvertor());
24748
24695
  convertors.push(new PgAlterTableAlterColumnSetPrimaryKeyConvertor());
24749
24696
  convertors.push(new PgAlterTableAlterColumnDropPrimaryKeyConvertor());
24750
24697
  convertors.push(new PgAlterTableAlterColumnSetNotNullConvertor());
@@ -25046,7 +24993,7 @@ var init_sqlitePushUtils = __esm({
25046
24993
  });
25047
24994
 
25048
24995
  // src/jsonStatements.ts
25049
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
24996
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
25050
24997
  var init_jsonStatements = __esm({
25051
24998
  "src/jsonStatements.ts"() {
25052
24999
  "use strict";
@@ -25136,28 +25083,6 @@ var init_jsonStatements = __esm({
25136
25083
  };
25137
25084
  });
25138
25085
  };
25139
- prepareDropEnumValues = (name, schema5, removedValues, json2) => {
25140
- if (!removedValues.length)
25141
- return [];
25142
- const affectedColumns = [];
25143
- for (const tableKey2 in json2.tables) {
25144
- const table4 = json2.tables[tableKey2];
25145
- for (const columnKey in table4.columns) {
25146
- const column7 = table4.columns[columnKey];
25147
- if (column7.type === name && column7.typeSchema === schema5) {
25148
- affectedColumns.push({ schema: table4.schema || "public", table: table4.name, column: column7.name });
25149
- }
25150
- }
25151
- }
25152
- return [{
25153
- type: "alter_type_drop_value",
25154
- name,
25155
- schema: schema5,
25156
- deletedValues: removedValues,
25157
- newValues: json2.enums[`${schema5}.${name}`].values,
25158
- columnsWithEnum: affectedColumns
25159
- }];
25160
- };
25161
25086
  prepareDropEnumJson = (name, schema5) => {
25162
25087
  return {
25163
25088
  type: "drop_type_enum",
@@ -27351,9 +27276,6 @@ var init_snapshotsDiffer = __esm({
27351
27276
  const jsonAlterEnumsWithAddedValues = typedResult.alteredEnums.map((it) => {
27352
27277
  return prepareAddValuesToEnumJson(it.name, it.schema, it.addedValues);
27353
27278
  }).flat() ?? [];
27354
- const jsonAlterEnumsWithDroppedValues = typedResult.alteredEnums.map((it) => {
27355
- return prepareDropEnumValues(it.name, it.schema, it.deletedValues, curFull);
27356
- }).flat() ?? [];
27357
27279
  const createSequences = createdSequences.map((it) => {
27358
27280
  return prepareCreateSequenceJson(it);
27359
27281
  }) ?? [];
@@ -27411,7 +27333,6 @@ var init_snapshotsDiffer = __esm({
27411
27333
  jsonStatements.push(...jsonAlteredCompositePKs);
27412
27334
  jsonStatements.push(...jsonAddedUniqueConstraints);
27413
27335
  jsonStatements.push(...jsonAlteredUniqueConstraints);
27414
- jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
27415
27336
  jsonStatements.push(...dropEnums);
27416
27337
  jsonStatements.push(...dropSequences);
27417
27338
  jsonStatements.push(...dropSchemas);
@@ -85433,7 +85354,7 @@ init_utils2();
85433
85354
  var version2 = async () => {
85434
85355
  const { npmVersion } = await ormCoreVersions();
85435
85356
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
85436
- const envVersion = "0.25.0-1f15bfd";
85357
+ const envVersion = "0.25.0-26155b0";
85437
85358
  const kitVersion = envVersion ? `v${envVersion}` : "--";
85438
85359
  const versions = `drizzle-kit: ${kitVersion}
85439
85360
  ${ormVersion}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.25.0-1f15bfd",
3
+ "version": "0.25.0-26155b0",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",