Files
wireguard-ui/db/schema.ts
T
2026-09-20 07:27:29 +01:00

298 lines
9.0 KiB
TypeScript

import {
ClientRuleProtocols,
ClientRuleTypes,
} from "@/src/dict/client-rules-dict";
import { MediaParadigms, MediaTypes } from "@/src/dict/media-dict";
import { UserTypes } from "@/src/dict/user-types-dict";
import { Variables } from "@/src/dict/variables-dict";
import type { BUN_SQLITE_DatabaseSchemaType } from "@moduletrace/bun-sqlite/dist/types";
const schema: BUN_SQLITE_DatabaseSchemaType = {
tables: [
{
tableName: "users",
fields: [
{
fieldName: "first_name",
dataType: "TEXT",
},
{
fieldName: "last_name",
dataType: "TEXT",
},
{
fieldName: "email",
dataType: "TEXT",
unique: true,
},
{
fieldName: "username",
dataType: "TEXT",
unique: true,
},
{
fieldName: "password",
dataType: "TEXT",
},
{
fieldName: "bio",
dataType: "TEXT",
html: true,
},
{
fieldName: "archived",
dataType: "INTEGER",
options: [0, 1],
defaultValue: 0,
},
],
},
{
tableName: "user_types",
fields: [
{
fieldName: "user_id",
dataType: "INTEGER",
},
{
fieldName: "user_type",
dataType: "TEXT",
options: UserTypes.map((ut) => ut.value),
},
],
},
{
tableName: "media",
fields: [
{
fieldName: "user_id",
dataType: "INTEGER",
},
{
fieldName: "title",
dataType: "TEXT",
},
{
fieldName: "description",
dataType: "TEXT",
},
{
fieldName: "summary",
dataType: "TEXT",
},
{
fieldName: "media_type",
dataType: "TEXT",
options: MediaTypes.map((it) => it.value),
},
{
fieldName: "media_write_path",
dataType: "TEXT",
},
{
fieldName: "media_thumbnail_write_path",
dataType: "TEXT",
},
{
fieldName: "mime_type",
dataType: "TEXT",
},
{
fieldName: "text_content",
dataType: "TEXT",
},
{
fieldName: "is_primary",
dataType: "INTEGER",
options: [0, 1],
},
{
fieldName: "is_rag_ingested",
dataType: "INTEGER",
options: [0, 1],
},
{
fieldName: "is_private",
dataType: "INTEGER",
options: [0, 1],
},
{
fieldName: "archived",
dataType: "INTEGER",
options: [0, 1],
},
],
uniqueConstraints: [
{
alias: "one_user_per_primary_profile_image",
constraintName: "One User per primary profile image",
constraintTableFields: [
{ value: "user_id" },
{ value: "is_primary" },
],
},
],
},
{
tableName: "media_paradigms",
fields: [
{
fieldName: "media_id",
dataType: "INTEGER",
foreignKey: {
cascadeDelete: true,
destinationTableName: "media",
destinationTableColumnName: "id",
destinationTableColumnType: "INTEGER",
foreignKeyName: "media_paradigm_media_fk",
},
},
{
fieldName: "media_paradigm",
dataType: "TEXT",
options: MediaParadigms.map((mp) => mp.value),
},
],
},
{
tableName: "clients",
fields: [
{
fieldName: "user_id",
dataType: "INTEGER",
},
{
fieldName: "host_id",
dataType: "INTEGER",
defaultValue: 0,
},
{
fieldName: "name",
dataType: "TEXT",
},
{
fieldName: "wg_ip_address",
dataType: "TEXT",
},
{
fieldName: "public_ip_address",
dataType: "TEXT",
},
{
fieldName: "public_key",
dataType: "TEXT",
},
{
fieldName: "allowed_ips",
dataType: "TEXT",
},
{
fieldName: "allow_all_ips",
dataType: "INTEGER",
options: [0, 1],
},
{
fieldName: "notes",
dataType: "TEXT",
},
],
uniqueConstraints: [
{
constraintName: "Unique client IPs per host",
alias: "unique_client_ip_per_host",
constraintTableFields: [
{
value: "host_id",
},
{
value: "wg_ip_address",
},
],
},
],
},
{
tableName: "hosts",
fields: [
{
fieldName: "user_id",
dataType: "INTEGER",
},
{
fieldName: "public_ip_address",
dataType: "TEXT",
},
{
fieldName: "wg_ip_address",
dataType: "TEXT",
},
{
fieldName: "public_key",
dataType: "TEXT",
},
],
},
{
tableName: "client_rules",
tableDescription: `IP table rules for this client`,
fields: [
{
fieldName: "user_id",
dataType: "INTEGER",
},
{
fieldName: "host_id",
dataType: "INTEGER",
defaultValue: 0,
},
{
fieldName: "client_id",
dataType: "INTEGER",
foreignKey: {
cascadeDelete: true,
destinationTableName: "clients",
destinationTableColumnName: "id",
destinationTableColumnType: "INTEGER",
foreignKeyName: "client_rules_client_fk",
},
},
{
fieldName: "rule_type",
dataType: "TEXT",
options: ClientRuleTypes.map((rt) => rt.value),
},
{
fieldName: "destination",
dataType: "TEXT",
},
{
fieldName: "ports",
dataType: "TEXT",
},
{
fieldName: "protocol",
dataType: "TEXT",
options: ClientRuleProtocols.map((p) => p.value),
},
],
},
{
tableName: "variables",
fields: [
{
fieldName: "key",
dataType: "TEXT",
options: Variables.map((v) => v.value),
unique: true,
},
{
fieldName: "value",
dataType: "TEXT",
},
],
},
],
};
export default schema;