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

48 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 на стороне БД)
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()();
// Статус и платежная система (enum as string)
TextColumn get status => text()(); // PaymentStatus
TextColumn get paymentSystem => text()(); // PaymentSystem
TextColumn get externalToken => text().nullable()();
TextColumn get meta => text().nullable()();
2025-12-13 23:35:14 +00:00
Column<PgDateTime> get date => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
2025-12-13 13:27:05 +00:00
// Продукты (JSON array)
TextColumn get products => text()
.withDefault(const Constant('[]'))
.map(const JsonListConverter())();
// Audit
2025-12-13 23:35:14 +00:00
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
2025-12-14 20:36:05 +00:00
BoolColumn get isDeleted => boolean()
.withDefault(const Constant(false))
.customConstraint('')();
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