File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,8 @@ 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
+ const useTimestamps = model . default ?. traits ?. useTimestamps ?? model . default ?. traits ?. timestampable
95
+ const useSoftDeletes = model . default ?. traits ?. useSoftDeletes ?? model . default ?. traits ?. softDeletable
95
96
96
97
let migrationContent = `import type { Database } from '@stacksjs/database'\n`
97
98
migrationContent += `import { sql } from '@stacksjs/database'\n\n`
@@ -120,9 +121,13 @@ export async function generateMigration(modelPath: string) {
120
121
// Append created_at and updated_at columns if useTimestamps is true
121
122
if ( useTimestamps ) {
122
123
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
+ migrationContent += ` .addColumn('updated_at', 'timestamp', col => col.nullable( ))\n`
124
125
}
125
126
127
+ // Append deleted_at column if useSoftDeletes is true
128
+ if ( useSoftDeletes )
129
+ migrationContent += ` .addColumn('deleted_at', 'timestamp', col => col.nullable())\n`
130
+
126
131
migrationContent += ` .execute()\n`
127
132
migrationContent += `}\n`
128
133
Original file line number Diff line number Diff line change @@ -45,7 +45,9 @@ export interface ModelOptions extends Base {
45
45
traits : {
46
46
useUuid ?: boolean // defaults to false
47
47
useTimestamps ?: boolean | TimestampOptions // defaults to true
48
+ timestampable ?: boolean | TimestampOptions // useTimestamps alias
48
49
useSoftDeletes ?: boolean | SoftDeleteOptions // defaults to false
50
+ softDeletable ?: boolean | SoftDeleteOptions // useSoftDeletes alias
49
51
50
52
useAuth ?: boolean | AuthOptions // defaults to false
51
53
authenticatable ?: boolean | AuthOptions // useAuth alias
You can’t perform that action at this time.
0 commit comments