stabilize-orm 1.1.2 → 1.1.3
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/migrations.ts +18 -7
- package/package.json +1 -1
package/migrations.ts
CHANGED
|
@@ -14,24 +14,30 @@ function getAutoIncrementPK(dbType: DBType) {
|
|
|
14
14
|
case DBType.MySQL:
|
|
15
15
|
return "INT AUTO_INCREMENT PRIMARY KEY";
|
|
16
16
|
case DBType.SQLite:
|
|
17
|
-
default:
|
|
18
17
|
return "INTEGER PRIMARY KEY AUTOINCREMENT";
|
|
18
|
+
default: // Default to Postgres
|
|
19
|
+
return "SERIAL PRIMARY KEY";
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
// Helper to get SQL type for timestamps
|
|
23
24
|
function getTimestampType(dbType: DBType) {
|
|
24
25
|
switch (dbType) {
|
|
25
|
-
case DBType.Postgres:
|
|
26
|
-
|
|
27
|
-
case DBType.
|
|
26
|
+
case DBType.Postgres:
|
|
27
|
+
return "TIMESTAMP";
|
|
28
|
+
case DBType.MySQL:
|
|
29
|
+
return "DATETIME";
|
|
30
|
+
case DBType.SQLite:
|
|
31
|
+
return "TEXT";
|
|
32
|
+
default: // Default to Postgres
|
|
33
|
+
return "TIMESTAMP";
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export async function generateMigration(
|
|
32
38
|
model: new (...args: any[]) => any,
|
|
33
39
|
name: string,
|
|
34
|
-
dbType: DBType = DBType.
|
|
40
|
+
dbType: DBType = DBType.Postgres, // default to Postgres
|
|
35
41
|
): Promise<Migration> {
|
|
36
42
|
const tableName = Reflect.getMetadata(ModelKey, model);
|
|
37
43
|
if (!tableName)
|
|
@@ -93,12 +99,17 @@ function getMigrationsTableSQL(dbType: DBType) {
|
|
|
93
99
|
applied_at DATETIME NOT NULL
|
|
94
100
|
)`;
|
|
95
101
|
case DBType.SQLite:
|
|
96
|
-
default:
|
|
97
102
|
return `CREATE TABLE IF NOT EXISTS migrations (
|
|
98
103
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
99
104
|
name TEXT NOT NULL,
|
|
100
105
|
applied_at TEXT NOT NULL
|
|
101
106
|
)`;
|
|
107
|
+
default: // Default to Postgres
|
|
108
|
+
return `CREATE TABLE IF NOT EXISTS migrations (
|
|
109
|
+
id SERIAL PRIMARY KEY,
|
|
110
|
+
name TEXT NOT NULL,
|
|
111
|
+
applied_at TIMESTAMP NOT NULL
|
|
112
|
+
)`;
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
115
|
|
|
@@ -106,7 +117,7 @@ export async function runMigrations(config: DBConfig, migrations: Migration[]) {
|
|
|
106
117
|
const client = new DBClient(config);
|
|
107
118
|
try {
|
|
108
119
|
// Detect DB type from config
|
|
109
|
-
const dbType = config.type ?? DBType.
|
|
120
|
+
const dbType = config.type ?? DBType.Postgres;
|
|
110
121
|
|
|
111
122
|
await client.query(getMigrationsTableSQL(dbType));
|
|
112
123
|
|
package/package.json
CHANGED