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
60 lines
2.2 KiB
Dart
60 lines
2.2 KiB
Dart
import 'package:drift/drift.dart';
|
|
import 'users.dart';
|
|
import '../converters.dart' show generateUuid;
|
|
import '../postgres_constants.dart';
|
|
|
|
/// Таблица Tokens - токены авторизации пользователей
|
|
class Tokens extends Table {
|
|
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
|
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get token => text().unique()();
|
|
TextColumn get externalUserId => text()();
|
|
|
|
DateTimeColumn get created => dateTime().withDefault(currentTimestamp)();
|
|
DateTimeColumn get expires => dateTime()();
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {id};
|
|
|
|
@override
|
|
List<String> get customConstraints => [
|
|
'CONSTRAINT valid_expiry CHECK (expires > created)',
|
|
];
|
|
}
|
|
|
|
/// Таблица RefreshTokens - refresh токены для JWT
|
|
class RefreshTokens extends Table {
|
|
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
|
TextColumn get userId => text().references(Users, #id, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get jti => text().unique()(); // JWT ID
|
|
|
|
BoolColumn get isBlacklisted => boolean().withDefault(const Constant(false))();
|
|
|
|
DateTimeColumn get createdAt => dateTime().withDefault(currentTimestamp)();
|
|
DateTimeColumn get expiresAt => dateTime()();
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {id};
|
|
}
|
|
|
|
/// Таблица TelegramAuthCodes - коды для авторизации через Telegram
|
|
class TelegramAuthCodes extends Table {
|
|
TextColumn get id => text().withDefault(const Constant('gen_random_uuid()'))();
|
|
|
|
TextColumn get code => text().unique()();
|
|
TextColumn get telegramUserId => text()();
|
|
TextColumn get telegramUsername => text().nullable()();
|
|
TextColumn get firstName => text().nullable()();
|
|
TextColumn get lastName => text().nullable()();
|
|
|
|
BoolColumn get isUsed => boolean().withDefault(const Constant(false))();
|
|
DateTimeColumn get usedAt => dateTime().nullable()();
|
|
|
|
DateTimeColumn get createdAt => dateTime().withDefault(currentTimestamp)();
|
|
DateTimeColumn get expiresAt => dateTime()();
|
|
|
|
@override
|
|
Set<Column> get primaryKey => {id};
|
|
}
|