mnemo_cards/mnemo_cards_backend/lib/database/tables/audit.dart
Dmitry 0f49280805
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Mobile App CI / test (push) Waiting to run
Mobile App CI / build-android (push) Blocked by required conditions
Mobile App CI / build-ios (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
fixes and format
2025-12-20 21:26:15 +03:00

48 lines
2.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:drift/drift.dart';
import 'package:drift_postgres/drift_postgres.dart';
import '../converters.dart' show generateUuid;
/// Таблица AuditLogs - audit trail для отслеживания изменений
///
/// ⚠️ ВАЖНО: Инфраструктура создается, но пока НЕ используется в коде.
/// Вызовы auditDao.log() будут добавлены позже, когда определим
/// какие операции нужно логировать.
///
/// Планируемые операции для логирования:
/// - Критичные: платежи, удаления пользователей, изменения подписок
/// - Retention policy: автоматическая очистка записей старше 90 дней
class AuditLogs extends Table {
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
TextColumn get id =>
text().withDefault(const CustomExpression('gen_random_uuid()::text'))();
// Какая таблица и запись изменена
// например: 'Users', 'Payments'
TextColumn get table => text()();
// ID записи, которая изменилась
TextColumn get recordId => text()();
// Тип операции: 'INSERT', 'UPDATE', 'DELETE', 'SOFT_DELETE', 'RESTORE'
TextColumn get action => text()();
// Кто сделал изменение
// ID пользователя (null для системных операций)
TextColumn get userId => text().nullable()();
// Данные до и после (JSON as TEXT)
// JSON данные до изменения
TextColumn get oldData => text().nullable()();
// JSON данные после изменения
TextColumn get newData => text().nullable()();
// Дополнительная информация
TextColumn get ipAddress => text().nullable()();
TextColumn get userAgent => text().nullable()();
// Audit
Column<PgDateTime> get createdAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
@override
Set<Column> get primaryKey => {id};
}