@lara-node/db 0.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.
@@ -0,0 +1,215 @@
1
+ const require_chunk = require("./chunk.cjs");
2
+ let fs = require("fs");
3
+ fs = require_chunk.__toESM(fs, 1);
4
+ let path = require("path");
5
+ path = require_chunk.__toESM(path, 1);
6
+ //#region src/Database/MakeMigration.ts
7
+ function pad(n) {
8
+ return n < 10 ? "0" + n : String(n);
9
+ }
10
+ function timestamp() {
11
+ const d = /* @__PURE__ */ new Date();
12
+ return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
13
+ }
14
+ function pascalCase(str) {
15
+ return str.replace(/[^a-zA-Z0-9]+/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
16
+ }
17
+ /**
18
+ * Parse migration name to extract table name and action type.
19
+ * Follows Laravel conventions:
20
+ * - create_users_table → creates 'users' table
21
+ * - add_column_to_users_table → alters 'users' table
22
+ * - remove_column_from_users_table → alters 'users' table
23
+ * - modify_column_in_users_table → alters 'users' table
24
+ * - drop_users_table → drops 'users' table
25
+ */
26
+ function parseMigrationName(name) {
27
+ const normalized = name.toLowerCase().replace(/\s+/g, "_");
28
+ const createMatch = normalized.match(/^create_(.+?)(?:_table)?$/);
29
+ if (createMatch) return {
30
+ table: createMatch[1],
31
+ action: "create"
32
+ };
33
+ const dropMatch = normalized.match(/^drop_(.+?)(?:_table)?$/);
34
+ if (dropMatch) return {
35
+ table: dropMatch[1],
36
+ action: "drop"
37
+ };
38
+ const addToMatch = normalized.match(/^add_.+_to_(.+?)(?:_table)?$/);
39
+ if (addToMatch) return {
40
+ table: addToMatch[1],
41
+ action: "alter"
42
+ };
43
+ const removeFromMatch = normalized.match(/^remove_.+_from_(.+?)(?:_table)?$/);
44
+ if (removeFromMatch) return {
45
+ table: removeFromMatch[1],
46
+ action: "alter"
47
+ };
48
+ const modifyInMatch = normalized.match(/^(?:modify|change|update)_.+_in_(.+?)(?:_table)?$/);
49
+ if (modifyInMatch) return {
50
+ table: modifyInMatch[1],
51
+ action: "alter"
52
+ };
53
+ const renameColMatch = normalized.match(/^rename_.+_to_.+_in_(.+?)(?:_table)?$/);
54
+ if (renameColMatch) return {
55
+ table: renameColMatch[1],
56
+ action: "alter"
57
+ };
58
+ const toTableMatch = normalized.match(/.+_to_(.+?)(?:_table)?$/);
59
+ if (toTableMatch) return {
60
+ table: toTableMatch[1],
61
+ action: "alter"
62
+ };
63
+ const fromTableMatch = normalized.match(/.+_from_(.+?)(?:_table)?$/);
64
+ if (fromTableMatch) return {
65
+ table: fromTableMatch[1],
66
+ action: "alter"
67
+ };
68
+ const inTableMatch = normalized.match(/.+_in_(.+?)(?:_table)?$/);
69
+ if (inTableMatch) return {
70
+ table: inTableMatch[1],
71
+ action: "alter"
72
+ };
73
+ const onTableMatch = normalized.match(/.+_on_(.+?)(?:_table)?$/);
74
+ if (onTableMatch) return {
75
+ table: onTableMatch[1],
76
+ action: "alter"
77
+ };
78
+ return {
79
+ table: void 0,
80
+ action: "create"
81
+ };
82
+ }
83
+ function getTemplate(name, className, table, action) {
84
+ const tbl = table || name.replace(/[^a-z0-9_]/gi, "_").toLowerCase();
85
+ if (action === "drop") return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';
86
+
87
+ /**
88
+ * Migration: ${name}
89
+ * Drop table: ${tbl}
90
+ */
91
+ export default class ${className} implements Migration {
92
+ /**
93
+ * Run the migrations.
94
+ */
95
+ async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {
96
+ return schema.dropTable('${tbl}');
97
+ }
98
+
99
+ /**
100
+ * Reverse the migrations.
101
+ */
102
+ async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {
103
+ return schema.createTable('${tbl}', (table: TableBuilder) => {
104
+ table.increments('id');
105
+ // Add the columns that were in the original table
106
+ table.timestamps();
107
+ });
108
+ }
109
+ }
110
+ `;
111
+ if (action === "alter") return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';
112
+
113
+ /**
114
+ * Migration: ${name}
115
+ * Alter table: ${tbl}
116
+ */
117
+ export default class ${className} implements Migration {
118
+ /**
119
+ * Run the migrations.
120
+ */
121
+ async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {
122
+ return schema.alterTable('${tbl}', (table: TableBuilder) => {
123
+ // Add a column:
124
+ // table.string('column_name', 255).nullable();
125
+
126
+ // Add an index:
127
+ // table.index(['column_name']);
128
+
129
+ // Add a foreign key:
130
+ // table.foreignKey('foreign_id', 'other_table', 'id', { onDelete: 'CASCADE' });
131
+
132
+ // Drop a column:
133
+ // table.dropColumn('column_name');
134
+
135
+ // Rename a column:
136
+ // table.renameColumn('old_name', 'new_name');
137
+ });
138
+ }
139
+
140
+ /**
141
+ * Reverse the migrations.
142
+ */
143
+ async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {
144
+ return schema.alterTable('${tbl}', (table: TableBuilder) => {
145
+ // Reverse the operations performed in up()
146
+ });
147
+ }
148
+ }
149
+ `;
150
+ return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';
151
+
152
+ /**
153
+ * Migration: ${name}
154
+ * Create table: ${tbl}
155
+ */
156
+ export default class ${className} implements Migration {
157
+ /**
158
+ * Run the migrations.
159
+ */
160
+ async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {
161
+ return schema.createTable('${tbl}', (table: TableBuilder) => {
162
+ table.increments('id');
163
+
164
+ // Add your columns here
165
+ // table.string('name', 255).notNullable();
166
+ // table.text('description').nullable();
167
+ // table.unsignedBigInteger('user_id').notNullable();
168
+
169
+ // Foreign keys
170
+ // table.foreignKey('user_id', 'users', 'id', { onDelete: 'CASCADE' });
171
+
172
+ table.timestamps();
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Reverse the migrations.
178
+ */
179
+ async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {
180
+ return schema.dropTable('${tbl}');
181
+ }
182
+ }
183
+ `;
184
+ }
185
+ function parseArgs(argv) {
186
+ const args = {};
187
+ for (let i = 2; i < argv.length; i++) {
188
+ const a = argv[i];
189
+ if (a.startsWith("--")) {
190
+ const [k, v] = a.slice(2).split("=");
191
+ args[k] = v === void 0 ? true : v;
192
+ } else if (!args._) args._ = a;
193
+ }
194
+ return args;
195
+ }
196
+ const args = parseArgs(process.argv);
197
+ const name = args._ || args.name;
198
+ if (!name) {
199
+ console.error("Usage: make-migration <name> [--table=tableName] [--create=tableName]");
200
+ process.exit(1);
201
+ }
202
+ const tableOption = args.table || null;
203
+ const createOption = args.create || null;
204
+ const parsed = parseMigrationName(name);
205
+ const table = createOption || tableOption || parsed.table;
206
+ const action = createOption ? "create" : tableOption ? "alter" : parsed.action;
207
+ const dir = path.default.resolve(process.cwd(), "src/database/migrations");
208
+ if (!fs.default.existsSync(dir)) fs.default.mkdirSync(dir, { recursive: true });
209
+ const fileName = `${timestamp()}_${name.replace(/\s+/g, "_")}.ts`;
210
+ const filePath = path.default.join(dir, fileName);
211
+ const template = getTemplate(name, pascalCase(name) + "Migration", table, action);
212
+ fs.default.writeFileSync(filePath, template);
213
+ console.log("Created migration:", filePath);
214
+ if (table) console.log(`Table: ${table} (${action})`);
215
+ //#endregion
@@ -0,0 +1,215 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ //#region src/Database/MakeMigration.ts
4
+ function pad(n) {
5
+ return n < 10 ? "0" + n : String(n);
6
+ }
7
+ function timestamp() {
8
+ const d = /* @__PURE__ */ new Date();
9
+ return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
10
+ }
11
+ function pascalCase(str) {
12
+ return str.replace(/[^a-zA-Z0-9]+/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
13
+ }
14
+ /**
15
+ * Parse migration name to extract table name and action type.
16
+ * Follows Laravel conventions:
17
+ * - create_users_table → creates 'users' table
18
+ * - add_column_to_users_table → alters 'users' table
19
+ * - remove_column_from_users_table → alters 'users' table
20
+ * - modify_column_in_users_table → alters 'users' table
21
+ * - drop_users_table → drops 'users' table
22
+ */
23
+ function parseMigrationName(name) {
24
+ const normalized = name.toLowerCase().replace(/\s+/g, "_");
25
+ const createMatch = normalized.match(/^create_(.+?)(?:_table)?$/);
26
+ if (createMatch) return {
27
+ table: createMatch[1],
28
+ action: "create"
29
+ };
30
+ const dropMatch = normalized.match(/^drop_(.+?)(?:_table)?$/);
31
+ if (dropMatch) return {
32
+ table: dropMatch[1],
33
+ action: "drop"
34
+ };
35
+ const addToMatch = normalized.match(/^add_.+_to_(.+?)(?:_table)?$/);
36
+ if (addToMatch) return {
37
+ table: addToMatch[1],
38
+ action: "alter"
39
+ };
40
+ const removeFromMatch = normalized.match(/^remove_.+_from_(.+?)(?:_table)?$/);
41
+ if (removeFromMatch) return {
42
+ table: removeFromMatch[1],
43
+ action: "alter"
44
+ };
45
+ const modifyInMatch = normalized.match(/^(?:modify|change|update)_.+_in_(.+?)(?:_table)?$/);
46
+ if (modifyInMatch) return {
47
+ table: modifyInMatch[1],
48
+ action: "alter"
49
+ };
50
+ const renameColMatch = normalized.match(/^rename_.+_to_.+_in_(.+?)(?:_table)?$/);
51
+ if (renameColMatch) return {
52
+ table: renameColMatch[1],
53
+ action: "alter"
54
+ };
55
+ const toTableMatch = normalized.match(/.+_to_(.+?)(?:_table)?$/);
56
+ if (toTableMatch) return {
57
+ table: toTableMatch[1],
58
+ action: "alter"
59
+ };
60
+ const fromTableMatch = normalized.match(/.+_from_(.+?)(?:_table)?$/);
61
+ if (fromTableMatch) return {
62
+ table: fromTableMatch[1],
63
+ action: "alter"
64
+ };
65
+ const inTableMatch = normalized.match(/.+_in_(.+?)(?:_table)?$/);
66
+ if (inTableMatch) return {
67
+ table: inTableMatch[1],
68
+ action: "alter"
69
+ };
70
+ const onTableMatch = normalized.match(/.+_on_(.+?)(?:_table)?$/);
71
+ if (onTableMatch) return {
72
+ table: onTableMatch[1],
73
+ action: "alter"
74
+ };
75
+ return {
76
+ table: void 0,
77
+ action: "create"
78
+ };
79
+ }
80
+ function getTemplate(name, className, table, action) {
81
+ const tbl = table || name.replace(/[^a-z0-9_]/gi, "_").toLowerCase();
82
+ if (action === "drop") return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';
83
+
84
+ /**
85
+ * Migration: ${name}
86
+ * Drop table: ${tbl}
87
+ */
88
+ export default class ${className} implements Migration {
89
+ /**
90
+ * Run the migrations.
91
+ */
92
+ async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {
93
+ return schema.dropTable('${tbl}');
94
+ }
95
+
96
+ /**
97
+ * Reverse the migrations.
98
+ */
99
+ async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {
100
+ return schema.createTable('${tbl}', (table: TableBuilder) => {
101
+ table.increments('id');
102
+ // Add the columns that were in the original table
103
+ table.timestamps();
104
+ });
105
+ }
106
+ }
107
+ `;
108
+ if (action === "alter") return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';
109
+
110
+ /**
111
+ * Migration: ${name}
112
+ * Alter table: ${tbl}
113
+ */
114
+ export default class ${className} implements Migration {
115
+ /**
116
+ * Run the migrations.
117
+ */
118
+ async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {
119
+ return schema.alterTable('${tbl}', (table: TableBuilder) => {
120
+ // Add a column:
121
+ // table.string('column_name', 255).nullable();
122
+
123
+ // Add an index:
124
+ // table.index(['column_name']);
125
+
126
+ // Add a foreign key:
127
+ // table.foreignKey('foreign_id', 'other_table', 'id', { onDelete: 'CASCADE' });
128
+
129
+ // Drop a column:
130
+ // table.dropColumn('column_name');
131
+
132
+ // Rename a column:
133
+ // table.renameColumn('old_name', 'new_name');
134
+ });
135
+ }
136
+
137
+ /**
138
+ * Reverse the migrations.
139
+ */
140
+ async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {
141
+ return schema.alterTable('${tbl}', (table: TableBuilder) => {
142
+ // Reverse the operations performed in up()
143
+ });
144
+ }
145
+ }
146
+ `;
147
+ return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';
148
+
149
+ /**
150
+ * Migration: ${name}
151
+ * Create table: ${tbl}
152
+ */
153
+ export default class ${className} implements Migration {
154
+ /**
155
+ * Run the migrations.
156
+ */
157
+ async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {
158
+ return schema.createTable('${tbl}', (table: TableBuilder) => {
159
+ table.increments('id');
160
+
161
+ // Add your columns here
162
+ // table.string('name', 255).notNullable();
163
+ // table.text('description').nullable();
164
+ // table.unsignedBigInteger('user_id').notNullable();
165
+
166
+ // Foreign keys
167
+ // table.foreignKey('user_id', 'users', 'id', { onDelete: 'CASCADE' });
168
+
169
+ table.timestamps();
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Reverse the migrations.
175
+ */
176
+ async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {
177
+ return schema.dropTable('${tbl}');
178
+ }
179
+ }
180
+ `;
181
+ }
182
+ function parseArgs(argv) {
183
+ const args = {};
184
+ for (let i = 2; i < argv.length; i++) {
185
+ const a = argv[i];
186
+ if (a.startsWith("--")) {
187
+ const [k, v] = a.slice(2).split("=");
188
+ args[k] = v === void 0 ? true : v;
189
+ } else if (!args._) args._ = a;
190
+ }
191
+ return args;
192
+ }
193
+ const args = parseArgs(process.argv);
194
+ const name = args._ || args.name;
195
+ if (!name) {
196
+ console.error("Usage: make-migration <name> [--table=tableName] [--create=tableName]");
197
+ process.exit(1);
198
+ }
199
+ const tableOption = args.table || null;
200
+ const createOption = args.create || null;
201
+ const parsed = parseMigrationName(name);
202
+ const table = createOption || tableOption || parsed.table;
203
+ const action = createOption ? "create" : tableOption ? "alter" : parsed.action;
204
+ const dir = path.resolve(process.cwd(), "src/database/migrations");
205
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
206
+ const fileName = `${timestamp()}_${name.replace(/\s+/g, "_")}.ts`;
207
+ const filePath = path.join(dir, fileName);
208
+ const template = getTemplate(name, pascalCase(name) + "Migration", table, action);
209
+ fs.writeFileSync(filePath, template);
210
+ console.log("Created migration:", filePath);
211
+ if (table) console.log(`Table: ${table} (${action})`);
212
+ //#endregion
213
+ export {};
214
+
215
+ //# sourceMappingURL=MakeMigration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MakeMigration.js","names":[],"sources":["../src/Database/MakeMigration.ts"],"sourcesContent":["#!/usr/bin/env ts-node\nimport fs from \"fs\";\nimport path from \"path\";\n\nfunction pad(n: number) {\n return n < 10 ? \"0\" + n : String(n);\n}\n\nfunction timestamp() {\n const d = new Date();\n return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;\n}\n\nfunction pascalCase(str: string): string {\n return str\n .replace(/[^a-zA-Z0-9]+/g, \" \")\n .split(\" \")\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join(\"\");\n}\n\n/**\n * Parse migration name to extract table name and action type.\n * Follows Laravel conventions:\n * - create_users_table → creates 'users' table\n * - add_column_to_users_table → alters 'users' table\n * - remove_column_from_users_table → alters 'users' table\n * - modify_column_in_users_table → alters 'users' table\n * - drop_users_table → drops 'users' table\n */\nfunction parseMigrationName(name: string): {\n table: string | undefined;\n action: \"create\" | \"alter\" | \"drop\";\n} {\n const normalized = name.toLowerCase().replace(/\\s+/g, \"_\");\n\n // Pattern: create_xxx_table or create_xxx\n const createMatch = normalized.match(/^create_(.+?)(?:_table)?$/);\n if (createMatch) {\n return { table: createMatch[1], action: \"create\" };\n }\n\n // Pattern: drop_xxx_table or drop_xxx\n const dropMatch = normalized.match(/^drop_(.+?)(?:_table)?$/);\n if (dropMatch) {\n return { table: dropMatch[1], action: \"drop\" };\n }\n\n // Pattern: add_xxx_to_yyy_table or add_xxx_to_yyy\n const addToMatch = normalized.match(/^add_.+_to_(.+?)(?:_table)?$/);\n if (addToMatch) {\n return { table: addToMatch[1], action: \"alter\" };\n }\n\n // Pattern: remove_xxx_from_yyy_table or remove_xxx_from_yyy\n const removeFromMatch = normalized.match(/^remove_.+_from_(.+?)(?:_table)?$/);\n if (removeFromMatch) {\n return { table: removeFromMatch[1], action: \"alter\" };\n }\n\n // Pattern: modify_xxx_in_yyy_table or change_xxx_in_yyy or update_xxx_in_yyy\n const modifyInMatch = normalized.match(/^(?:modify|change|update)_.+_in_(.+?)(?:_table)?$/);\n if (modifyInMatch) {\n return { table: modifyInMatch[1], action: \"alter\" };\n }\n\n // Pattern: rename_xxx_to_yyy_in_zzz_table (rename column)\n const renameColMatch = normalized.match(/^rename_.+_to_.+_in_(.+?)(?:_table)?$/);\n if (renameColMatch) {\n return { table: renameColMatch[1], action: \"alter\" };\n }\n\n // Pattern: xxx_to_yyy_table (generic \"to table\" pattern)\n const toTableMatch = normalized.match(/.+_to_(.+?)(?:_table)?$/);\n if (toTableMatch) {\n return { table: toTableMatch[1], action: \"alter\" };\n }\n\n // Pattern: xxx_from_yyy_table (generic \"from table\" pattern)\n const fromTableMatch = normalized.match(/.+_from_(.+?)(?:_table)?$/);\n if (fromTableMatch) {\n return { table: fromTableMatch[1], action: \"alter\" };\n }\n\n // Pattern: xxx_in_yyy_table (generic \"in table\" pattern)\n const inTableMatch = normalized.match(/.+_in_(.+?)(?:_table)?$/);\n if (inTableMatch) {\n return { table: inTableMatch[1], action: \"alter\" };\n }\n\n // Pattern: xxx_on_yyy_table (generic \"on table\" pattern)\n const onTableMatch = normalized.match(/.+_on_(.+?)(?:_table)?$/);\n if (onTableMatch) {\n return { table: onTableMatch[1], action: \"alter\" };\n }\n\n // No pattern matched\n return { table: undefined, action: \"create\" };\n}\n\nfunction getTemplate(\n name: string,\n className: string,\n table: string | undefined,\n action: \"create\" | \"alter\" | \"drop\",\n): string {\n const tbl = table || name.replace(/[^a-z0-9_]/gi, \"_\").toLowerCase();\n\n if (action === \"drop\") {\n return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';\n\n/**\n * Migration: ${name}\n * Drop table: ${tbl}\n */\nexport default class ${className} implements Migration {\n /**\n * Run the migrations.\n */\n async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {\n return schema.dropTable('${tbl}');\n }\n\n /**\n * Reverse the migrations.\n */\n async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {\n return schema.createTable('${tbl}', (table: TableBuilder) => {\n table.increments('id');\n // Add the columns that were in the original table\n table.timestamps();\n });\n }\n}\n`;\n }\n\n if (action === \"alter\") {\n return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';\n\n/**\n * Migration: ${name}\n * Alter table: ${tbl}\n */\nexport default class ${className} implements Migration {\n /**\n * Run the migrations.\n */\n async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {\n return schema.alterTable('${tbl}', (table: TableBuilder) => {\n // Add a column:\n // table.string('column_name', 255).nullable();\n \n // Add an index:\n // table.index(['column_name']);\n \n // Add a foreign key:\n // table.foreignKey('foreign_id', 'other_table', 'id', { onDelete: 'CASCADE' });\n\n // Drop a column:\n // table.dropColumn('column_name');\n\n // Rename a column:\n // table.renameColumn('old_name', 'new_name');\n });\n }\n\n /**\n * Reverse the migrations.\n */\n async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {\n return schema.alterTable('${tbl}', (table: TableBuilder) => {\n // Reverse the operations performed in up()\n });\n }\n}\n`;\n }\n\n // Default: create table\n return `import type { Migration, MigrationSchema, TableBuilder, QueryFn } from '@lara-node/db';\n\n/**\n * Migration: ${name}\n * Create table: ${tbl}\n */\nexport default class ${className} implements Migration {\n /**\n * Run the migrations.\n */\n async up(schema: MigrationSchema, query?: QueryFn): Promise<any> {\n return schema.createTable('${tbl}', (table: TableBuilder) => {\n table.increments('id');\n \n // Add your columns here\n // table.string('name', 255).notNullable();\n // table.text('description').nullable();\n // table.unsignedBigInteger('user_id').notNullable();\n \n // Foreign keys\n // table.foreignKey('user_id', 'users', 'id', { onDelete: 'CASCADE' });\n \n table.timestamps();\n });\n }\n\n /**\n * Reverse the migrations.\n */\n async down(schema: MigrationSchema, query?: QueryFn): Promise<any> {\n return schema.dropTable('${tbl}');\n }\n}\n`;\n}\n\nfunction parseArgs(argv: string[]) {\n const args: Record<string, string | boolean> = {};\n for (let i = 2; i < argv.length; i++) {\n const a = argv[i];\n if (a.startsWith(\"--\")) {\n const [k, v] = a.slice(2).split(\"=\");\n args[k] = v === undefined ? true : v;\n } else if (!args._) {\n args._ = a;\n }\n }\n return args;\n}\n\n// Main execution\nconst args = parseArgs(process.argv);\nconst name = (args._ as string) || (args.name as string);\nif (!name) {\n console.error(\"Usage: make-migration <name> [--table=tableName] [--create=tableName]\");\n process.exit(1);\n}\n\nconst tableOption = (args.table as string) || null;\nconst createOption = (args.create as string) || null;\n\n// Parse the migration name to extract table and action\nconst parsed = parseMigrationName(name);\n\n// Options override parsed values\nconst table = createOption || tableOption || parsed.table;\nconst action = createOption ? \"create\" : tableOption ? \"alter\" : parsed.action;\n\nconst dir = path.resolve(process.cwd(), \"src/database/migrations\");\nif (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });\n\nconst ts = timestamp();\nconst fileName = `${ts}_${name.replace(/\\s+/g, \"_\")}.ts`;\nconst filePath = path.join(dir, fileName);\nconst className = pascalCase(name) + \"Migration\";\n\nconst template = getTemplate(name, className, table, action);\n\nfs.writeFileSync(filePath, template);\nconsole.log(\"Created migration:\", filePath);\nif (table) {\n console.log(`Table: ${table} (${action})`);\n}\n"],"mappings":";;;AAIA,SAAS,IAAI,GAAW;CACtB,OAAO,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC;AACpC;AAEA,SAAS,YAAY;CACnB,MAAM,oBAAI,IAAI,KAAK;CACnB,OAAO,GAAG,EAAE,YAAY,IAAI,IAAI,EAAE,SAAS,IAAI,CAAC,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,CAAC;AAChB;AAEA,MAAM,cAAe,KAAK,SAAoB;AAC9C,MAAM,eAAgB,KAAK,UAAqB;AAGhD,MAAM,SAAS,mBAAmB,IAAI;AAGtC,MAAM,QAAQ,gBAAgB,eAAe,OAAO;AACpD,MAAM,SAAS,eAAe,WAAW,cAAc,UAAU,OAAO;AAExE,MAAM,MAAM,KAAK,QAAQ,QAAQ,IAAI,GAAG,yBAAyB;AACjE,IAAI,CAAC,GAAG,WAAW,GAAG,GAAG,GAAG,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAG9D,MAAM,WAAW,GADN,UACU,EAAE,GAAG,KAAK,QAAQ,QAAQ,GAAG,EAAE;AACpD,MAAM,WAAW,KAAK,KAAK,KAAK,QAAQ;AAGxC,MAAM,WAAW,YAAY,MAFX,WAAW,IAAI,IAAI,aAES,OAAO,MAAM;AAE3D,GAAG,cAAc,UAAU,QAAQ;AACnC,QAAQ,IAAI,sBAAsB,QAAQ;AAC1C,IAAI,OACF,QAAQ,IAAI,UAAU,MAAM,IAAI,OAAO,EAAE"}
package/dist/chunk.cjs ADDED
@@ -0,0 +1,43 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __exportAll = (all, no_symbols) => {
9
+ let target = {};
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ return target;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
+ key = keys[i];
20
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
+ get: ((k) => from[k]).bind(null, key),
22
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
+ });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ //#endregion
32
+ Object.defineProperty(exports, "__exportAll", {
33
+ enumerable: true,
34
+ get: function() {
35
+ return __exportAll;
36
+ }
37
+ });
38
+ Object.defineProperty(exports, "__toESM", {
39
+ enumerable: true,
40
+ get: function() {
41
+ return __toESM;
42
+ }
43
+ });