mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat: implement long-lived sessions
This commit is contained in:
parent
d0705afca8
commit
44f7e26270
35 changed files with 739 additions and 190 deletions
69
src/database/migrations/04-CreateAuthSessionsTable.ts
Normal file
69
src/database/migrations/04-CreateAuthSessionsTable.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
Table,
|
||||
TableIndex,
|
||||
TableForeignKey,
|
||||
} from "typeorm";
|
||||
import { TableColumnOptions } from "typeorm/schema-builder/options/TableColumnOptions";
|
||||
|
||||
const primaryUUIDColumn: TableColumnOptions = {
|
||||
name: "id",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "uuid",
|
||||
};
|
||||
|
||||
export class CreateAuthSessionsTable0000000000004
|
||||
implements MigrationInterface {
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "auth_session",
|
||||
columns: [
|
||||
primaryUUIDColumn,
|
||||
{
|
||||
name: "userId",
|
||||
type: "uuid",
|
||||
},
|
||||
{
|
||||
name: "createdAt",
|
||||
type: "timestamp",
|
||||
default: "CURRENT_TIMESTAMP",
|
||||
},
|
||||
{
|
||||
name: "lastUsedAt",
|
||||
type: "timestamp",
|
||||
default: "CURRENT_TIMESTAMP",
|
||||
},
|
||||
{
|
||||
name: "revokedAt",
|
||||
type: "timestamp",
|
||||
default: null,
|
||||
isNullable: true,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
new TableIndex({
|
||||
name: "IDX_AUTH_SESSION_USER_ID",
|
||||
columnNames: ["userId"],
|
||||
}),
|
||||
],
|
||||
foreignKeys: [
|
||||
new TableForeignKey({
|
||||
name: "FK_AUTH_SESSION_USER_ID",
|
||||
columnNames: ["userId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "user",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable("auth_session");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue