Some checks are pending
Backend CI / test (push) Waiting to run
Backend 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
69 lines
2.6 KiB
Dart
69 lines
2.6 KiB
Dart
import 'package:drift/drift.dart';
|
|
import 'package:drift_postgres/drift_postgres.dart';
|
|
import '../converters.dart' show JsonMapConverter, JsonListConverter;
|
|
import 'users.dart';
|
|
|
|
/// Таблица SubscriptionPlans - планы подписки
|
|
class SubscriptionPlans extends Table {
|
|
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
|
TextColumn get id => text()
|
|
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
|
|
|
// UI информация (JSON)
|
|
TextColumn get ui => text().nullable().map(const JsonMapConverter())();
|
|
|
|
// Цена и валюта
|
|
TextColumn get price => text()();
|
|
TextColumn get currency => text()();
|
|
IntColumn get durationDays => integer()();
|
|
|
|
// Функции подписки (JSON array)
|
|
TextColumn get features => text()
|
|
.withDefault(const Constant('[]'))
|
|
.map(const JsonListConverter())();
|
|
|
|
// Платежная система
|
|
TextColumn get paymentId => text().nullable()();
|
|
TextColumn get paymentSystem => text()(); // enum as string
|
|
|
|
// Audit
|
|
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
|
.withDefault(now())();
|
|
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
|
.withDefault(now())();
|
|
BoolColumn get isDeleted => boolean()
|
|
.withDefault(const Constant(false))();
|
|
// PostgreSQL использует нативный BOOLEAN
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {id};
|
|
}
|
|
|
|
/// Таблица UserSubscriptions - подписки пользователей
|
|
class UserSubscriptions extends Table {
|
|
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
|
TextColumn get id => text()
|
|
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
|
TextColumn get userId => text()
|
|
.unique()
|
|
.references(Users, #id, onDelete: KeyAction.cascade)();
|
|
|
|
Column<PgDateTime> get start => customType(PgTypes.timestampWithTimezone)();
|
|
Column<PgDateTime> get finish => customType(PgTypes.timestampWithTimezone)();
|
|
|
|
// Функции подписки (JSON array)
|
|
TextColumn get features => text()
|
|
.withDefault(const Constant('[]'))
|
|
.map(const JsonListConverter())();
|
|
|
|
// Audit
|
|
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
|
|
.withDefault(now())();
|
|
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
|
|
.withDefault(now())();
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {id};
|
|
}
|
|
|
|
// Конвертеры импортированы из converters.dart
|