kontas-express 1.0.10 → 1.0.11
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/dist/index.js +54 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -284,7 +284,61 @@ export class ${name}Repository {
|
|
284
284
|
}
|
285
285
|
|
286
286
|
export const ${name.toLowerCase()} = new ${name}Repository()`;
|
287
|
+
// src/database/postgresql/migration.template.js
|
288
|
+
var generatePostgresMigration = (name, pluralName, fields) => {
|
289
|
+
const pgTypes = {
|
290
|
+
string: "VARCHAR(255)",
|
291
|
+
number: "INTEGER",
|
292
|
+
boolean: "BOOLEAN",
|
293
|
+
date: "TIMESTAMP"
|
294
|
+
};
|
295
|
+
const columns = fields.map((field) => {
|
296
|
+
const pgType = pgTypes[field.type] || "VARCHAR(255)";
|
297
|
+
return ` ${field.name} ${pgType}`;
|
298
|
+
}).join(`,
|
299
|
+
`);
|
300
|
+
return `import { getPool } from "../../config"
|
301
|
+
|
302
|
+
export async function up() {
|
303
|
+
const pool = await getPool()
|
304
|
+
|
305
|
+
await pool.query(\`
|
306
|
+
CREATE TABLE IF NOT EXISTS ${pluralName.toLowerCase()} (
|
307
|
+
id SERIAL PRIMARY KEY,
|
308
|
+
${columns},
|
309
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
310
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
311
|
+
)
|
312
|
+
\`)
|
313
|
+
|
314
|
+
console.log('\u2705 Migration ${name} created successfully')
|
315
|
+
}
|
316
|
+
|
317
|
+
export async function down() {
|
318
|
+
const pool = await getPool()
|
319
|
+
|
320
|
+
await pool.query(\`
|
321
|
+
DROP TABLE IF EXISTS ${pluralName.toLowerCase()}
|
322
|
+
\`)
|
323
|
+
|
324
|
+
console.log('\u2705 Migration ${name} dropped successfully')
|
325
|
+
}
|
326
|
+
|
327
|
+
// Jalankan migration
|
328
|
+
if (process.argv[2] === 'up') {
|
329
|
+
up()
|
330
|
+
.catch(console.error)
|
331
|
+
.finally(() => process.exit())
|
332
|
+
}
|
333
|
+
|
334
|
+
if (process.argv[2] === 'down') {
|
335
|
+
down()
|
336
|
+
.catch(console.error)
|
337
|
+
.finally(() => process.exit())
|
338
|
+
}`;
|
339
|
+
};
|
287
340
|
export {
|
288
341
|
generatePostgresRepository,
|
342
|
+
generatePostgresMigration,
|
289
343
|
generateMongoRepository
|
290
344
|
};
|