forj 0.0.6 → 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
CHANGED
|
@@ -23,7 +23,7 @@ export class Blueprint {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
id(name: string = 'id') { // Auto-increment ID (bigint unsigned)
|
|
26
|
-
return this.#column({ name, type: '
|
|
26
|
+
return this.#column({ name, type: 'INTEGER', autoIncrement: true, primary: true, nullable: false })
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
string(name: string, length: number = 255) {
|
|
@@ -34,49 +34,58 @@ export class Blueprint {
|
|
|
34
34
|
return this.#column({ name, type: 'TEXT', nullable: false })
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
int(name: string) {
|
|
38
38
|
return this.#column({ name, type: 'INTEGER', nullable: false })
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return this.#column({ name, type: 'BIGINT', nullable: false })
|
|
40
|
+
integer(name: string) {
|
|
41
|
+
return this.int(name)
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
real(name: string) {
|
|
44
|
+
return this.#column({ name, type: 'REAL', nullable: false })
|
|
45
|
+
}
|
|
46
|
+
numeric(name: string) {
|
|
47
|
+
return this.#column({ name, type: 'NUMERIC', nullable: false })
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
// bigInteger(name: string) {
|
|
51
|
+
// return this.#column({ name, type: 'BIGINT', nullable: false })
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// tinyInteger(name: string) {
|
|
55
|
+
// return this.#column({ name, type: 'TINYINT', nullable: false })
|
|
56
|
+
// }
|
|
57
|
+
|
|
49
58
|
boolean(name: string) {
|
|
50
|
-
return this.#column({ name, type: '
|
|
59
|
+
return this.#column({ name, type: 'INTEGER', nullable: false })
|
|
51
60
|
}
|
|
52
61
|
|
|
53
|
-
decimal(name: string, precision: number = 8, scale: number = 2) {
|
|
54
|
-
|
|
55
|
-
}
|
|
62
|
+
// decimal(name: string, precision: number = 8, scale: number = 2) {
|
|
63
|
+
// return this.#column({ name, type: `DECIMAL(${precision},${scale})`, nullable: false })
|
|
64
|
+
// }
|
|
56
65
|
|
|
57
|
-
float(name: string) {
|
|
58
|
-
|
|
59
|
-
}
|
|
66
|
+
// float(name: string) {
|
|
67
|
+
// return this.#column({ name, type: 'FLOAT', nullable: false })
|
|
68
|
+
// }
|
|
60
69
|
|
|
61
|
-
double(name: string) {
|
|
62
|
-
|
|
63
|
-
}
|
|
70
|
+
// double(name: string) {
|
|
71
|
+
// return this.#column({ name, type: 'DOUBLE', nullable: false })
|
|
72
|
+
// }
|
|
64
73
|
|
|
65
|
-
date(name: string) {
|
|
66
|
-
|
|
67
|
-
}
|
|
74
|
+
// date(name: string) {
|
|
75
|
+
// return this.#column({ name, type: 'DATE', nullable: false })
|
|
76
|
+
// }
|
|
68
77
|
|
|
69
|
-
dateTime(name: string) {
|
|
70
|
-
|
|
71
|
-
}
|
|
78
|
+
// dateTime(name: string) {
|
|
79
|
+
// return this.#column({ name, type: 'DATETIME', nullable: false })
|
|
80
|
+
// }
|
|
72
81
|
|
|
73
|
-
timestamp(name: string) {
|
|
74
|
-
|
|
75
|
-
}
|
|
82
|
+
// timestamp(name: string) {
|
|
83
|
+
// return this.#column({ name, type: 'TIMESTAMP', nullable: false })
|
|
84
|
+
// }
|
|
76
85
|
|
|
77
|
-
time(name: string) {
|
|
78
|
-
|
|
79
|
-
}
|
|
86
|
+
// time(name: string) {
|
|
87
|
+
// return this.#column({ name, type: 'TIME', nullable: false })
|
|
88
|
+
// }
|
|
80
89
|
|
|
81
90
|
json(name: string) {
|
|
82
91
|
return this.#column({ name, type: 'JSON', nullable: false })
|
|
@@ -86,14 +95,18 @@ export class Blueprint {
|
|
|
86
95
|
return this.#column({ name, type: `ENUM(${values.map(v => `'${v}'`).join(', ')})`, nullable: false })
|
|
87
96
|
}
|
|
88
97
|
|
|
98
|
+
blob(name: string) {
|
|
99
|
+
return this.#column({ name, type: 'BLOB', nullable: false })
|
|
100
|
+
}
|
|
101
|
+
|
|
89
102
|
timestamps() {
|
|
90
|
-
this
|
|
91
|
-
this
|
|
103
|
+
this.#column({ name: 'created_at', type: 'TEXT', nullable: false })
|
|
104
|
+
this.#column({ name: 'updated_at', type: 'TEXT', nullable: false })
|
|
92
105
|
return this
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
softDelete(name: string = 'deleted_at') {
|
|
96
|
-
this
|
|
109
|
+
this.#column({ name, type: 'TEXT', nullable: true })
|
|
97
110
|
return this
|
|
98
111
|
}
|
|
99
112
|
|
|
@@ -53,8 +53,11 @@ export default class SchemaBuilder {
|
|
|
53
53
|
if (column.length && !column.type.includes('('))
|
|
54
54
|
sql += `(${column.length})`
|
|
55
55
|
|
|
56
|
-
if (column.
|
|
57
|
-
sql += '
|
|
56
|
+
if (column.autoIncrement)
|
|
57
|
+
sql += ' AUTOINCREMENT'
|
|
58
|
+
|
|
59
|
+
// if (column.unsigned)
|
|
60
|
+
// sql += ' UNSIGNED'
|
|
58
61
|
|
|
59
62
|
if (column.nullable) {
|
|
60
63
|
sql += ' NULL'
|
|
@@ -62,9 +65,6 @@ export default class SchemaBuilder {
|
|
|
62
65
|
sql += ' NOT NULL'
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
if (column.autoIncrement)
|
|
66
|
-
sql += ' AUTO_INCREMENT'
|
|
67
|
-
|
|
68
68
|
if (column.default !== undefined) {
|
|
69
69
|
if (column.default === null) {
|
|
70
70
|
sql += ' DEFAULT NULL'
|
|
@@ -83,8 +83,8 @@ export default class SchemaBuilder {
|
|
|
83
83
|
if (column.primary)
|
|
84
84
|
sql += ' PRIMARY KEY'
|
|
85
85
|
|
|
86
|
-
if (column.comment)
|
|
87
|
-
|
|
86
|
+
// if (column.comment)
|
|
87
|
+
// sql += ` COMMENT '${column.comment.replace(/'/g, "''")}'`
|
|
88
88
|
|
|
89
89
|
return sql
|
|
90
90
|
}
|
|
@@ -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
|