drizzle-kit 0.20.0-50d6b73 → 0.20.0-572b8ee

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  import type { PgConfigIntrospect } from "../validations/pg";
2
2
  import type { DrizzleDbClient } from "src/drivers";
3
+ export declare const pgSchemas: (client: DrizzleDbClient) => Promise<string[]>;
3
4
  export declare const pgPushIntrospect: (connection: {
4
5
  client: DrizzleDbClient;
5
6
  }, filters: string[], schemaFilters: string[]) => Promise<{
@@ -1,6 +1,6 @@
1
- import { Client } from "@libsql/client";
2
- import { PgDatabase } from "drizzle-orm/pg-core";
3
- import { Client as PgClient } from "pg";
1
+ import type { Client } from "@libsql/client";
2
+ import type { PgDatabase } from "drizzle-orm/pg-core";
3
+ import type { Client as PgClient } from "pg";
4
4
  export declare abstract class DrizzleDbClient<T = any> {
5
5
  protected db: T;
6
6
  constructor(db: T);
package/index.cjs CHANGED
@@ -12701,7 +12701,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12701
12701
  }
12702
12702
  }
12703
12703
  };
12704
- toDrizzle = (schema4) => {
12704
+ toDrizzle = (schema4, schemaName) => {
12705
12705
  const tables = {};
12706
12706
  Object.values(schema4.tables).forEach((t) => {
12707
12707
  const columns = {};
@@ -12775,17 +12775,31 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12775
12775
  }
12776
12776
  columns[columnName] = columnBuilder;
12777
12777
  });
12778
- tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
12779
- const res = {};
12780
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12781
- const gh = cpk.columns.map((c) => cb[c]);
12782
- res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12783
- gh,
12784
- cpk.name
12785
- );
12778
+ if (schemaName === "public") {
12779
+ tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
12780
+ const res = {};
12781
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12782
+ const gh = cpk.columns.map((c) => cb[c]);
12783
+ res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12784
+ gh,
12785
+ cpk.name
12786
+ );
12787
+ });
12788
+ return res;
12786
12789
  });
12787
- return res;
12788
- });
12790
+ } else {
12791
+ tables[t.name] = (0, import_pg_core2.pgSchema)(schemaName).table(t.name, columns, (cb) => {
12792
+ const res = {};
12793
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12794
+ const gh = cpk.columns.map((c) => cb[c]);
12795
+ res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12796
+ gh,
12797
+ cpk.name
12798
+ );
12799
+ });
12800
+ return res;
12801
+ });
12802
+ }
12789
12803
  });
12790
12804
  return tables;
12791
12805
  };
