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
77 lines
3.2 KiB
Dart
77 lines
3.2 KiB
Dart
import 'package:drift/drift.dart';
|
||
import 'package:drift_postgres/drift_postgres.dart';
|
||
import '../converters.dart';
|
||
|
||
/// Таблица Users - основная информация о пользователях
|
||
class Users extends Table {
|
||
// ID как String, но фактически UUID (генерируется PostgreSQL на стороне БД)
|
||
TextColumn get id => text()
|
||
.withDefault(const CustomExpression('gen_random_uuid()::text'))();
|
||
TextColumn get externalUserId => text().unique()();
|
||
TextColumn get name => text().nullable()();
|
||
TextColumn get email => text().nullable()();
|
||
BoolColumn get admin => boolean()
|
||
.withDefault(const Constant(false))
|
||
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
||
|
||
// UserSettings (JSON)
|
||
TextColumn get userSettings => text().nullable()();
|
||
|
||
// Purchases (JSON array)
|
||
TextColumn get purchases => text()
|
||
.nullable()
|
||
.withDefault(const Constant('[]'))
|
||
.map(const StringListConverter())();
|
||
|
||
// Audit fields
|
||
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))
|
||
.customConstraint('')(); // PostgreSQL использует нативный BOOLEAN
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
/// Таблица UserDatas - расширенная информация о пользователе
|
||
class UserDatas 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)();
|
||
|
||
// Статистика
|
||
IntColumn get totalStudyTimeMinutes => integer().withDefault(const Constant(0))();
|
||
IntColumn get currentStreak => integer().withDefault(const Constant(0))();
|
||
IntColumn get longestStreak => integer().withDefault(const Constant(0))();
|
||
IntColumn get totalCards => integer().withDefault(const Constant(0))();
|
||
IntColumn get totalTests => integer().withDefault(const Constant(0))();
|
||
|
||
// Временные метки
|
||
Column<PgDateTime> get lastTimeOnline => customType(PgTypes.timestampWithTimezone)
|
||
.nullable()();
|
||
Column<PgDateTime> get registrationDate => customType(PgTypes.timestampWithTimezone)
|
||
.withDefault(now())();
|
||
TextColumn get lastTestSessionToken => text().nullable()();
|
||
|
||
// Теги (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())();
|
||
|
||
@override
|
||
Set<Column> get primaryKey => {id};
|
||
}
|
||
|
||
// Конвертеры импортированы из converters.dart
|