@kairojsmodule/migration 1.0.0 → 1.1.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kairojsmodule/migration",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Schema builder, migration runner and seeder engine for KairoJS",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "dependencies": {
21
- "@kairojsmodule/query-builder": "^1.0.0"
21
+ "@kairojsmodule/query-builder": "^1.1.0"
22
22
  },
23
23
  "author": "Riski Ardiane <@kairojsmodule>"
24
24
  }
@@ -45,7 +45,16 @@ export class ColumnDefinition {
45
45
  parts.push('UNIQUE');
46
46
  }
47
47
  if (this.defaultValue !== undefined) {
48
- const def = typeof this.defaultValue === 'string' ? `'${this.defaultValue}'` : this.defaultValue;
48
+ let def;
49
+ if (this.defaultValue === null) {
50
+ def = 'NULL';
51
+ } else if (typeof this.defaultValue === 'boolean') {
52
+ def = this.defaultValue ? 1 : 0;
53
+ } else if (typeof this.defaultValue === 'string') {
54
+ def = `'${this.defaultValue.replace(/'/g, "''")}'`;
55
+ } else {
56
+ def = this.defaultValue;
57
+ }
49
58
  parts.push(`DEFAULT ${def}`);
50
59
  }
51
60
 
@@ -96,6 +105,22 @@ export class TableBlueprint {
96
105
  return this.addColumn(name, 'TEXT');
97
106
  }
98
107
 
108
+ timestamp(name) {
109
+ return this.addColumn(name, 'VARCHAR(255)');
110
+ }
111
+
112
+ uuid(name = 'uuid') {
113
+ return this.addColumn(name, 'VARCHAR(36)');
114
+ }
115
+
116
+ foreignId(name) {
117
+ return this.addColumn(name, 'INTEGER');
118
+ }
119
+
120
+ softDeletes(column = 'deleted_at') {
121
+ return this.timestamp(column).nullable();
122
+ }
123
+
99
124
  timestamps() {
100
125
  this.string('created_at').nullable();
101
126
  this.string('updated_at').nullable();