phase01
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { pgTable, uuid, varchar, jsonb, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { organizations } from './organizations';
|
||||
import { users } from './users';
|
||||
import { servers } from './servers';
|
||||
|
||||
export const auditLogs = pgTable('audit_logs', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
organizationId: uuid('organization_id')
|
||||
.notNull()
|
||||
.references(() => organizations.id, { onDelete: 'cascade' }),
|
||||
userId: uuid('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
serverId: uuid('server_id').references(() => servers.id, { onDelete: 'set null' }),
|
||||
action: varchar('action', { length: 255 }).notNull(),
|
||||
metadata: jsonb('metadata').default({}).notNull(),
|
||||
ipAddress: varchar('ip_address', { length: 45 }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { pgTable, uuid, varchar, bigint, text, boolean, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { servers } from './servers';
|
||||
|
||||
export const backups = pgTable('backups', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
serverId: uuid('server_id')
|
||||
.notNull()
|
||||
.references(() => servers.id, { onDelete: 'cascade' }),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
sizeBytes: bigint('size_bytes', { mode: 'number' }),
|
||||
cdnPath: text('cdn_path'),
|
||||
checksum: text('checksum'),
|
||||
isLocked: boolean('is_locked').default(false).notNull(),
|
||||
completedAt: timestamp('completed_at', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import { pgTable, uuid, varchar, integer, text, jsonb, timestamp } from 'drizzle-orm/pg-core';
|
||||
|
||||
export const games = pgTable('games', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
slug: varchar('slug', { length: 100 }).notNull().unique(),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
dockerImage: text('docker_image').notNull(),
|
||||
defaultPort: integer('default_port').notNull(),
|
||||
configFiles: jsonb('config_files').default([]).notNull(),
|
||||
startupCommand: text('startup_command').notNull(),
|
||||
stopCommand: text('stop_command'),
|
||||
environmentVars: jsonb('environment_vars').default([]).notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
export * from './users';
|
||||
export * from './organizations';
|
||||
export * from './nodes';
|
||||
export * from './games';
|
||||
export * from './servers';
|
||||
export * from './backups';
|
||||
export * from './plugins';
|
||||
export * from './schedules';
|
||||
export * from './audit-logs';
|
||||
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
pgTable,
|
||||
uuid,
|
||||
varchar,
|
||||
integer,
|
||||
bigint,
|
||||
text,
|
||||
boolean,
|
||||
timestamp,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { organizations } from './organizations';
|
||||
import { servers } from './servers';
|
||||
|
||||
export const nodes = pgTable('nodes', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
organizationId: uuid('organization_id')
|
||||
.notNull()
|
||||
.references(() => organizations.id, { onDelete: 'cascade' }),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
fqdn: varchar('fqdn', { length: 255 }).notNull(),
|
||||
daemonPort: integer('daemon_port').default(8443).notNull(),
|
||||
grpcPort: integer('grpc_port').default(50051).notNull(),
|
||||
location: varchar('location', { length: 255 }),
|
||||
memoryTotal: bigint('memory_total', { mode: 'number' }).notNull(),
|
||||
diskTotal: bigint('disk_total', { mode: 'number' }).notNull(),
|
||||
memoryOveralloc: integer('memory_overalloc').default(0).notNull(),
|
||||
diskOveralloc: integer('disk_overalloc').default(0).notNull(),
|
||||
daemonToken: text('daemon_token').notNull(),
|
||||
tlsEnabled: boolean('tls_enabled').default(true).notNull(),
|
||||
isOnline: boolean('is_online').default(false).notNull(),
|
||||
lastHeartbeat: timestamp('last_heartbeat', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const allocations = pgTable('allocations', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
nodeId: uuid('node_id')
|
||||
.notNull()
|
||||
.references(() => nodes.id, { onDelete: 'cascade' }),
|
||||
serverId: uuid('server_id').references(() => servers.id, { onDelete: 'set null' }),
|
||||
ip: varchar('ip', { length: 45 }).notNull(),
|
||||
port: integer('port').notNull(),
|
||||
isDefault: boolean('is_default').default(false).notNull(),
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { pgTable, uuid, varchar, integer, timestamp, jsonb, pgEnum } from 'drizzle-orm/pg-core';
|
||||
import { users } from './users';
|
||||
|
||||
export const orgRoleEnum = pgEnum('org_role', ['admin', 'user']);
|
||||
|
||||
export const organizations = pgTable('organizations', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
slug: varchar('slug', { length: 255 }).notNull().unique(),
|
||||
ownerId: uuid('owner_id')
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
maxServers: integer('max_servers').default(0).notNull(),
|
||||
maxNodes: integer('max_nodes').default(0).notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const organizationMembers = pgTable('organization_members', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
organizationId: uuid('organization_id')
|
||||
.notNull()
|
||||
.references(() => organizations.id, { onDelete: 'cascade' }),
|
||||
userId: uuid('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: 'cascade' }),
|
||||
role: orgRoleEnum('role').default('user').notNull(),
|
||||
customPermissions: jsonb('custom_permissions').default({}).notNull(),
|
||||
joinedAt: timestamp('joined_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
pgTable,
|
||||
uuid,
|
||||
varchar,
|
||||
text,
|
||||
boolean,
|
||||
timestamp,
|
||||
pgEnum,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { games } from './games';
|
||||
import { servers } from './servers';
|
||||
|
||||
export const pluginSourceEnum = pgEnum('plugin_source', ['spiget', 'manual']);
|
||||
|
||||
export const plugins = pgTable('plugins', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
gameId: uuid('game_id')
|
||||
.notNull()
|
||||
.references(() => games.id, { onDelete: 'cascade' }),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
slug: varchar('slug', { length: 255 }).notNull(),
|
||||
description: text('description'),
|
||||
source: pluginSourceEnum('source').notNull(),
|
||||
externalId: varchar('external_id', { length: 255 }),
|
||||
downloadUrl: text('download_url'),
|
||||
version: varchar('version', { length: 100 }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const serverPlugins = pgTable('server_plugins', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
serverId: uuid('server_id')
|
||||
.notNull()
|
||||
.references(() => servers.id, { onDelete: 'cascade' }),
|
||||
pluginId: uuid('plugin_id')
|
||||
.notNull()
|
||||
.references(() => plugins.id, { onDelete: 'cascade' }),
|
||||
installedVersion: varchar('installed_version', { length: 100 }),
|
||||
isActive: boolean('is_active').default(true).notNull(),
|
||||
installedAt: timestamp('installed_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
pgTable,
|
||||
uuid,
|
||||
varchar,
|
||||
text,
|
||||
boolean,
|
||||
jsonb,
|
||||
timestamp,
|
||||
pgEnum,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { servers } from './servers';
|
||||
|
||||
export const scheduleActionEnum = pgEnum('schedule_action', ['command', 'power', 'backup']);
|
||||
|
||||
export const scheduleTypeEnum = pgEnum('schedule_type', [
|
||||
'interval',
|
||||
'daily',
|
||||
'weekly',
|
||||
'cron',
|
||||
]);
|
||||
|
||||
export const scheduledTasks = pgTable('scheduled_tasks', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
serverId: uuid('server_id')
|
||||
.notNull()
|
||||
.references(() => servers.id, { onDelete: 'cascade' }),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
action: scheduleActionEnum('action').notNull(),
|
||||
payload: text('payload').notNull(),
|
||||
scheduleType: scheduleTypeEnum('schedule_type').notNull(),
|
||||
scheduleData: jsonb('schedule_data').notNull(),
|
||||
isActive: boolean('is_active').default(true).notNull(),
|
||||
lastRunAt: timestamp('last_run_at', { withTimezone: true }),
|
||||
nextRunAt: timestamp('next_run_at', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
pgTable,
|
||||
uuid,
|
||||
varchar,
|
||||
integer,
|
||||
bigint,
|
||||
text,
|
||||
jsonb,
|
||||
timestamp,
|
||||
pgEnum,
|
||||
} from 'drizzle-orm/pg-core';
|
||||
import { organizations } from './organizations';
|
||||
import { nodes } from './nodes';
|
||||
import { games } from './games';
|
||||
import { users } from './users';
|
||||
|
||||
export const serverStatusEnum = pgEnum('server_status', [
|
||||
'installing',
|
||||
'running',
|
||||
'stopped',
|
||||
'suspended',
|
||||
'error',
|
||||
]);
|
||||
|
||||
export const servers = pgTable('servers', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
uuid: varchar('uuid', { length: 36 }).notNull().unique(),
|
||||
organizationId: uuid('organization_id')
|
||||
.notNull()
|
||||
.references(() => organizations.id, { onDelete: 'cascade' }),
|
||||
nodeId: uuid('node_id')
|
||||
.notNull()
|
||||
.references(() => nodes.id),
|
||||
gameId: uuid('game_id')
|
||||
.notNull()
|
||||
.references(() => games.id),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
description: text('description'),
|
||||
status: serverStatusEnum('status').default('installing').notNull(),
|
||||
memoryLimit: bigint('memory_limit', { mode: 'number' }).notNull(),
|
||||
diskLimit: bigint('disk_limit', { mode: 'number' }).notNull(),
|
||||
cpuLimit: integer('cpu_limit').default(100).notNull(),
|
||||
port: integer('port').notNull(),
|
||||
additionalPorts: jsonb('additional_ports').default([]).notNull(),
|
||||
environment: jsonb('environment').default({}).notNull(),
|
||||
startupOverride: text('startup_override'),
|
||||
installedAt: timestamp('installed_at', { withTimezone: true }),
|
||||
suspendedAt: timestamp('suspended_at', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const serverSubusers = pgTable('server_subusers', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
serverId: uuid('server_id')
|
||||
.notNull()
|
||||
.references(() => servers.id, { onDelete: 'cascade' }),
|
||||
userId: uuid('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: 'cascade' }),
|
||||
permissions: jsonb('permissions').notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { pgTable, uuid, varchar, text, boolean, timestamp } from 'drizzle-orm/pg-core';
|
||||
|
||||
export const users = pgTable('users', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
email: varchar('email', { length: 255 }).notNull().unique(),
|
||||
username: varchar('username', { length: 100 }).notNull().unique(),
|
||||
passwordHash: text('password_hash').notNull(),
|
||||
isSuperAdmin: boolean('is_super_admin').default(false).notNull(),
|
||||
avatarUrl: text('avatar_url'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
Reference in New Issue
Block a user