Files
big-brother/api/database/migrations/1770000000002_create_sites_table.ts
T
2026-10-12 14:25:22 +02:00

58 lines
1.7 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* Sites are synchronized from the Caddyfile and checked every minute.
*/
export default class extends BaseSchema {
async up() {
this.schema.createTable('sites', (table) => {
table.increments('id')
table.string('domain').notNullable().unique()
/**
* False once the domain disappeared from the Caddyfile.
*/
table.boolean('active').notNullable().defaultTo(true)
/**
* What Caddy serves: "proxy" (upstream = container:port) or "static" (upstream = root path).
*/
table.string('kind').nullable()
table.string('upstream').nullable()
table.boolean('last_ok').nullable()
table.integer('last_status').nullable()
table.integer('last_response_ms').nullable()
table.text('last_error').nullable()
table.integer('last_checked_at').nullable()
table.integer('cert_expires_at').nullable()
table.integer('cert_checked_at').nullable()
table.timestamp('created_at').notNullable()
table.timestamp('updated_at').nullable()
})
this.schema.createTable('site_checks', (table) => {
table.increments('id')
table
.integer('site_id')
.notNullable()
.unsigned()
.references('id')
.inTable('sites')
.onDelete('CASCADE')
table.integer('ts').notNullable()
table.boolean('ok').notNullable()
table.integer('status').nullable()
table.integer('response_ms').nullable()
table.text('error').nullable()
table.index(['site_id', 'ts'])
})
}
async down() {
this.schema.dropTable('site_checks')
this.schema.dropTable('sites')
}
}