mnemo_cards/mnemo_cards_backend/lib/database/tables/payments.dart

47 lines
1.7 KiB
Dart
Raw Normal View History

2025-12-13 13:27:05 +00:00
import 'package:drift/drift.dart';
2025-12-13 23:35:14 +00:00
import 'package:drift_postgres/drift_postgres.dart';
import '../converters.dart' show JsonListConverter, StringListConverter;
2025-12-13 13:27:05 +00:00
import 'users.dart';
/// Таблица Payments - платежи
class Payments extends Table {
2025-12-13 23:35:14 +00:00
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
2025-12-20 18:26:15 +00:00
TextColumn get id =>
text().withDefault(const CustomExpression('gen_random_uuid()::text'))();
TextColumn get userId =>
text().references(Users, #id, onDelete: KeyAction.cascade)();
2025-12-13 13:27:05 +00:00
TextColumn get amount => text()();
TextColumn get currency => text()();
2025-12-20 18:26:15 +00:00
2025-12-13 13:27:05 +00:00
// Статус и платежная система (enum as string)
2025-12-20 18:26:15 +00:00
TextColumn get status => text()(); // PaymentStatus
TextColumn get paymentSystem => text()(); // PaymentSystem
2025-12-13 13:27:05 +00:00
TextColumn get externalToken => text().nullable()();
TextColumn get meta => text().nullable()();
2025-12-20 18:26:15 +00:00
Column<PgDateTime> get date =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
2025-12-13 13:27:05 +00:00
// Продукты (JSON array)
2025-12-20 18:26:15 +00:00
TextColumn get products =>
text().withDefault(const Constant('[]')).map(const JsonListConverter())();
2025-12-13 13:27:05 +00:00
// Audit
2025-12-20 18:26:15 +00:00
Column<PgDateTime> get createdAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
Column<PgDateTime> get updatedAt =>
customType(PgTypes.timestampWithTimezone).withDefault(now())();
BoolColumn get isDeleted =>
boolean().customConstraint('NOT NULL DEFAULT FALSE')();
Column<PgDateTime> get deletedAt =>
customType(PgTypes.timestampWithTimezone).nullable()();
2025-12-13 20:55:50 +00:00
@override
Set<Column> get primaryKey => {id};
2025-12-13 13:27:05 +00:00
}
// Конвертеры импортированы из converters.dart