Skip to content

Commit b7d9b98

Browse files
committed
chore: wip
1 parent c5f6c16 commit b7d9b98

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

storage/framework/core/database/src/migrations.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export async function generateMigration(modelPath: string) {
9191
const model = await import(modelPath)
9292
const tableName = model.default.table
9393
const fields = model.default.fields
94+
const useTimestamps = model.default?.traits?.useTimestamps
9495

9596
let migrationContent = `import type { Database } from '@stacksjs/database'\n`
9697
migrationContent += `import { sql } from '@stacksjs/database'\n\n`
@@ -116,6 +117,12 @@ export async function generateMigration(modelPath: string) {
116117
migrationContent += `)\n`
117118
}
118119

120+
// Append created_at and updated_at columns if useTimestamps is true
121+
if (useTimestamps) {
122+
migrationContent += ` .addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))\n`
123+
migrationContent += ` .addColumn('updated_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))\n`
124+
}
125+
119126
migrationContent += ` .execute()\n`
120127
migrationContent += `}\n`
121128

0 commit comments

Comments
 (0)