first commit

This commit is contained in:
Rutra committed 2026-10-12 14:25:22 +02:00
commit 3c0479faf0
169 files changed
+27617

No files matched your search

@@ -0,0 +1,30 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'users'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').notNullable()
table.string('username', 64).notNullable().unique()
table.string('password').notNullable()
/**
* TOTP secret, encrypted with the APP_KEY.
*/
table.text('totp_secret').notNullable()
/**
* Last accepted TOTP time step, to refuse a code being replayed.
*/
table.integer('totp_last_step').nullable()
table.timestamp('created_at').notNullable()
table.timestamp('updated_at').nullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,27 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* One row per minute with the averaged host metrics.
*/
export default class extends BaseSchema {
protected tableName = 'metrics'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.integer('ts').notNullable().index()
table.float('cpu').notNullable()
table.float('load1').nullable()
table.bigInteger('mem_used').notNullable()
table.bigInteger('mem_total').notNullable()
table.bigInteger('disk_used').notNullable()
table.bigInteger('disk_total').notNullable()
table.float('net_rx').nullable()
table.float('net_tx').nullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,57 @@
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')
}
}
@@ -0,0 +1,32 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* Every action done from the dashboard, with the output of the commands.
*/
export default class extends BaseSchema {
protected tableName = 'audit_logs'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.string('username').nullable()
table.string('ip').nullable()
table.string('action').notNullable()
table.string('target').nullable()
/**
* "running", "success" or "error"
*/
table.string('status').notNullable()
table.text('output').nullable()
table.timestamp('created_at').notNullable()
table.timestamp('finished_at').nullable()
table.index(['created_at'])
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,22 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
/**
* Previous contents of the Caddyfile, saved before every change.
*/
export default class extends BaseSchema {
protected tableName = 'caddyfile_versions'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.text('content').notNullable()
table.string('username').nullable()
table.string('reason').nullable()
table.timestamp('created_at').notNullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
+142
View File
@@ -0,0 +1,142 @@
/**
* This file is automatically generated
* DO NOT EDIT manually
* Run "node ace migration:run" command to re-generate this file
*/
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { DateTime } from 'luxon'
export class AuditLogSchema extends BaseModel {
static $columns = ['action', 'createdAt', 'finishedAt', 'id', 'ip', 'output', 'status', 'target', 'username'] as const
$columns = AuditLogSchema.$columns
@column()
declare action: string
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column.dateTime()
declare finishedAt: DateTime | null
@column({ isPrimary: true })
declare id: number
@column()
declare ip: string | null
@column()
declare output: string | null
@column()
declare status: string
@column()
declare target: string | null
@column()
declare username: string | null
}
export class CaddyfileVersionSchema extends BaseModel {
static $columns = ['content', 'createdAt', 'id', 'reason', 'username'] as const
$columns = CaddyfileVersionSchema.$columns
@column()
declare content: string
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column({ isPrimary: true })
declare id: number
@column()
declare reason: string | null
@column()
declare username: string | null
}
export class MetricSchema extends BaseModel {
static $columns = ['cpu', 'diskTotal', 'diskUsed', 'id', 'load1', 'memTotal', 'memUsed', 'netRx', 'netTx', 'ts'] as const
$columns = MetricSchema.$columns
@column()
declare cpu: number
@column()
declare diskTotal: bigint | number
@column()
declare diskUsed: bigint | number
@column({ isPrimary: true })
declare id: number
@column()
declare load1: number | null
@column()
declare memTotal: bigint | number
@column()
declare memUsed: bigint | number
@column()
declare netRx: number | null
@column()
declare netTx: number | null
@column()
declare ts: number
}
export class SiteCheckSchema extends BaseModel {
static $columns = ['error', 'id', 'ok', 'responseMs', 'siteId', 'status', 'ts'] as const
$columns = SiteCheckSchema.$columns
@column()
declare error: string | null
@column({ isPrimary: true })
declare id: number
@column()
declare ok: boolean
@column()
declare responseMs: number | null
@column()
declare siteId: number
@column()
declare status: number | null
@column()
declare ts: number
}
export class SiteSchema extends BaseModel {
static $columns = ['active', 'certCheckedAt', 'certExpiresAt', 'createdAt', 'domain', 'id', 'kind', 'lastCheckedAt', 'lastError', 'lastOk', 'lastResponseMs', 'lastStatus', 'updatedAt', 'upstream'] as const
$columns = SiteSchema.$columns
@column()
declare active: boolean
@column()
declare certCheckedAt: number | null
@column()
declare certExpiresAt: number | null
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column()
declare domain: string
@column({ isPrimary: true })
declare id: number
@column()
declare kind: string | null
@column()
declare lastCheckedAt: number | null
@column()
declare lastError: string | null
@column()
declare lastOk: boolean | null
@column()
declare lastResponseMs: number | null
@column()
declare lastStatus: number | null
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
@column()
declare upstream: string | null
}
export class UserSchema extends BaseModel {
static $columns = ['createdAt', 'id', 'password', 'totpLastStep', 'totpSecret', 'updatedAt', 'username'] as const
$columns = UserSchema.$columns
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column({ isPrimary: true })
declare id: number
@column({ serializeAs: null })
declare password: string
@column()
declare totpLastStep: number | null
@column()
declare totpSecret: string
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
@column()
declare username: string
}
+3
View File
@@ -0,0 +1,3 @@
import { type SchemaRules } from '@adonisjs/lucid/types/schema_generator'
export default {} satisfies SchemaRules