tethys.backend/database/migrations/1782294801884_create_activities_table.ts
Arno Kaimbacher 7e2f320b4f
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
feat: implement activity logging for user actions and create activities table
2026-06-24 15:03:17 +02:00

25 lines
985 B
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema';
export default class extends BaseSchema {
protected tableName = 'activities';
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id');
table.string('type').notNullable().index(); // 'dataset.uploaded', 'auth.login'
table.integer('user_id').unsigned().nullable().references('id').inTable('accounts').onDelete('SET NULL');
table.string('subject_type').nullable(); // manual morph: model name
table.bigInteger('subject_id').unsigned().nullable();
table.string('description').notNullable();
table.json('properties').nullable();
table.timestamp('created_at');
table.timestamp('updated_at');
table.index(['subject_type', 'subject_id'])
table.index('created_at')
});
}
async down() {
this.schema.dropTable(this.tableName);
}
}