From fd77ad5cd3213752a6deba3ea4389bd70b5a1519 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Thu, 28 Apr 2022 19:17:25 -0500 Subject: [PATCH] Create migration for oauth2_tokens table --- package.json | 2 +- src/auth/server/models/OAuth2TokenModel.ts | 2 +- ....000Z_CreateOAuth2TokensTable.migration.ts | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/migrations/2022-04-28T19:04:55.000Z_CreateOAuth2TokensTable.migration.ts diff --git a/package.json b/package.json index 39f1b36..58d28c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.9.39", + "version": "0.9.40", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/auth/server/models/OAuth2TokenModel.ts b/src/auth/server/models/OAuth2TokenModel.ts index 1cb6d24..402489f 100644 --- a/src/auth/server/models/OAuth2TokenModel.ts +++ b/src/auth/server/models/OAuth2TokenModel.ts @@ -14,7 +14,7 @@ export class OAuth2TokenModel extends Model implements OAuth2T } @Field(FieldType.varchar, 'user_id') - public userId!: string + public userId?: string @Field(FieldType.varchar, 'client_id') public clientId!: string diff --git a/src/migrations/2022-04-28T19:04:55.000Z_CreateOAuth2TokensTable.migration.ts b/src/migrations/2022-04-28T19:04:55.000Z_CreateOAuth2TokensTable.migration.ts new file mode 100644 index 0000000..e03a2c5 --- /dev/null +++ b/src/migrations/2022-04-28T19:04:55.000Z_CreateOAuth2TokensTable.migration.ts @@ -0,0 +1,46 @@ +import {DatabaseService, FieldType, Migration, raw, Schema} from '../orm' +import {Inject} from '../di' + +export default class CreateOAuth2TokensTableMigration extends Migration { + @Inject() + protected readonly db!: DatabaseService + + async up(): Promise { + const schema: Schema = this.db.get().schema() + const table = await schema.table('oauth2_tokens') + + table.primaryKey('oauth2_token_id').required() + + table.column('user_id') + .type(FieldType.varchar) + .nullable() + + table.column('client_id') + .type(FieldType.varchar) + .required() + + table.column('issued') + .type(FieldType.timestamp) + .default(raw('NOW()')) + .required() + + table.column('expires') + .type(FieldType.timestamp) + .required() + + table.column('scope') + .type(FieldType.varchar) + .nullable() + + await schema.commit(table) + } + + async down(): Promise { + const schema: Schema = this.db.get().schema() + const table = await schema.table('oauth2_tokens') + + table.dropIfExists() + + await schema.commit(table) + } +}