Skip to content

Commit

Permalink
Merge pull request #86 from andrewwippler/feature/frontend-uploads
Browse files Browse the repository at this point in the history
Fix migrations for live DB
  • Loading branch information
andrewwippler authored Jul 27, 2024
2 parents e5c50c9 + f9c167c commit 0df8e70
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class User extends compose(BaseModel, AuthFinder) {
static accessTokens = DbAccessTokensProvider.forModel(User, {
expiresIn: '30 days',
prefix: 'oat_',
table: 'api_tokens',
table: 'auth_access_tokens',
type: 'auth_token',
tokenSecretLength: 40,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
protected tableName = 'api_tokens'
protected tableName = 'auth_access_tokens'

async up() {
this.schema.alterTable(this.tableName, (table) => {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table
.integer('tokenable_id')
.notNullable()
Expand All @@ -13,25 +14,18 @@ export default class extends BaseSchema {
.inTable('users')
.onDelete('CASCADE')

table.string('type').notNullable()
table.string('name').nullable()
table.string('hash').notNullable()
table.text('abilities').notNullable()
table.timestamp('created_at')
table.timestamp('updated_at')
table.timestamp('last_used_at').nullable()
table.string('name').nullable().alter()
table.dropColumn('token')
table.timestamp('expires_at').nullable()
})
}

async down() {
this.schema.alterTable(this.tableName, (table) => {
table.dropColumn('last_used_at')
table.dropColumn('updated_at')
table.dropColumn('abilities')
table.dropColumn('hash')
table.dropForeign('tokenable_id')
table.string('name').notNullable().alter()
table.string('token', 64).notNullable().unique()
})
this.schema.dropTable(this.tableName)
}

}
}
26 changes: 26 additions & 0 deletions api/database/migrations/1722051530896_delete_api_tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
protected tableName = 'api_tokens'

async up() {
this.schema.dropTable(this.tableName)
}

async down() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.integer('user_id').unsigned().index('user_id')
table.foreign('user_id').references('users.id').onDelete('cascade')
table.string('name').notNullable()
table.string('type').notNullable()
table.string('token', 64).notNullable().unique()

/**
* Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
*/
table.timestamp('expires_at', { useTz: true }).nullable()
table.timestamp('created_at', { useTz: true }).notNullable()
})
}
}
4 changes: 2 additions & 2 deletions api/tests/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
}

export const reporters: Config['reporters'] = {
activated: ['ndjson'],
// activated: ['spec'],
// activated: ['ndjson'],
activated: ['spec'],
}


Expand Down

0 comments on commit 0df8e70

Please sign in to comment.