@@ -25262,9 +25276,10 @@ var init_pgConnect = __esm({
25262
25276
  var pgIntrospect_exports = {};
25263
25277
  __export(pgIntrospect_exports, {
25264
25278
  pgIntrospect: () => pgIntrospect,
25265
- pgPushIntrospect: () => pgPushIntrospect
25279
+ pgPushIntrospect: () => pgPushIntrospect,
25280
+ pgSchemas: () => pgSchemas
25266
25281
  });
25267
- var import_hanji4, pgPushIntrospect, pgIntrospect;
25282
+ var import_hanji4, pgSchemas, pgPushIntrospect, pgIntrospect;
25268
25283
  var init_pgIntrospect = __esm({
25269
25284
  "src/cli/commands/pgIntrospect.ts"() {
25270
25285
  import_hanji4 = __toESM(require_hanji());
@@ -25273,6 +25288,18 @@ var init_pgIntrospect = __esm({
25273
25288
  init_introspect();
25274
25289
  init_global();
25275
25290
  init_mjs();
25291
+ pgSchemas = async (client) => {
25292
+ const res = await client.query(`select s.nspname as table_schema,
25293
+ s.oid as schema_id,
25294
+ u.usename as owner
25295
+ from pg_catalog.pg_namespace s
25296
+ join pg_catalog.pg_user u on u.usesysid = s.nspowner
25297
+ where nspname not in ('information_schema', 'pg_catalog')
25298
+ and nspname not like 'pg_toast%'
25299
+ and nspname not like 'pg_temp_%'
25300
+ order by table_schema;`);
25301
+ return res.map((it) => it["table_schema"]);
25302
+ };
25276
25303
  pgPushIntrospect = async (connection, filters, schemaFilters) => {
25277
25304
  const { client } = connection;
25278
25305
  const matchers = filters.map((it) => {
@@ -58014,7 +58041,7 @@ var init_studioUtils = __esm({
58014
58041
  prepareModels = async (path4) => {
58015
58042
  const imports = prepareFilenames(path4);
58016
58043
  const sqliteSchema2 = {};
58017
- const pgSchema3 = {};
58044
+ const pgSchema4 = {};
58018
58045
  const mysqlSchema4 = {};
58019
58046
  const { unregister } = await safeRegister();
58020
58047
  for (let i = 0; i < imports.length; i++) {
@@ -58023,7 +58050,7 @@ var init_studioUtils = __esm({
58023
58050
  const i0values = Object.entries(i0);
58024
58051
  i0values.forEach(([k, t]) => {
58025
58052
  if ((0, import_drizzle_orm14.is)(t, import_pg_core4.PgTable)) {
58026
- pgSchema3[k] = t;
58053
+ pgSchema4[k] = t;
58027
58054
  }
58028
58055
  if ((0, import_drizzle_orm14.is)(t, import_mysql_core4.MySqlTable)) {
58029
58056
  mysqlSchema4[k] = t;
@@ -58033,22 +58060,19 @@ var init_studioUtils = __esm({
58033
58060
  }
58034
58061
  if ((0, import_drizzle_orm14.is)(t, import_drizzle_orm14.Relations)) {
58035
58062
  sqliteSchema2[k] = t;
58036
- pgSchema3[k] = t;
58063
+ pgSchema4[k] = t;
58037
58064
  mysqlSchema4[k] = t;
58038
58065
  }
58039
58066
  });
58040
58067
  }
58041
58068
  unregister();
58042
- return { pgSchema: pgSchema3, mysqlSchema: mysqlSchema4, sqliteSchema: sqliteSchema2 };
58069
+ return { pgSchema: pgSchema4, mysqlSchema: mysqlSchema4, sqliteSchema: sqliteSchema2 };
58043
58070
  };
58044
- drizzleDb = async (drizzleConfig, models, logger) => {
58071
+ drizzleDb = async (drizzleConfig, models, logger, pgClient) => {
58045
58072
  if (drizzleConfig.driver === "pg") {
58046
58073
  const { drizzle: drizzle2 } = await import("drizzle-orm/node-postgres");
58047
- const { Pool, types } = await Promise.resolve().then(() => __toESM(require_lib2()));
58048
- const client = new Pool({ ...drizzleConfig.dbCredentials, max: 1 });
58049
- types.setTypeParser(types.builtins.INTERVAL, (val) => val);
58050
58074
  return {
58051
- db: drizzle2(client, { logger }),
58075
+ db: drizzle2(pgClient, { logger }),
58052
58076
  type: "pg",
58053
58077
  schema: models.pgSchema
58054
58078
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.20.0-50d6b73",
3
+ "version": "0.20.0-572b8ee",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
@@ -1,9 +1,9 @@
1
1
  import { AnyPgTable, PgEnum, PgSchema } from "drizzle-orm/pg-core";
2
2
  import { Relations } from "drizzle-orm";
3
- import type { IntrospectStage, IntrospectStatus } from "src/cli/views";
4
- import type { PgSchemaInternal } from "src/serializer/pgSchema";
5
- import type { DrizzleDbClient } from "src/drivers";
3
+ import type { IntrospectStage, IntrospectStatus } from "../cli/views";
4
+ import type { PgSchemaInternal } from "../serializer/pgSchema";
5
+ import type { DrizzleDbClient } from "../drivers";
6
6
  export declare const indexName: (tableName: string, columns: string[]) => string;
7
7
  export declare const generatePgSnapshot: (tables: AnyPgTable[], enums: PgEnum<any>[], schemas: PgSchema[], schemaFilter?: string[]) => PgSchemaInternal;
8
8
  export declare const fromDatabase: (db: DrizzleDbClient, tablesFilter: ((table: string) => boolean) | undefined, schemaFilters: string[], progressCallback?: ((stage: IntrospectStage, count: number, status: IntrospectStatus) => void) | undefined) => Promise<PgSchemaInternal>;
9
- export declare const toDrizzle: (schema: PgSchemaInternal) => Record<string, AnyPgTable | Relations>;
9
+ export declare const toDrizzle: (schema: PgSchemaInternal, schemaName: string) => Record<string, AnyPgTable | Relations>;
@@ -2,6 +2,7 @@ import { Relations } from "drizzle-orm";
2
2
  import { AnyMySqlTable } from "drizzle-orm/mysql-core";
3
3
  import { AnyPgTable } from "drizzle-orm/pg-core";
4
4
  import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
5
+ import type { Pool } from "pg";
5
6
  import { StudioConfigConnections } from "src/cli/validations/studio";
6
7
  export declare const prepareModels: (path: string | string[]) => Promise<{
7
8
  pgSchema: Record<string, AnyPgTable<{}> | Relations<string, Record<string, import("drizzle-orm").Relation<string>>>>;
@@ -12,7 +13,7 @@ export declare const drizzleDb: (drizzleConfig: StudioConfigConnections, models:
12
13
  pgSchema?: Record<string, AnyPgTable | Relations>;
13
14
  mysqlSchema?: Record<string, AnyMySqlTable | Relations>;
14
15
  sqliteSchema?: Record<string, AnySQLiteTable | Relations>;
15
- }, logger: boolean) => Promise<{
16
+ }, logger: boolean, pgClient?: Pool) => Promise<{
16
17
  db: import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>>;
17
18
  type: "pg";
18
19
  schema: Record<string, AnyPgTable<{}> | Relations<string, Record<string, import("drizzle-orm").Relation<string>>>> | undefined;
package/utils-studio.d.ts CHANGED
@@ -2,3 +2,4 @@ export { toDrizzle as drizzleSchemaPg } from "./serializer/pgSerializer";
2
2
  export { toDrizzle as drizzleSchemaSQLite } from "./serializer/sqliteSerializer";
3
3
  export { sqlitePushIntrospect } from "./cli/commands/sqliteIntrospect";
4
4
  export { pgPushIntrospect } from "./cli/commands/pgIntrospect";
5
+ export { DrizzleORMPgClient } from "./drivers";
package/utils-studio.js CHANGED
@@ -967,7 +967,7 @@ var init_pgSerializer = __esm({
967
967
  }
968
968
  }
969
969
  };
970
- toDrizzle = (schema) => {
970
+ toDrizzle = (schema, schemaName) => {
971
971
  const tables = {};
972
972
  Object.values(schema.tables).forEach((t) => {
973
973
  const columns = {};
@@ -1041,17 +1041,31 @@ var init_pgSerializer = __esm({
1041
1041
  }
1042
1042
  columns[columnName] = columnBuilder;
1043
1043
  });
1044
- tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
1045
- const res = {};
1046
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1047
- const gh = cpk.columns.map((c) => cb[c]);
1048
- res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1049
- gh,
1050
- cpk.name
1051
- );
1044
+ if (schemaName === "public") {
1045
+ tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
1046
+ const res = {};
1047
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1048
+ const gh = cpk.columns.map((c) => cb[c]);
1049
+ res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1050
+ gh,
1051
+ cpk.name
1052
+ );
1053
+ });
1054
+ return res;
1052
1055
  });
1053
- return res;
1054
- });
1056
+ } else {
1057
+ tables[t.name] = (0, import_pg_core.pgSchema)(schemaName).table(t.name, columns, (cb) => {
1058
+ const res = {};
1059
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1060
+ const gh = cpk.columns.map((c) => cb[c]);
1061
+ res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1062
+ gh,
1063
+ cpk.name
1064
+ );
1065
+ });
1066
+ return res;
1067
+ });
1068
+ }
1055
1069
  });
1056
1070
  return tables;
1057
1071
  };
@@ -2094,9 +2108,33 @@ var require_brace_expansion = __commonJS({
2094
2108
  }
2095
2109
  });
2096
2110
 
2111
+ // src/drivers/index.ts
2112
+ var import_drizzle_orm3, DrizzleDbClient, DrizzleORMPgClient;
2113
+ var init_drivers = __esm({
2114
+ "src/drivers/index.ts"() {
2115
+ import_drizzle_orm3 = require("drizzle-orm");
2116
+ DrizzleDbClient = class {
2117
+ constructor(db) {
2118
+ this.db = db;
2119
+ }
2120
+ };
2121
+ DrizzleORMPgClient = class extends DrizzleDbClient {
2122
+ async query(query, values) {
2123
+ const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
2124
+ return res.rows;
2125
+ }
2126
+ async run(query) {
2127
+ const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
2128
+ return res.rows;
2129
+ }
2130
+ };
2131
+ }
2132
+ });
2133
+
2097
2134
  // src/utils-studio.ts
2098
2135
  var utils_studio_exports = {};
2099
2136
  __export(utils_studio_exports, {
2137
+ DrizzleORMPgClient: () => DrizzleORMPgClient,
2100
2138
  drizzleSchemaPg: () => toDrizzle,
2101
2139
  drizzleSchemaSQLite: () => toDrizzle2,
2102
2140
  pgPushIntrospect: () => pgPushIntrospect,
@@ -3316,8 +3354,12 @@ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
3316
3354
  const { internal, ...schemaWithoutInternals } = schema;
3317
3355
  return { schema: schemaWithoutInternals };
3318
3356
  };
3357
+
3358
+ // src/utils-studio.ts
3359
+ init_drivers();
3319
3360
  // Annotate the CommonJS export names for ESM import in node:
3320
3361
  0 && (module.exports = {
3362
+ DrizzleORMPgClient,
3321
3363
  drizzleSchemaPg,
3322
3364
  drizzleSchemaSQLite,
3323
3365
  pgPushIntrospect,
package/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Dialect } from "./schemaValidator";
2
2
  import { NamedWithSchema } from "./cli/commands/migrate";
3
- import { AnyPgTable, PgDatabase } from "drizzle-orm/pg-core";
3
+ import { PgDatabase } from "drizzle-orm/pg-core";
4
4
  import { PgSchema as PgSchemaKit } from "./serializer/pgSchema";
5
5
  import { Config, DbConnection } from ".";
6
6
  export declare const assertV1OutFolder: (out: string, dialect: Dialect | "{dialect}") => void;
@@ -209,24 +209,4 @@ export declare const pushSchema: (imports: Record<string, unknown>, db: PgDataba
209
209
  statementsToExecute: string[];
210
210
  apply: () => Promise<void>;
211
211
  }>;
212
- export declare const prepareFrom: (connection: DbConnection) => Promise<{
213
- db: import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>>;
214
- type: "pg";
215
- schema: Record<string, AnyPgTable<{}> | import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>>> | undefined;
216
- } | {
217
- db: import("drizzle-orm/mysql2").MySql2Database<Record<string, never>>;
218
- type: "mysql";
219
- schema: Record<string, import("drizzle-orm/mysql-core").AnyMySqlTable<{}> | import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>>> | undefined;
220
- } | {
221
- db: import("./orm-extenstions/d1-driver/driver").DrizzleD1WranglerDatabase<Record<string, never>>;
222
- type: "sqlite";
223
- schema: Record<string, import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | import("drizzle-orm/sqlite-core").AnySQLiteTable<{}>> | undefined;
224
- } | {
225
- db: import("drizzle-orm/better-sqlite3").BetterSQLite3Database<Record<string, never>>;
226
- type: "sqlite";
227
- schema: Record<string, import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | import("drizzle-orm/sqlite-core").AnySQLiteTable<{}>> | undefined;
228
- } | {
229
- db: import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>>;
230
- type: "sqlite";
231
- schema: Record<string, import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | import("drizzle-orm/sqlite-core").AnySQLiteTable<{}>> | undefined;
232
- }>;
212
+ export declare const prepareFrom: (connection: DbConnection) => Promise<Record<string, any>>;