File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
storage/framework/core/database/src Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ export async function generateMigration(modelPath: string) {
91
91
const model = await import ( modelPath )
92
92
const tableName = model . default . table
93
93
const fields = model . default . fields
94
+ const useTimestamps = model . default ?. traits ?. useTimestamps
94
95
95
96
let migrationContent = `import type { Database } from '@stacksjs/database'\n`
96
97
migrationContent += `import { sql } from '@stacksjs/database'\n\n`
@@ -116,6 +117,12 @@ export async function generateMigration(modelPath: string) {
116
117
migrationContent += `)\n`
117
118
}
118
119
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
+
119
126
migrationContent += ` .execute()\n`
120
127
migrationContent += `}\n`
121
128
You can’t perform that action at this time.
0 commit comments