@guren/orm 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { SQL } from 'drizzle-orm';
2
2
  import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
3
3
  import postgres from 'postgres';
4
- import { MySql2Database } from 'drizzle-orm/mysql2';
5
4
  import * as drizzle_orm_aws_data_api_pg from 'drizzle-orm/aws-data-api/pg';
6
5
  import { AwsDataApiPgDatabase as AwsDataApiPgDatabase$1 } from 'drizzle-orm/aws-data-api/pg';
7
- import { RDSDataClientConfig } from '@aws-sdk/client-rds-data';
8
6
  import { SQLiteBunDatabase } from 'drizzle-orm/bun-sqlite';
7
+ import { MySql2Database } from 'drizzle-orm/mysql2';
8
+ import { RDSDataClientConfig } from '@aws-sdk/client-rds-data';
9
9
 
10
10
  /** Accessor function: transforms a record field value after reading from DB. */
11
11
  type AccessorFn<T = unknown> = (record: PlainObject) => T;
@@ -1760,12 +1760,86 @@ declare const DrizzleAdapter: ORMAdapterAdvanced & {
1760
1760
  */
1761
1761
  declare function buildDrizzleConditions(table: unknown, conditions: WhereCondition[]): SQL | undefined;
1762
1762
 
1763
+ /**
1764
+ * What one `migrateDatabase()` call had to work with. `db:migrate` reports
1765
+ * success off this rather than off the call returning: a folder with nothing
1766
+ * in it applies nothing, and saying "completed" there reads as a database that
1767
+ * is now up to date.
1768
+ *
1769
+ * It describes the run the driver memoized, not the folder as it stands now.
1770
+ * Migrations are single-flighted per handle, so a second call returns this same
1771
+ * summary without re-reading the folder — which is the pre-existing no-rerun
1772
+ * behaviour, faithfully reported.
1773
+ */
1774
+ interface MigrationRunSummary {
1775
+ /** The folder the migrator read, absolute as the driver resolved it. */
1776
+ migrationsFolder: string;
1777
+ /** drizzle-kit migrations found there (one folder each, holding migration.sql). */
1778
+ migrationsFound: number;
1779
+ /**
1780
+ * Loose .sql files in that folder, which the drizzle migrator never runs.
1781
+ * Non-zero alongside `migrationsFound: 0` means the folder is not empty but
1782
+ * holds nothing to apply, which is a different problem from having generated
1783
+ * no migrations yet.
1784
+ */
1785
+ looseSqlFiles: number;
1786
+ }
1763
1787
  interface MigrationStatusEntry {
1764
1788
  name: string;
1765
1789
  applied: boolean;
1766
1790
  appliedAt: Date | null;
1767
1791
  }
1768
1792
 
1793
+ /**
1794
+ * The context a seeder receives. `db` is the drizzle database the app
1795
+ * configured, so its type depends on the dialect: annotate the seeder with the
1796
+ * matching alias below (or pass the driver's own database type) whenever the
1797
+ * app is not on PostgreSQL.
1798
+ *
1799
+ * The type parameter defaults to `PostgresJsDatabase` for backwards
1800
+ * compatibility — seeders written before this was generic keep compiling.
1801
+ */
1802
+ interface SeederContext<TDatabase = PostgresJsDatabase> {
1803
+ db: TDatabase;
1804
+ }
1805
+ type SeederHandler<TDatabase = PostgresJsDatabase> = (context: SeederContext<TDatabase>) => unknown;
1806
+ /** Seeder context for apps created with `createPostgresDatabase()`. */
1807
+ type PostgresSeederContext = SeederContext<PostgresJsDatabase>;
1808
+ /** Seeder context for apps created with `createMySqlDatabase()`. */
1809
+ type MySqlSeederContext = SeederContext<MySql2Database>;
1810
+ /** Seeder context for apps created with `createSqliteDatabase()`. */
1811
+ type SqliteSeederContext = SeederContext<SQLiteBunDatabase>;
1812
+ /** Seeder context for apps created with `createAwsDataApiDatabase()`. */
1813
+ type AwsDataApiSeederContext = SeederContext<AwsDataApiPgDatabase$1>;
1814
+ /**
1815
+ * What one `runSeeders()` call had to work with. `db:seed` reports success off
1816
+ * this rather than off the call returning: a folder with no seeders in it seeds
1817
+ * nothing, and saying "executed" there reads as a database that now holds the
1818
+ * rows the seeders would have written.
1819
+ */
1820
+ interface SeederRunSummary {
1821
+ /** The folder that was read, absolute as the driver resolved it. */
1822
+ seedersFolder: string;
1823
+ /** How many seeders ran. They run in the order their files sorted. */
1824
+ seedersRan: number;
1825
+ /**
1826
+ * Files with a seeder extension that exported nothing runnable, so they were
1827
+ * skipped. Non-zero alongside `seedersRan: 0` means the folder is not empty
1828
+ * but holds nothing to run — a different problem from having written no
1829
+ * seeder yet, and one `make:seeder` would not solve.
1830
+ */
1831
+ filesWithoutSeeder: number;
1832
+ }
1833
+ /**
1834
+ * Seeders are loaded as modules, so the dialect they were written against is
1835
+ * unknowable here. `TDatabase` is the caller stating which database it will
1836
+ * hand them — the same contract `runSeeders()` fulfils from the driver side.
1837
+ */
1838
+ declare function loadSeeders<TDatabase = PostgresJsDatabase>(directory: string | URL): Promise<Array<SeederHandler<TDatabase>>>;
1839
+ /** Runs every seeder in `directory` and reports what the folder held. */
1840
+ declare function runSeeders<TDatabase>(db: TDatabase, directory: string | URL): Promise<SeederRunSummary>;
1841
+ declare function defineSeeder<TDatabase = PostgresJsDatabase>(handler: SeederHandler<TDatabase>): SeederHandler<TDatabase>;
1842
+
1769
1843
  type ConnectionResolver$3 = string | (() => string | undefined);
1770
1844
  interface PostgresDatabaseOptions {
1771
1845
  migrationsFolder: string | URL;
@@ -1781,12 +1855,14 @@ interface PostgresDatabaseOptions {
1781
1855
  }
1782
1856
  interface PostgresDatabase {
1783
1857
  getDatabase(): Promise<PostgresJsDatabase>;
1784
- migrateDatabase(): Promise<void>;
1858
+ /** Applies pending drizzle-kit migrations and reports what the folder held. */
1859
+ migrateDatabase(): Promise<MigrationRunSummary>;
1785
1860
  closeDatabase(): Promise<void>;
1786
1861
  configureOrm(): Promise<void>;
1787
- seedDatabase(): Promise<void>;
1862
+ /** Runs every seeder in the configured folder and reports what it held. */
1863
+ seedDatabase(): Promise<SeederRunSummary>;
1788
1864
  /** Drops the public schema (and the drizzle tracker schema), then re-applies migrations — same end state as `guren db:reset`. */
1789
- resetDatabase(): Promise<void>;
1865
+ resetDatabase(): Promise<MigrationRunSummary>;
1790
1866
  /** Per-migration applied state derived from the drizzle-kit journal and drizzle.__drizzle_migrations. */
1791
1867
  migrationStatus(): Promise<MigrationStatusEntry[]>;
1792
1868
  }
@@ -1808,12 +1884,14 @@ interface MySqlDatabaseOptions {
1808
1884
  }
1809
1885
  interface MySqlDatabase {
1810
1886
  getDatabase(): Promise<MySql2Database>;
1811
- migrateDatabase(): Promise<void>;
1887
+ /** Applies pending drizzle-kit migrations and reports what the folder held. */
1888
+ migrateDatabase(): Promise<MigrationRunSummary>;
1812
1889
  closeDatabase(): Promise<void>;
1813
1890
  configureOrm(): Promise<void>;
1814
- seedDatabase(): Promise<void>;
1891
+ /** Runs every seeder in the configured folder and reports what it held. */
1892
+ seedDatabase(): Promise<SeederRunSummary>;
1815
1893
  /** Drops every table and view (including the drizzle migration tracker), then re-applies migrations — same end state as `guren db:reset`. */
1816
- resetDatabase(): Promise<void>;
1894
+ resetDatabase(): Promise<MigrationRunSummary>;
1817
1895
  /** Per-migration applied state derived from the drizzle-kit journal and the __drizzle_migrations table. */
1818
1896
  migrationStatus(): Promise<MigrationStatusEntry[]>;
1819
1897
  }
@@ -1834,12 +1912,19 @@ interface SqliteDatabaseOptions {
1834
1912
  }
1835
1913
  interface SqliteDatabase {
1836
1914
  getDatabase(): Promise<unknown>;
1837
- migrateDatabase(): Promise<void>;
1915
+ /** Applies pending drizzle-kit migrations and reports what the folder held. */
1916
+ migrateDatabase(): Promise<MigrationRunSummary>;
1838
1917
  closeDatabase(): Promise<void>;
1839
1918
  configureOrm(): Promise<void>;
1840
- seedDatabase(): Promise<void>;
1841
- /** Drops every table and view (including the drizzle migration tracker), then re-applies migrations — same end state as `guren db:reset`. */
1842
- resetDatabase(): Promise<void>;
1919
+ /** Runs every seeder in the configured folder and reports what it held. */
1920
+ seedDatabase(): Promise<SeederRunSummary>;
1921
+ /**
1922
+ * Drops every table and view (including the drizzle migration tracker), then
1923
+ * re-applies migrations — same end state as `guren db:reset`. Resolves
1924
+ * undefined only when a concurrent `closeDatabase()` left nothing to drop, so
1925
+ * there was no migration run to report.
1926
+ */
1927
+ resetDatabase(): Promise<MigrationRunSummary | undefined>;
1843
1928
  /** Per-migration applied state derived from the drizzle-kit journal and the __drizzle_migrations table. */
1844
1929
  migrationStatus(): Promise<MigrationStatusEntry[]>;
1845
1930
  }
@@ -1868,13 +1953,13 @@ interface D1DatabaseOptions {
1868
1953
  interface D1DatabaseHandle {
1869
1954
  getDatabase(): Promise<unknown>;
1870
1955
  /** Always throws: D1 migrations are applied with `wrangler d1 migrations apply`, never at runtime. */
1871
- migrateDatabase(): Promise<void>;
1956
+ migrateDatabase(): Promise<never>;
1872
1957
  closeDatabase(): Promise<void>;
1873
1958
  configureOrm(): Promise<void>;
1874
1959
  /** Always throws: seed with SQL through `wrangler d1 execute`. */
1875
- seedDatabase(): Promise<void>;
1960
+ seedDatabase(): Promise<never>;
1876
1961
  /** Always throws: recreate the database with wrangler instead. */
1877
- resetDatabase(): Promise<void>;
1962
+ resetDatabase(): Promise<never>;
1878
1963
  /** Always throws: wrangler's tracker is authoritative — use `wrangler d1 migrations list`. */
1879
1964
  migrationStatus(): Promise<never>;
1880
1965
  }
@@ -1915,47 +2000,19 @@ interface AwsDataApiDatabaseOptions {
1915
2000
  }
1916
2001
  interface AwsDataApiDatabase {
1917
2002
  getDatabase(): Promise<AwsDataApiPgDatabase>;
1918
- migrateDatabase(): Promise<void>;
2003
+ /** Applies pending drizzle-kit migrations and reports what the folder held. */
2004
+ migrateDatabase(): Promise<MigrationRunSummary>;
1919
2005
  closeDatabase(): Promise<void>;
1920
2006
  configureOrm(): Promise<void>;
1921
- seedDatabase(): Promise<void>;
2007
+ /** Runs every seeder in the configured folder and reports what it held. */
2008
+ seedDatabase(): Promise<SeederRunSummary>;
1922
2009
  /** Drops the public schema (and the drizzle tracker schema), then re-applies migrations — same end state as `guren db:reset`. */
1923
- resetDatabase(): Promise<void>;
2010
+ resetDatabase(): Promise<MigrationRunSummary>;
1924
2011
  /** Per-migration applied state derived from the drizzle-kit journal and drizzle.__drizzle_migrations. */
1925
2012
  migrationStatus(): Promise<MigrationStatusEntry[]>;
1926
2013
  }
1927
2014
  declare function createAwsDataApiDatabase(options: AwsDataApiDatabaseOptions): AwsDataApiDatabase;
1928
2015
 
1929
- /**
1930
- * The context a seeder receives. `db` is the drizzle database the app
1931
- * configured, so its type depends on the dialect: annotate the seeder with the
1932
- * matching alias below (or pass the driver's own database type) whenever the
1933
- * app is not on PostgreSQL.
1934
- *
1935
- * The type parameter defaults to `PostgresJsDatabase` for backwards
1936
- * compatibility — seeders written before this was generic keep compiling.
1937
- */
1938
- interface SeederContext<TDatabase = PostgresJsDatabase> {
1939
- db: TDatabase;
1940
- }
1941
- type SeederHandler<TDatabase = PostgresJsDatabase> = (context: SeederContext<TDatabase>) => unknown;
1942
- /** Seeder context for apps created with `createPostgresDatabase()`. */
1943
- type PostgresSeederContext = SeederContext<PostgresJsDatabase>;
1944
- /** Seeder context for apps created with `createMySqlDatabase()`. */
1945
- type MySqlSeederContext = SeederContext<MySql2Database>;
1946
- /** Seeder context for apps created with `createSqliteDatabase()`. */
1947
- type SqliteSeederContext = SeederContext<SQLiteBunDatabase>;
1948
- /** Seeder context for apps created with `createAwsDataApiDatabase()`. */
1949
- type AwsDataApiSeederContext = SeederContext<AwsDataApiPgDatabase$1>;
1950
- /**
1951
- * Seeders are loaded as modules, so the dialect they were written against is
1952
- * unknowable here. `TDatabase` is the caller stating which database it will
1953
- * hand them — the same contract `runSeeders()` fulfils from the driver side.
1954
- */
1955
- declare function loadSeeders<TDatabase = PostgresJsDatabase>(directory: string | URL): Promise<Array<SeederHandler<TDatabase>>>;
1956
- declare function runSeeders<TDatabase>(db: TDatabase, directory: string | URL): Promise<void>;
1957
- declare function defineSeeder<TDatabase = PostgresJsDatabase>(handler: SeederHandler<TDatabase>): SeederHandler<TDatabase>;
1958
-
1959
2016
  /**
1960
2017
  * Serialize a model record for API/JSON output.
1961
2018
  *
@@ -1970,4 +2027,4 @@ declare function serializeRecord(record: PlainObject, options: {
1970
2027
  /** Serialize an array of records. */
1971
2028
  declare function serializeRecords(records: PlainObject[], options: Parameters<typeof serializeRecord>[1]): PlainObject[];
1972
2029
 
1973
- export { type AccessorDefinitions, type AccessorFn, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type D1DatabaseHandle, type D1DatabaseOptions, DrizzleAdapter, type EagerLoadConstraint, type FindManyOptions, GlobalScopeRegistry, type GroupCondition, type HasManyRecord, type HasManyRelationResult, type HasManyThroughRecord, type HasManyThroughRelationResult, type HasOneRecord, type HasOneRelationResult, type HookCallback, type HookName, type InferModelInsert, type InferModelRecord, MassAssignmentException, type MigrationStatusEntry, Model, type ModelHooks, ModelNotFoundException, type ModelObserver, type ModelObserverConstructor, type ModelPaginationMeta, type ModelQueryOptions, type MorphManyRecord, type MorphManyRelationResult, type MorphToRecord, type MorphToRelationResult, type MutatorDefinitions, type MutatorFn, type MySqlDatabase, type MySqlDatabaseOptions, type MySqlSeederContext, type ORMAdapter, type ORMAdapterAdvanced, type OrderByClause, type OrderByInput, type OrderDefinition, type OrderDirection, type PaginateOptions, type PaginatedResult, type PlainObject, type PostgresDatabase, type PostgresDatabaseOptions, type PostgresSeederContext, QueryBuilder, type QueryBuilderOptions, type ScopeFunction, type SeederContext, type SeederHandler, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type TransactionHandle, type TransactionModelScope, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, applyAccessors, applyMutators, buildDrizzleConditions, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, executeHook, executeObservers, loadSeeders, runSeeders, serializeRecord, serializeRecords };
2030
+ export { type AccessorDefinitions, type AccessorFn, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type D1DatabaseHandle, type D1DatabaseOptions, DrizzleAdapter, type EagerLoadConstraint, type FindManyOptions, GlobalScopeRegistry, type GroupCondition, type HasManyRecord, type HasManyRelationResult, type HasManyThroughRecord, type HasManyThroughRelationResult, type HasOneRecord, type HasOneRelationResult, type HookCallback, type HookName, type InferModelInsert, type InferModelRecord, MassAssignmentException, type MigrationRunSummary, type MigrationStatusEntry, Model, type ModelHooks, ModelNotFoundException, type ModelObserver, type ModelObserverConstructor, type ModelPaginationMeta, type ModelQueryOptions, type MorphManyRecord, type MorphManyRelationResult, type MorphToRecord, type MorphToRelationResult, type MutatorDefinitions, type MutatorFn, type MySqlDatabase, type MySqlDatabaseOptions, type MySqlSeederContext, type ORMAdapter, type ORMAdapterAdvanced, type OrderByClause, type OrderByInput, type OrderDefinition, type OrderDirection, type PaginateOptions, type PaginatedResult, type PlainObject, type PostgresDatabase, type PostgresDatabaseOptions, type PostgresSeederContext, QueryBuilder, type QueryBuilderOptions, type ScopeFunction, type SeederContext, type SeederHandler, type SeederRunSummary, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type TransactionHandle, type TransactionModelScope, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, applyAccessors, applyMutators, buildDrizzleConditions, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, executeHook, executeObservers, loadSeeders, runSeeders, serializeRecord, serializeRecords };
package/dist/index.js CHANGED
@@ -2962,26 +2962,29 @@ function releaseActiveConnection(key, teardown) {
2962
2962
  // src/migration-utils.ts
2963
2963
  import { existsSync, readdirSync } from "fs";
2964
2964
  import { resolve } from "path";
2965
- function hasDrizzleMigrations(migrationsFolder) {
2965
+ function inspectMigrationsFolder(migrationsFolder) {
2966
2966
  if (!existsSync(migrationsFolder)) {
2967
- return false;
2967
+ return { migrationsFolder, migrationsFound: 0, looseSqlFiles: 0 };
2968
2968
  }
2969
2969
  const entries = readdirSync(migrationsFolder, { withFileTypes: true });
2970
- return entries.some(
2971
- (entry) => entry.isDirectory() && existsSync(resolve(migrationsFolder, entry.name, "migration.sql"))
2972
- );
2970
+ return {
2971
+ migrationsFolder,
2972
+ migrationsFound: entries.filter(
2973
+ (entry) => entry.isDirectory() && existsSync(resolve(migrationsFolder, entry.name, "migration.sql"))
2974
+ ).length,
2975
+ looseSqlFiles: entries.filter((entry) => entry.isFile() && entry.name.endsWith(".sql")).length
2976
+ };
2973
2977
  }
2974
- function warnIgnoredFlatSqlMigrations(migrationsFolder) {
2975
- if (!existsSync(migrationsFolder)) {
2976
- return;
2978
+ function noMigrationsToRun(summary) {
2979
+ if (summary.looseSqlFiles === 0) {
2980
+ return summary;
2977
2981
  }
2978
- const flatSqlFiles = readdirSync(migrationsFolder, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".sql")).map((entry) => entry.name);
2979
- if (flatSqlFiles.length > 0) {
2980
- console.warn(
2981
- `[guren/orm] Ignoring ${flatSqlFiles.length} loose .sql file(s) in ${migrationsFolder}: ${flatSqlFiles.join(", ")}.
2982
+ const flatSqlFiles = readdirSync(summary.migrationsFolder, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".sql")).map((entry) => entry.name);
2983
+ console.warn(
2984
+ `[guren/orm] Ignoring ${flatSqlFiles.length} loose .sql file(s) in ${summary.migrationsFolder}: ${flatSqlFiles.join(", ")}.
2982
2985
  [guren/orm] Migrations must be generated with drizzle-kit (\`bun run db:make\`), which creates one folder per migration.`
2983
- );
2984
- }
2986
+ );
2987
+ return summary;
2985
2988
  }
2986
2989
  var PRE_CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
2987
2990
  "CONNECT_TIMEOUT",
@@ -3086,6 +3089,10 @@ import { readdir } from "fs/promises";
3086
3089
  import { extname, resolve as resolve2 } from "path";
3087
3090
  import { fileURLToPath, pathToFileURL } from "url";
3088
3091
  var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".ts"]);
3092
+ var DECLARATION_SUFFIXES = [".d.ts", ".d.mts", ".d.cts"];
3093
+ function isSeederCandidate(name) {
3094
+ return SUPPORTED_EXTENSIONS.has(extname(name)) && !DECLARATION_SUFFIXES.some((suffix) => name.endsWith(suffix));
3095
+ }
3089
3096
  function normalizeSeeder(candidate) {
3090
3097
  if (!candidate) {
3091
3098
  return void 0;
@@ -3127,10 +3134,18 @@ async function loadSeederModule(path) {
3127
3134
  }
3128
3135
  return void 0;
3129
3136
  }
3130
- async function loadSeeders(directory) {
3137
+ async function collectSeeders(directory) {
3131
3138
  const root = directory instanceof URL ? fileURLToPath(directory) : resolve2(directory);
3132
- const entries = await readdir(root, { withFileTypes: true });
3133
- const files = entries.filter((entry) => entry.isFile() && SUPPORTED_EXTENSIONS.has(extname(entry.name))).map((entry) => resolve2(root, entry.name)).sort();
3139
+ let entries;
3140
+ try {
3141
+ entries = await readdir(root, { withFileTypes: true });
3142
+ } catch (error) {
3143
+ if (error?.code !== "ENOENT") {
3144
+ throw error;
3145
+ }
3146
+ return { root, seeders: [], filesWithoutSeeder: 0 };
3147
+ }
3148
+ const files = entries.filter((entry) => entry.isFile() && isSeederCandidate(entry.name)).map((entry) => resolve2(root, entry.name)).sort();
3134
3149
  const seeders = [];
3135
3150
  for (const file of files) {
3136
3151
  const handler = await loadSeederModule(file);
@@ -3138,13 +3153,17 @@ async function loadSeeders(directory) {
3138
3153
  seeders.push(handler);
3139
3154
  }
3140
3155
  }
3141
- return seeders;
3156
+ return { root, seeders, filesWithoutSeeder: files.length - seeders.length };
3157
+ }
3158
+ async function loadSeeders(directory) {
3159
+ return (await collectSeeders(directory)).seeders;
3142
3160
  }
3143
3161
  async function runSeeders(db, directory) {
3144
- const seeders = await loadSeeders(directory);
3162
+ const { root, seeders, filesWithoutSeeder } = await collectSeeders(directory);
3145
3163
  for (const handler of seeders) {
3146
3164
  await handler({ db });
3147
3165
  }
3166
+ return { seedersFolder: root, seedersRan: seeders.length, filesWithoutSeeder };
3148
3167
  }
3149
3168
  function defineSeeder(handler) {
3150
3169
  return handler;
@@ -3206,9 +3225,9 @@ function createPostgresDatabase(options) {
3206
3225
  const migrations = singleFlight(async () => {
3207
3226
  let endpoint;
3208
3227
  try {
3209
- if (!hasDrizzleMigrations(resolvedMigrationsFolder)) {
3210
- warnIgnoredFlatSqlMigrations(resolvedMigrationsFolder);
3211
- return;
3228
+ const summary = inspectMigrationsFolder(resolvedMigrationsFolder);
3229
+ if (summary.migrationsFound === 0) {
3230
+ return noMigrationsToRun(summary);
3212
3231
  }
3213
3232
  const { drizzle, migrate, postgres: postgresFactory } = await loadPostgresModules();
3214
3233
  const url = resolveConnectionString();
@@ -3223,6 +3242,7 @@ function createPostgresDatabase(options) {
3223
3242
  } finally {
3224
3243
  await migrationClient.end({ timeout: 0 });
3225
3244
  }
3245
+ return summary;
3226
3246
  } catch (error) {
3227
3247
  throw migrationFailure(error, endpoint);
3228
3248
  }
@@ -3271,7 +3291,7 @@ function createPostgresDatabase(options) {
3271
3291
  }
3272
3292
  const db = await database2.get();
3273
3293
  try {
3274
- await runSeeders(db, resolvedSeedersFolder);
3294
+ return await runSeeders(db, resolvedSeedersFolder);
3275
3295
  } catch (error) {
3276
3296
  throw seedFailure(error, describeConnectionEndpoint(resolveConnectionString()));
3277
3297
  }
@@ -3298,7 +3318,7 @@ function createPostgresDatabase(options) {
3298
3318
  await adminClient.unsafe("DROP SCHEMA IF EXISTS drizzle CASCADE");
3299
3319
  });
3300
3320
  migrations.reset();
3301
- await migrations.get();
3321
+ return migrations.get();
3302
3322
  }
3303
3323
  async function migrationStatus() {
3304
3324
  const localMigrations = listLocalMigrations(resolvedMigrationsFolder);
@@ -3364,9 +3384,9 @@ function createMySqlDatabase(options) {
3364
3384
  const migrations = singleFlight(async () => {
3365
3385
  let endpoint;
3366
3386
  try {
3367
- if (!hasDrizzleMigrations(resolvedMigrationsFolder)) {
3368
- warnIgnoredFlatSqlMigrations(resolvedMigrationsFolder);
3369
- return;
3387
+ const summary = inspectMigrationsFolder(resolvedMigrationsFolder);
3388
+ if (summary.migrationsFound === 0) {
3389
+ return noMigrationsToRun(summary);
3370
3390
  }
3371
3391
  const { drizzle, migrate, createPool } = await loadMySqlModules();
3372
3392
  const url = resolveConnectionString();
@@ -3381,6 +3401,7 @@ function createMySqlDatabase(options) {
3381
3401
  } finally {
3382
3402
  await closePool(migrationClient);
3383
3403
  }
3404
+ return summary;
3384
3405
  } catch (error) {
3385
3406
  throw migrationFailure(error, endpoint);
3386
3407
  }
@@ -3426,7 +3447,7 @@ function createMySqlDatabase(options) {
3426
3447
  }
3427
3448
  const db = await database2.get();
3428
3449
  try {
3429
- await runSeeders(db, resolvedSeedersFolder);
3450
+ return await runSeeders(db, resolvedSeedersFolder);
3430
3451
  } catch (error) {
3431
3452
  throw seedFailure(error, describeConnectionEndpoint(resolveConnectionString()));
3432
3453
  }
@@ -3465,7 +3486,7 @@ function createMySqlDatabase(options) {
3465
3486
  }
3466
3487
  });
3467
3488
  migrations.reset();
3468
- await migrations.get();
3489
+ return migrations.get();
3469
3490
  }
3470
3491
  async function migrationStatus() {
3471
3492
  const localMigrations = listLocalMigrations(resolvedMigrationsFolder);
@@ -3569,13 +3590,14 @@ function createSqliteDatabase(options) {
3569
3590
  }
3570
3591
  const migrations = singleFlight(async () => {
3571
3592
  try {
3572
- if (!hasDrizzleMigrations(resolvedMigrationsFolder)) {
3573
- warnIgnoredFlatSqlMigrations(resolvedMigrationsFolder);
3574
- return;
3593
+ const summary = inspectMigrationsFolder(resolvedMigrationsFolder);
3594
+ if (summary.migrationsFound === 0) {
3595
+ return noMigrationsToRun(summary);
3575
3596
  }
3576
3597
  const db = await database2.get();
3577
3598
  const { migrate } = await import("drizzle-orm/bun-sqlite/migrator");
3578
3599
  await migrate(db, { migrationsFolder: resolvedMigrationsFolder });
3600
+ return summary;
3579
3601
  } catch (error) {
3580
3602
  throw migrationFailure(error);
3581
3603
  }
@@ -3589,7 +3611,7 @@ function createSqliteDatabase(options) {
3589
3611
  closeDatabase,
3590
3612
  async resetDatabase() {
3591
3613
  await database2.get();
3592
- if (!sqliteClient) return;
3614
+ if (!sqliteClient) return void 0;
3593
3615
  const objects = sqliteClient.query(
3594
3616
  "SELECT name, type FROM main.sqlite_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite\\_%' ESCAPE '\\'"
3595
3617
  ).all();
@@ -3603,7 +3625,7 @@ function createSqliteDatabase(options) {
3603
3625
  sqliteClient.exec("PRAGMA foreign_keys = ON;");
3604
3626
  }
3605
3627
  migrations.reset();
3606
- await migrations.get();
3628
+ return migrations.get();
3607
3629
  },
3608
3630
  async migrationStatus() {
3609
3631
  const localMigrations = listLocalMigrations(resolvedMigrationsFolder);
@@ -3628,7 +3650,7 @@ function createSqliteDatabase(options) {
3628
3650
  }
3629
3651
  const db = await database2.get();
3630
3652
  try {
3631
- await runSeeders(db, resolvedSeedersFolder);
3653
+ return await runSeeders(db, resolvedSeedersFolder);
3632
3654
  } catch (error) {
3633
3655
  throw seedFailure(error);
3634
3656
  }
@@ -3737,12 +3759,13 @@ function createAwsDataApiDatabase(options) {
3737
3759
  }
3738
3760
  const migrations = singleFlight(async () => {
3739
3761
  try {
3740
- if (!hasDrizzleMigrations(resolvedMigrationsFolder)) {
3741
- warnIgnoredFlatSqlMigrations(resolvedMigrationsFolder);
3742
- return;
3762
+ const summary = inspectMigrationsFolder(resolvedMigrationsFolder);
3763
+ if (summary.migrationsFound === 0) {
3764
+ return noMigrationsToRun(summary);
3743
3765
  }
3744
3766
  const { migrate } = await loadAwsDataApiModules();
3745
3767
  await withAdminDb((db) => migrate(db, { migrationsFolder: resolvedMigrationsFolder }));
3768
+ return summary;
3746
3769
  } catch (error) {
3747
3770
  const reason = error instanceof Error ? error.message : String(error);
3748
3771
  throw new Error(`Failed to run database migrations: ${reason}`);
@@ -3787,7 +3810,7 @@ function createAwsDataApiDatabase(options) {
3787
3810
  throw new Error('No seeders folder configured. Provide "seedersFolder" when calling createAwsDataApiDatabase().');
3788
3811
  }
3789
3812
  const db = await databaseHandle.get();
3790
- await runSeeders(db, resolvedSeedersFolder);
3813
+ return runSeeders(db, resolvedSeedersFolder);
3791
3814
  }
3792
3815
  async function withAdminDb(callback) {
3793
3816
  const { drizzle } = await loadAwsDataApiModules();
@@ -3806,7 +3829,7 @@ function createAwsDataApiDatabase(options) {
3806
3829
  await adminDb.execute(sql.raw("DROP SCHEMA IF EXISTS drizzle CASCADE"));
3807
3830
  });
3808
3831
  migrations.reset();
3809
- await migrations.get();
3832
+ return migrations.get();
3810
3833
  }
3811
3834
  async function migrationStatus() {
3812
3835
  const localMigrations = listLocalMigrations(resolvedMigrationsFolder);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/orm",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {