drizzle-kit 0.30.0-e14a5a2 → 0.30.1-019d9b0

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 +323 -209
  2. package/api.mjs +323 -209
  3. package/bin.cjs +211 -8
  4. package/package.json +1 -1
package/bin.cjs CHANGED
@@ -28892,7 +28892,8 @@ var init_common = __esm({
28892
28892
  schemaFilter: unionType([stringType(), stringType().array()]).default(["public"]),
28893
28893
  migrations: configMigrations,
28894
28894
  dbCredentials: anyType().optional(),
28895
- casing: casingType.optional()
28895
+ casing: casingType.optional(),
28896
+ sql: booleanType().default(true)
28896
28897
  }).passthrough();
28897
28898
  casing = unionType([literalType("camel"), literalType("preserve")]).default(
28898
28899
  "camel"
@@ -34995,7 +34996,7 @@ var require_node2 = __commonJS({
34995
34996
  });
34996
34997
 
34997
34998
  // src/cli/commands/utils.ts
34998
- var import_fs3, import_hanji2, import_path3, assertES5, safeRegister, prepareCheckParams, prepareDropParams, prepareGenerateConfig, flattenDatabaseCredentials, flattenPull, preparePushConfig, preparePullConfig, prepareStudioConfig, migrateConfig, prepareMigrateConfig, drizzleConfigFromFile;
34999
+ var import_fs3, import_hanji2, import_path3, assertES5, safeRegister, prepareCheckParams, prepareDropParams, prepareGenerateConfig, prepareExportConfig, flattenDatabaseCredentials, flattenPull, preparePushConfig, preparePullConfig, prepareStudioConfig, migrateConfig, prepareMigrateConfig, drizzleConfigFromFile;
34999
35000
  var init_utils3 = __esm({
35000
35001
  "src/cli/commands/utils.ts"() {
35001
35002
  "use strict";
@@ -35104,6 +35105,26 @@ var init_utils3 = __esm({
35104
35105
  driver: driver2
35105
35106
  };
35106
35107
  };
35108
+ prepareExportConfig = async (options, from) => {
35109
+ const config = from === "config" ? await drizzleConfigFromFile(options.config, true) : options;
35110
+ const { schema: schema6, dialect: dialect6, sql } = config;
35111
+ if (!schema6 || !dialect6) {
35112
+ console.log(error("Please provide required params:"));
35113
+ console.log(wrapParam("schema", schema6));
35114
+ console.log(wrapParam("dialect", dialect6));
35115
+ process.exit(1);
35116
+ }
35117
+ const fileNames = prepareFilenames(schema6);
35118
+ if (fileNames.length === 0) {
35119
+ (0, import_hanji2.render)(`[${source_default.blue("i")}] No schema file in ${schema6} was found`);
35120
+ process.exit(0);
35121
+ }
35122
+ return {
35123
+ dialect: dialect6,
35124
+ schema: schema6,
35125
+ sql
35126
+ };
35127
+ };
35107
35128
  flattenDatabaseCredentials = (config) => {
35108
35129
  if ("dbCredentials" in config) {
35109
35130
  const { dbCredentials, ...rest } = config;
@@ -35544,7 +35565,7 @@ var init_utils3 = __esm({
35544
35565
  }
35545
35566
  assertUnreachable(dialect6);
35546
35567
  };
35547
- drizzleConfigFromFile = async (configPath) => {
35568
+ drizzleConfigFromFile = async (configPath, isExport) => {
35548
35569
  const prefix2 = process.env.TEST_CONFIG_PATH_PREFIX || "";
35549
35570
  const defaultTsConfigExists = (0, import_fs3.existsSync)((0, import_path3.resolve)((0, import_path3.join)(prefix2, "drizzle.config.ts")));
35550
35571
  const defaultJsConfigExists = (0, import_fs3.existsSync)((0, import_path3.resolve)((0, import_path3.join)(prefix2, "drizzle.config.js")));
@@ -35552,7 +35573,7 @@ var init_utils3 = __esm({
35552
35573
  (0, import_path3.join)((0, import_path3.resolve)("drizzle.config.json"))
35553
35574
  );
35554
35575
  const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
35555
- if (!configPath) {
35576
+ if (!configPath && !isExport) {
35556
35577
  console.log(
35557
35578
  source_default.gray(
35558
35579
  `No config path provided, using default '${defaultConfigPath}'`
@@ -35564,7 +35585,8 @@ var init_utils3 = __esm({
35564
35585
  console.log(`${path5} file does not exist`);
35565
35586
  process.exit(1);
35566
35587
  }
35567
- console.log(source_default.grey(`Reading config file '${path5}'`));
35588
+ if (!isExport)
35589
+ console.log(source_default.grey(`Reading config file '${path5}'`));
35568
35590
  const { unregister } = await safeRegister();
35569
35591
  const required = require(`${path5}`);
35570
35592
  const content = required.default ?? required;
@@ -51418,6 +51440,11 @@ __export(migrate_exports, {
51418
51440
  indPolicyResolver: () => indPolicyResolver,
51419
51441
  mySqlViewsResolver: () => mySqlViewsResolver,
51420
51442
  policyResolver: () => policyResolver,
51443
+ prepareAndExportLibSQL: () => prepareAndExportLibSQL,
51444
+ prepareAndExportMysql: () => prepareAndExportMysql,
51445
+ prepareAndExportPg: () => prepareAndExportPg,
51446
+ prepareAndExportSinglestore: () => prepareAndExportSinglestore,
51447
+ prepareAndExportSqlite: () => prepareAndExportSqlite,
51421
51448
  prepareAndMigrateLibSQL: () => prepareAndMigrateLibSQL,
51422
51449
  prepareAndMigrateMysql: () => prepareAndMigrateMysql,
51423
51450
  prepareAndMigratePg: () => prepareAndMigratePg,
@@ -51441,7 +51468,7 @@ __export(migrate_exports, {
51441
51468
  viewsResolver: () => viewsResolver,
51442
51469
  writeResult: () => writeResult
51443
51470
  });
51444
- var import_fs6, import_hanji3, import_path5, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, roleResolver, policyResolver, indPolicyResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareSingleStorePush, prepareAndMigrateSingleStore, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
51471
+ var import_fs6, import_hanji3, import_path5, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, roleResolver, policyResolver, indPolicyResolver, enumsResolver, columnsResolver, prepareAndMigratePg, prepareAndExportPg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareSingleStorePush, prepareAndMigrateSingleStore, prepareAndExportSinglestore, prepareAndExportMysql, prepareAndMigrateSqlite, prepareAndExportSqlite, prepareAndMigrateLibSQL, prepareAndExportLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedConflict, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
51445
51472
  var init_migrate = __esm({
51446
51473
  "src/cli/commands/migrate.ts"() {
51447
51474
  "use strict";
@@ -51691,6 +51718,39 @@ var init_migrate = __esm({
51691
51718
  console.error(e2);
51692
51719
  }
51693
51720
  };
51721
+ prepareAndExportPg = async (config) => {
51722
+ const schemaPath = config.schema;
51723
+ try {
51724
+ const { prev, cur } = await preparePgMigrationSnapshot(
51725
+ [],
51726
+ // no snapshots before
51727
+ schemaPath,
51728
+ void 0
51729
+ );
51730
+ const validatedPrev = pgSchema.parse(prev);
51731
+ const validatedCur = pgSchema.parse(cur);
51732
+ const squashedPrev = squashPgScheme(validatedPrev);
51733
+ const squashedCur = squashPgScheme(validatedCur);
51734
+ const { sqlStatements } = await applyPgSnapshotsDiff(
51735
+ squashedPrev,
51736
+ squashedCur,
51737
+ schemasResolver,
51738
+ enumsResolver,
51739
+ sequencesResolver,
51740
+ policyResolver,
51741
+ indPolicyResolver,
51742
+ roleResolver,
51743
+ tablesResolver,
51744
+ columnsResolver,
51745
+ viewsResolver,
51746
+ validatedPrev,
51747
+ validatedCur
51748
+ );
51749
+ console.log(sqlStatements.join("\n"));
51750
+ } catch (e2) {
51751
+ console.error(e2);
51752
+ }
51753
+ };
51694
51754
  preparePgPush = async (cur, prev) => {
51695
51755
  const validatedPrev = pgSchema.parse(prev);
51696
51756
  const validatedCur = pgSchema.parse(cur);
@@ -51872,6 +51932,58 @@ var init_migrate = __esm({
51872
51932
  console.error(e2);
51873
51933
  }
51874
51934
  };
51935
+ prepareAndExportSinglestore = async (config) => {
51936
+ const schemaPath = config.schema;
51937
+ try {
51938
+ const { prev, cur } = await prepareSingleStoreMigrationSnapshot(
51939
+ [],
51940
+ schemaPath,
51941
+ void 0
51942
+ );
51943
+ const validatedPrev = singlestoreSchema.parse(prev);
51944
+ const validatedCur = singlestoreSchema.parse(cur);
51945
+ const squashedPrev = squashSingleStoreScheme(validatedPrev);
51946
+ const squashedCur = squashSingleStoreScheme(validatedCur);
51947
+ const { sqlStatements, _meta } = await applySingleStoreSnapshotsDiff(
51948
+ squashedPrev,
51949
+ squashedCur,
51950
+ tablesResolver,
51951
+ columnsResolver,
51952
+ /* singleStoreViewsResolver, */
51953
+ validatedPrev,
51954
+ validatedCur
51955
+ );
51956
+ console.log(sqlStatements.join("\n"));
51957
+ } catch (e2) {
51958
+ console.error(e2);
51959
+ }
51960
+ };
51961
+ prepareAndExportMysql = async (config) => {
51962
+ const schemaPath = config.schema;
51963
+ try {
51964
+ const { prev, cur, custom: custom2 } = await prepareMySqlMigrationSnapshot(
51965
+ [],
51966
+ schemaPath,
51967
+ void 0
51968
+ );
51969
+ const validatedPrev = mysqlSchema.parse(prev);
51970
+ const validatedCur = mysqlSchema.parse(cur);
51971
+ const squashedPrev = squashMysqlScheme(validatedPrev);
51972
+ const squashedCur = squashMysqlScheme(validatedCur);
51973
+ const { sqlStatements, statements, _meta } = await applyMysqlSnapshotsDiff(
51974
+ squashedPrev,
51975
+ squashedCur,
51976
+ tablesResolver,
51977
+ columnsResolver,
51978
+ mySqlViewsResolver,
51979
+ validatedPrev,
51980
+ validatedCur
51981
+ );
51982
+ console.log(sqlStatements.join("\n"));
51983
+ } catch (e2) {
51984
+ console.error(e2);
51985
+ }
51986
+ };
51875
51987
  prepareAndMigrateSqlite = async (config) => {
51876
51988
  const outFolder = config.out;
51877
51989
  const schemaPath = config.schema;
@@ -51927,6 +52039,32 @@ var init_migrate = __esm({
51927
52039
  console.error(e2);
51928
52040
  }
51929
52041
  };
52042
+ prepareAndExportSqlite = async (config) => {
52043
+ const schemaPath = config.schema;
52044
+ try {
52045
+ const { prev, cur } = await prepareSqliteMigrationSnapshot(
52046
+ [],
52047
+ schemaPath,
52048
+ void 0
52049
+ );
52050
+ const validatedPrev = sqliteSchema.parse(prev);
52051
+ const validatedCur = sqliteSchema.parse(cur);
52052
+ const squashedPrev = squashSqliteScheme(validatedPrev);
52053
+ const squashedCur = squashSqliteScheme(validatedCur);
52054
+ const { sqlStatements, _meta } = await applySqliteSnapshotsDiff(
52055
+ squashedPrev,
52056
+ squashedCur,
52057
+ tablesResolver,
52058
+ columnsResolver,
52059
+ sqliteViewsResolver,
52060
+ validatedPrev,
52061
+ validatedCur
52062
+ );
52063
+ console.log(sqlStatements.join("\n"));
52064
+ } catch (e2) {
52065
+ console.error(e2);
52066
+ }
52067
+ };
51930
52068
  prepareAndMigrateLibSQL = async (config) => {
51931
52069
  const outFolder = config.out;
51932
52070
  const schemaPath = config.schema;
@@ -51981,6 +52119,32 @@ var init_migrate = __esm({
51981
52119
  console.error(e2);
51982
52120
  }
51983
52121
  };
52122
+ prepareAndExportLibSQL = async (config) => {
52123
+ const schemaPath = config.schema;
52124
+ try {
52125
+ const { prev, cur, custom: custom2 } = await prepareSqliteMigrationSnapshot(
52126
+ [],
52127
+ schemaPath,
52128
+ void 0
52129
+ );
52130
+ const validatedPrev = sqliteSchema.parse(prev);
52131
+ const validatedCur = sqliteSchema.parse(cur);
52132
+ const squashedPrev = squashSqliteScheme(validatedPrev);
52133
+ const squashedCur = squashSqliteScheme(validatedCur);
52134
+ const { sqlStatements, _meta } = await applyLibSQLSnapshotsDiff(
52135
+ squashedPrev,
52136
+ squashedCur,
52137
+ tablesResolver,
52138
+ columnsResolver,
52139
+ sqliteViewsResolver,
52140
+ validatedPrev,
52141
+ validatedCur
52142
+ );
52143
+ console.log(sqlStatements.join("\n"));
52144
+ } catch (e2) {
52145
+ console.error(e2);
52146
+ }
52147
+ };
51984
52148
  prepareSQLitePush = async (schemaPath, snapshot, casing2) => {
51985
52149
  const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath, casing2);
51986
52150
  const validatedPrev = sqliteSchema.parse(prev);
@@ -92400,13 +92564,52 @@ Drizzle Studio is up and running on ${source_default.blue(
92400
92564
  }
92401
92565
  }
92402
92566
  });
92567
+ var exportRaw = command2({
92568
+ name: "export",
92569
+ desc: "Generate diff between current state and empty state in specified formats: sql",
92570
+ options: {
92571
+ sql: boolean("sql").default(true).desc("Generate as sql"),
92572
+ config: optionConfig,
92573
+ dialect: optionDialect,
92574
+ schema: string().desc("Path to a schema file or folder")
92575
+ },
92576
+ transform: async (opts) => {
92577
+ const from = assertCollisions("export", opts, ["sql"], ["dialect", "schema"]);
92578
+ return prepareExportConfig(opts, from);
92579
+ },
92580
+ handler: async (opts) => {
92581
+ await assertOrmCoreVersion();
92582
+ await assertPackages("drizzle-orm");
92583
+ const {
92584
+ prepareAndExportPg: prepareAndExportPg2,
92585
+ prepareAndExportMysql: prepareAndExportMysql2,
92586
+ prepareAndExportSqlite: prepareAndExportSqlite2,
92587
+ prepareAndExportLibSQL: prepareAndExportLibSQL2,
92588
+ prepareAndExportSinglestore: prepareAndExportSinglestore2
92589
+ } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
92590
+ const dialect6 = opts.dialect;
92591
+ if (dialect6 === "postgresql") {
92592
+ await prepareAndExportPg2(opts);
92593
+ } else if (dialect6 === "mysql") {
92594
+ await prepareAndExportMysql2(opts);
92595
+ } else if (dialect6 === "sqlite") {
92596
+ await prepareAndExportSqlite2(opts);
92597
+ } else if (dialect6 === "turso") {
92598
+ await prepareAndExportLibSQL2(opts);
92599
+ } else if (dialect6 === "singlestore") {
92600
+ await prepareAndExportSinglestore2(opts);
92601
+ } else {
92602
+ assertUnreachable(dialect6);
92603
+ }
92604
+ }
92605
+ });
92403
92606
 
92404
92607
  // src/cli/index.ts
92405
92608
  init_utils5();
92406
92609
  var version2 = async () => {
92407
92610
  const { npmVersion } = await ormCoreVersions();
92408
92611
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
92409
- const envVersion = "0.30.0-e14a5a2";
92612
+ const envVersion = "0.30.1-019d9b0";
92410
92613
  const kitVersion = envVersion ? `v${envVersion}` : "--";
92411
92614
  const versions = `drizzle-kit: ${kitVersion}
92412
92615
  ${ormVersion}`;
@@ -92440,7 +92643,7 @@ var legacy = [
92440
92643
  legacyCommand("check:mysql", "check"),
92441
92644
  legacyCommand("check:sqlite", "check")
92442
92645
  ];
92443
- run([generate, migrate, pull, push, studio, up, check, drop, ...legacy], {
92646
+ run([generate, migrate, pull, push, studio, up, check, drop, exportRaw, ...legacy], {
92444
92647
  name: "drizzle-kit",
92445
92648
  version: version2
92446
92649
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.30.0-e14a5a2",
3
+ "version": "0.30.1-019d9b0",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",