DNS backend

This commit is contained in:
Face
2025-08-12 21:31:09 +03:00
parent c61167b834
commit 65f3a21890
22 changed files with 5916 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
-- Create users table
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
registrations_remaining INTEGER DEFAULT 3,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create invite codes table
CREATE TABLE IF NOT EXISTS invite_codes (
id SERIAL PRIMARY KEY,
code VARCHAR(32) UNIQUE NOT NULL,
created_by INTEGER REFERENCES users(id),
used_by INTEGER REFERENCES users(id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
used_at TIMESTAMP
);
-- Create domains table
CREATE TABLE IF NOT EXISTS domains (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
tld VARCHAR(20) NOT NULL,
ip VARCHAR(255) NOT NULL,
user_id INTEGER REFERENCES users(id),
status VARCHAR(20) DEFAULT 'pending',
denial_reason TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(name, tld)
);
-- Create indexes for faster lookups
CREATE INDEX IF NOT EXISTS idx_domains_name_tld ON domains(name, tld);
CREATE INDEX IF NOT EXISTS idx_domains_user_id ON domains(user_id);
CREATE INDEX IF NOT EXISTS idx_domains_status ON domains(status);
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
CREATE INDEX IF NOT EXISTS idx_invite_codes_code ON invite_codes(code);

View File

@@ -0,0 +1,5 @@
-- Remove email field from users table
ALTER TABLE users DROP COLUMN IF EXISTS email;
-- Drop email index if it exists
DROP INDEX IF EXISTS idx_users_email;

View File

@@ -0,0 +1,5 @@
-- Fix timestamp columns to use TIMESTAMPTZ instead of TIMESTAMP
ALTER TABLE users ALTER COLUMN created_at TYPE TIMESTAMPTZ;
ALTER TABLE invite_codes ALTER COLUMN created_at TYPE TIMESTAMPTZ;
ALTER TABLE invite_codes ALTER COLUMN used_at TYPE TIMESTAMPTZ;
ALTER TABLE domains ALTER COLUMN created_at TYPE TIMESTAMPTZ;

View File

@@ -0,0 +1,17 @@
-- Add domain_invite_codes field to users table
ALTER TABLE users ADD COLUMN domain_invite_codes INTEGER DEFAULT 3;
-- Create domain invite codes table for domain-specific invites
CREATE TABLE IF NOT EXISTS domain_invite_codes (
id SERIAL PRIMARY KEY,
code VARCHAR(32) UNIQUE NOT NULL,
created_by INTEGER REFERENCES users(id),
used_by INTEGER REFERENCES users(id),
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
used_at TIMESTAMPTZ
);
-- Create indexes for faster lookups
CREATE INDEX IF NOT EXISTS idx_domain_invite_codes_code ON domain_invite_codes(code);
CREATE INDEX IF NOT EXISTS idx_domain_invite_codes_created_by ON domain_invite_codes(created_by);
CREATE INDEX IF NOT EXISTS idx_domain_invite_codes_used_by ON domain_invite_codes(used_by);