forj 0.0.7 → 0.0.8
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/package.json +1 -1
- package/src/migrations/migrator.ts +24 -2
package/package.json
CHANGED
|
@@ -8,8 +8,16 @@ import { MigrationInfo, MigrationClass, Queue } from './types'
|
|
|
8
8
|
const __root = resolve(dirname(new URL(import.meta.url).pathname), '../../../..')
|
|
9
9
|
|
|
10
10
|
export class Migrator {
|
|
11
|
-
static #input
|
|
12
|
-
static #output
|
|
11
|
+
static #input = join(__root, 'migrations')
|
|
12
|
+
static #output = join(__root, 'migrations', 'sql')
|
|
13
|
+
static #createPatterns = [
|
|
14
|
+
/^create_(\w+)_table$/,
|
|
15
|
+
/^create_(\w+)$/,
|
|
16
|
+
]
|
|
17
|
+
static #changePatterns = [
|
|
18
|
+
/.+_(to|from|in)_(\w+)_table$/,
|
|
19
|
+
/.+_(to|from|in)_(\w+)$/,
|
|
20
|
+
]
|
|
13
21
|
|
|
14
22
|
static inputDir(dir: string) {
|
|
15
23
|
this.#input = join(__root, dir)
|
|
@@ -93,6 +101,20 @@ export class Migrator {
|
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
static guess(name: string): [string, boolean] {
|
|
105
|
+
for (const pattern of this.#createPatterns) {
|
|
106
|
+
const match = name.match(pattern)
|
|
107
|
+
if (match) return [match[1], true]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const pattern of this.#changePatterns) {
|
|
111
|
+
const match = name.match(pattern)
|
|
112
|
+
if (match) return [match[2], false]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return ['', false]
|
|
116
|
+
}
|
|
117
|
+
|
|
96
118
|
static className(name: string) {
|
|
97
119
|
const lastSlashIndex = name.lastIndexOf('/')
|
|
98
120
|
const fileName = lastSlashIndex >= 0 ? name.substring(lastSlashIndex + 1) : name
|