@stonyx/orm 0.3.2-beta.92 → 0.3.2-beta.94

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/README.md CHANGED
@@ -98,6 +98,7 @@ export default {
98
98
  connectionLimit: parseInt(MYSQL_CONNECTION_LIMIT ?? '10'),
99
99
  migrationsDir: MYSQL_MIGRATIONS_DIR ?? 'migrations',
100
100
  migrationsTable: '__migrations',
101
+ autoMigrate: AUTO_MIGRATE === 'true' ? true : AUTO_MIGRATE === 'false' ? false : undefined,
101
102
  } : undefined,
102
103
  dynamodb: DYNAMODB_REGION ? {
103
104
  region: DYNAMODB_REGION,
@@ -8,6 +8,7 @@ interface MysqlConfig {
8
8
  connectionLimit?: number;
9
9
  migrationsTable?: string;
10
10
  migrationsDir?: string;
11
+ autoMigrate?: boolean;
11
12
  }
12
13
  export declare function getPool(mysqlConfig: MysqlConfig): Promise<Pool>;
13
14
  export declare function closePool(): Promise<void>;
@@ -65,7 +65,17 @@ export default class MysqlDB {
65
65
  const pending = files.filter(f => !applied.includes(f));
66
66
  if (pending.length > 0) {
67
67
  this.deps.log.db?.(`${pending.length} pending migration(s) found.`);
68
- const shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
68
+ let shouldApply;
69
+ if (this.mysqlConfig.autoMigrate === true) {
70
+ shouldApply = true;
71
+ }
72
+ else if (this.mysqlConfig.autoMigrate === false) {
73
+ shouldApply = false;
74
+ this.deps.log.warn?.(`autoMigrate is false — skipping ${pending.length} pending migration(s).`);
75
+ }
76
+ else {
77
+ shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
78
+ }
69
79
  if (shouldApply) {
70
80
  for (const filename of pending) {
71
81
  const content = await this.deps.readFile(this.deps.path.join(migrationsPath, filename));
@@ -84,7 +94,17 @@ export default class MysqlDB {
84
94
  const schemas = this.deps.introspectModels();
85
95
  const modelCount = Object.keys(schemas).length;
86
96
  if (modelCount > 0) {
87
- const shouldGenerate = await this.deps.confirm(`No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`);
97
+ let shouldGenerate;
98
+ if (this.mysqlConfig.autoMigrate === true) {
99
+ shouldGenerate = true;
100
+ }
101
+ else if (this.mysqlConfig.autoMigrate === false) {
102
+ shouldGenerate = false;
103
+ this.deps.log.warn?.(`autoMigrate is false — skipping initial migration generation for ${modelCount} model(s).`);
104
+ }
105
+ else {
106
+ shouldGenerate = await this.deps.confirm(`No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`);
107
+ }
88
108
  if (shouldGenerate) {
89
109
  const { generateMigration } = await import('./migration-generator.js');
90
110
  const result = await generateMigration('initial_setup');
@@ -7,7 +7,7 @@ export async function getPool(pgConfig, extensions = ['vector']) {
7
7
  if (pool)
8
8
  return pool;
9
9
  const { default: pg } = await import('pg');
10
- const { host, port, user, password, database, connectionLimit, migrationsDir, migrationsTable, ...poolOpts } = pgConfig;
10
+ const { host, port, user, password, database, connectionLimit, migrationsDir, migrationsTable, autoMigrate, ...poolOpts } = pgConfig;
11
11
  pool = new pg.Pool({
12
12
  host,
13
13
  port,
@@ -65,7 +65,17 @@ export default class PostgresDB {
65
65
  const pending = files.filter(f => !applied.includes(f));
66
66
  if (pending.length > 0) {
67
67
  this.deps.log.db?.(`${pending.length} pending migration(s) found.`);
68
- const shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
68
+ let shouldApply;
69
+ if (this.pgConfig.autoMigrate === true) {
70
+ shouldApply = true;
71
+ }
72
+ else if (this.pgConfig.autoMigrate === false) {
73
+ shouldApply = false;
74
+ this.deps.log.warn?.(`autoMigrate is false — skipping ${pending.length} pending migration(s).`);
75
+ }
76
+ else {
77
+ shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
78
+ }
69
79
  if (shouldApply) {
70
80
  for (const filename of pending) {
71
81
  const content = await this.deps.readFile(this.deps.path.join(migrationsPath, filename));
@@ -84,7 +94,17 @@ export default class PostgresDB {
84
94
  const schemas = this.deps.introspectModels();
85
95
  const modelCount = Object.keys(schemas).length;
86
96
  if (modelCount > 0) {
87
- const shouldGenerate = await this.deps.confirm(`No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`);
97
+ let shouldGenerate;
98
+ if (this.pgConfig.autoMigrate === true) {
99
+ shouldGenerate = true;
100
+ }
101
+ else if (this.pgConfig.autoMigrate === false) {
102
+ shouldGenerate = false;
103
+ this.deps.log.warn?.(`autoMigrate is false — skipping initial migration generation for ${modelCount} model(s).`);
104
+ }
105
+ else {
106
+ shouldGenerate = await this.deps.confirm(`No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`);
107
+ }
88
108
  if (shouldGenerate) {
89
109
  const { generateMigration } = await import('./migration-generator.js');
90
110
  const result = await generateMigration('initial_setup');
@@ -16,6 +16,7 @@ export interface OrmMysqlConfig {
16
16
  connectionLimit?: number;
17
17
  migrationsDir?: string;
18
18
  migrationsTable?: string;
19
+ autoMigrate?: boolean;
19
20
  [key: string]: unknown;
20
21
  }
21
22
  export interface OrmPostgresConfig {
@@ -27,6 +28,7 @@ export interface OrmPostgresConfig {
27
28
  connectionLimit?: number;
28
29
  migrationsDir?: string;
29
30
  migrationsTable?: string;
31
+ autoMigrate?: boolean;
30
32
  [key: string]: unknown;
31
33
  }
32
34
  export interface OrmPaths {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.3.2-beta.92",
7
+ "version": "0.3.2-beta.94",
8
8
  "description": "",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",
@@ -63,7 +63,7 @@
63
63
  "dependencies": {
64
64
  "@stonyx/cron": "0.2.1-beta.70",
65
65
  "@stonyx/events": "0.1.1-beta.51",
66
- "@stonyx/utils": "0.2.3-beta.25",
66
+ "@stonyx/utils": "0.2.3-beta.26",
67
67
  "stonyx": "0.2.3-beta.68"
68
68
  },
69
69
  "peerDependencies": {
@@ -9,6 +9,7 @@ interface MysqlConfig {
9
9
  connectionLimit?: number;
10
10
  migrationsTable?: string;
11
11
  migrationsDir?: string;
12
+ autoMigrate?: boolean;
12
13
  }
13
14
 
14
15
  let pool: Pool | null = null;
@@ -127,7 +127,15 @@ export default class MysqlDB {
127
127
  if (pending.length > 0) {
128
128
  this.deps.log.db?.(`${pending.length} pending migration(s) found.`);
129
129
 
130
- const shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
130
+ let shouldApply: boolean;
131
+ if (this.mysqlConfig.autoMigrate === true) {
132
+ shouldApply = true;
133
+ } else if (this.mysqlConfig.autoMigrate === false) {
134
+ shouldApply = false;
135
+ this.deps.log.warn?.(`autoMigrate is false — skipping ${pending.length} pending migration(s).`);
136
+ } else {
137
+ shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
138
+ }
131
139
 
132
140
  if (shouldApply) {
133
141
  for (const filename of pending) {
@@ -148,9 +156,17 @@ export default class MysqlDB {
148
156
  const modelCount = Object.keys(schemas).length;
149
157
 
150
158
  if (modelCount > 0) {
151
- const shouldGenerate = await this.deps.confirm(
152
- `No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`
153
- );
159
+ let shouldGenerate: boolean;
160
+ if (this.mysqlConfig.autoMigrate === true) {
161
+ shouldGenerate = true;
162
+ } else if (this.mysqlConfig.autoMigrate === false) {
163
+ shouldGenerate = false;
164
+ this.deps.log.warn?.(`autoMigrate is false — skipping initial migration generation for ${modelCount} model(s).`);
165
+ } else {
166
+ shouldGenerate = await this.deps.confirm(
167
+ `No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`
168
+ );
169
+ }
154
170
 
155
171
  if (shouldGenerate) {
156
172
  const { generateMigration } = await import('./migration-generator.js');
@@ -21,7 +21,7 @@ export async function getPool(pgConfig: PgConfig, extensions: string[] = ['vecto
21
21
 
22
22
  const { default: pg } = await import('pg');
23
23
 
24
- const { host, port, user, password, database, connectionLimit, migrationsDir, migrationsTable, ...poolOpts } = pgConfig;
24
+ const { host, port, user, password, database, connectionLimit, migrationsDir, migrationsTable, autoMigrate, ...poolOpts } = pgConfig;
25
25
 
26
26
  pool = new pg.Pool({
27
27
  host,
@@ -134,7 +134,15 @@ export default class PostgresDB {
134
134
  if (pending.length > 0) {
135
135
  this.deps.log.db?.(`${pending.length} pending migration(s) found.`);
136
136
 
137
- const shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
137
+ let shouldApply: boolean;
138
+ if (this.pgConfig.autoMigrate === true) {
139
+ shouldApply = true;
140
+ } else if (this.pgConfig.autoMigrate === false) {
141
+ shouldApply = false;
142
+ this.deps.log.warn?.(`autoMigrate is false — skipping ${pending.length} pending migration(s).`);
143
+ } else {
144
+ shouldApply = await this.deps.confirm(`${pending.length} pending migration(s) found. Apply now?`);
145
+ }
138
146
 
139
147
  if (shouldApply) {
140
148
  for (const filename of pending) {
@@ -155,9 +163,17 @@ export default class PostgresDB {
155
163
  const modelCount = Object.keys(schemas).length;
156
164
 
157
165
  if (modelCount > 0) {
158
- const shouldGenerate = await this.deps.confirm(
159
- `No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`
160
- );
166
+ let shouldGenerate: boolean;
167
+ if (this.pgConfig.autoMigrate === true) {
168
+ shouldGenerate = true;
169
+ } else if (this.pgConfig.autoMigrate === false) {
170
+ shouldGenerate = false;
171
+ this.deps.log.warn?.(`autoMigrate is false — skipping initial migration generation for ${modelCount} model(s).`);
172
+ } else {
173
+ shouldGenerate = await this.deps.confirm(
174
+ `No migrations found but ${modelCount} model(s) detected. Generate and apply initial migration?`
175
+ );
176
+ }
161
177
 
162
178
  if (shouldGenerate) {
163
179
  const { generateMigration } = await import('./migration-generator.js');
@@ -18,6 +18,7 @@ export interface OrmMysqlConfig {
18
18
  connectionLimit?: number;
19
19
  migrationsDir?: string;
20
20
  migrationsTable?: string;
21
+ autoMigrate?: boolean;
21
22
  [key: string]: unknown;
22
23
  }
23
24
 
@@ -30,6 +31,7 @@ export interface OrmPostgresConfig {
30
31
  connectionLimit?: number;
31
32
  migrationsDir?: string;
32
33
  migrationsTable?: string;
34
+ autoMigrate?: boolean;
33
35
  [key: string]: unknown;
34
36
  }
35
37