mnemo_cards/mnemo_cards_backend/lib/database/tables/subscriptions.dart
Dmitry f81e405d4f
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
bool
2025-12-14 01:00:36 +03:00

60 lines
2.2 KiB
Dart

import 'package:drift/drift.dart';
import '../converters.dart' show JsonMapConverter, JsonListConverter;
import '../postgres_constants.dart';
import 'users.dart';
/// Таблица SubscriptionPlans - планы подписки
class SubscriptionPlans extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
// 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
DateTimeColumn get createdAt => dateTime().withDefault(currentTimestamp)();
DateTimeColumn get updatedAt => dateTime().withDefault(currentTimestamp)();
BoolColumn get isDeleted => boolean()
.withDefault(const Constant(false))
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN, не нужен CHECK
@override
Set<Column> get primaryKey => {id};
}
/// Таблица UserSubscriptions - подписки пользователей
class UserSubscriptions extends Table {
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
TextColumn get userId => text().unique().references(Users, #id, onDelete: KeyAction.cascade)();
DateTimeColumn get start => dateTime()();
DateTimeColumn get finish => dateTime()();
// Функции подписки (JSON array)
TextColumn get features => text()
.withDefault(const Constant('[]'))
.map(const JsonListConverter())();
// Audit
DateTimeColumn get createdAt => dateTime().withDefault(currentTimestamp)();
DateTimeColumn get updatedAt => dateTime().withDefault(currentTimestamp)();
@override
Set<Column> get primaryKey => {id};
}
// Конвертеры импортированы из converters.dart