Files
usenet-indexer/database/migrations/1770000000900_create_nodes.ts

31 lines
1.1 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
/** Edge workers and their API tokens (the `node` guard). */
export default class extends BaseSchema {
async up() {
this.schema.createTable('nodes', (table) => {
table.increments('id')
table.string('name', 64).notNullable().unique()
table.timestamp('last_seen_at', { useTz: true }).nullable()
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(this.now())
})
this.schema.createTable('node_access_tokens', (table) => {
table.increments('id')
table.integer('tokenable_id').notNullable().unsigned().references('id').inTable('nodes').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.timestamp('expires_at').nullable()
})
}
async down() {
this.schema.dropTable('node_access_tokens')
this.schema.dropTable('nodes')
}
}