Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Mobile App CI / test (push) Waiting to run
Mobile App CI / build-android (push) Blocked by required conditions
Mobile App CI / build-ios (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App 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
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
60 lines
2.3 KiB
Dart
60 lines
2.3 KiB
Dart
import 'package:drift/drift.dart';
|
||
import '../converters.dart' show generateUuid, JsonListConverter, StringListConverter;
|
||
import 'users.dart';
|
||
|
||
/// Таблица PromoCodesCampaigns - кампании промокодов
|
||
class PromoCodesCampaigns extends Table {
|
||
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
||
|
||
TextColumn get template => text()();
|
||
TextColumn get name => text().nullable()();
|
||
|
||
// Продукты (JSON array)
|
||
TextColumn get products => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const JsonListConverter())();
|
||
|
||
IntColumn get activationsPerCode => integer()();
|
||
IntColumn get activationsPerUser => integer()();
|
||
IntColumn get generationSize => integer()();
|
||
|
||
DateTimeColumn get start => dateTime()();
|
||
DateTimeColumn get finish => dateTime()();
|
||
|
||
// Статус (enum as string)
|
||
TextColumn get status => text()(); // created, preparing, ready, active, disabled
|
||
|
||
// Теги (JSON array)
|
||
TextColumn get tags => text()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const StringListConverter())();
|
||
|
||
// Audit
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||
BoolColumn get isDeleted => boolean().withDefault(const Constant(false))();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
/// Таблица PromoCodes - промокоды
|
||
class PromoCodes extends Table {
|
||
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
||
TextColumn get campaignId => text().references(PromoCodesCampaigns, #id, onDelete: KeyAction.cascade)();
|
||
|
||
TextColumn get code => text().unique()();
|
||
IntColumn get activations => integer().withDefault(const Constant(0))();
|
||
|
||
// Индивидуальный промокод (связан с пользователем)
|
||
TextColumn get userId => text().nullable().references(Users, #id, onDelete: KeyAction.cascade)();
|
||
|
||
// Audit
|
||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
// Конвертеры импортированы из converters.dart
|