@stonyx/orm 0.3.2-beta.92 → 0.3.2-beta.93
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 +1 -0
- package/dist/mysql/connection.d.ts +1 -0
- package/dist/mysql/mysql-db.js +22 -2
- package/dist/postgres/connection.js +1 -1
- package/dist/postgres/postgres-db.js +22 -2
- package/dist/types/orm-types.d.ts +2 -0
- package/package.json +1 -1
- package/src/mysql/connection.ts +1 -0
- package/src/mysql/mysql-db.ts +20 -4
- package/src/postgres/connection.ts +1 -1
- package/src/postgres/postgres-db.ts +20 -4
- package/src/types/orm-types.ts +2 -0
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>;
|
package/dist/mysql/mysql-db.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
package/src/mysql/connection.ts
CHANGED
package/src/mysql/mysql-db.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
152
|
-
|
|
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
|
-
|
|
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
|
-
|
|
159
|
-
|
|
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');
|
package/src/types/orm-types.ts
CHANGED
|
@@ -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
|
|