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())();
|
|
|
|
|
|
|
|
|
|
// Deprecated fields (для обратной совместимости)
|
|
|
|
|
TextColumn get packs => text()
|
|
|
|
|
.withDefault(const Constant('[]'))
|
|
|
|
|
.map(const StringListConverter())();
|
2025-12-13 22:00:36 +00:00
|
|
|
BoolColumn get subscription => boolean()
|
|
|
|
|
.withDefault(const Constant(false))
|
2025-12-13 23:35:14 +00:00
|
|
|
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
2025-12-13 13:27:05 +00:00
|
|
|
|
|
|
|
|
// 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-13 20:55:50 +00:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Set<Column> get primaryKey => {id};
|
2025-12-13 13:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Конвертеры импортированы из converters.dart
|