mnemo_cards/mnemo_cards_backend/lib/database/tables/promo_codes.dart
Dmitry 8ce8569625
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Admin Panel / Deploy Admin Panel (push) Waiting to run
Deploy Admin Panel / Admin Panel Verification (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
fixes
2025-12-15 00:55:42 +03:00

81 lines
3.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:drift/drift.dart';
import 'package:drift_postgres/drift_postgres.dart';
import '../converters.dart' show generateUuid, JsonListConverter, StringListConverter;
import 'users.dart';
/// Таблица PromoCodesCampaigns - кампании промокодов
class PromoCodesCampaigns extends Table {
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
TextColumn get id => text()
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
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()();
Column<PgDateTime> get start => customType(PgTypes.timestampWithTimezone)();
Column<PgDateTime> get finish => customType(PgTypes.timestampWithTimezone)();
// Статус (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
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
BoolColumn get isDeleted => boolean()
.customConstraint('NOT NULL DEFAULT FALSE')();
// PostgreSQL использует нативный BOOLEAN
Column<PgDateTime> get deletedAt => customType(PgTypes.timestampWithTimezone)
.nullable()();
@override
Set<Column> get primaryKey => {id};
}
/// Таблица PromoCodes - промокоды
class PromoCodes extends Table {
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
TextColumn get id => text()
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
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
Column<PgDateTime> get createdAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
Column<PgDateTime> get updatedAt => customType(PgTypes.timestampWithTimezone)
.withDefault(now())();
BoolColumn get isDeleted => boolean()
.customConstraint('NOT NULL DEFAULT FALSE')();
Column<PgDateTime> get deletedAt => customType(PgTypes.timestampWithTimezone)
.nullable()();
@override
Set<Column> get primaryKey => {id};
}
// Конвертеры импортированы из converters.dart