feat: Consolidate user, role, and theme settings tables into a single migration file
This commit is contained in:
@@ -158,4 +158,32 @@ ALTER TABLE capex
|
||||
ALTER TABLE opex
|
||||
DROP COLUMN IF EXISTS currency_code;
|
||||
|
||||
-- Role-based access control tables
|
||||
CREATE TABLE IF NOT EXISTS roles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(255) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
hashed_password VARCHAR(255) NOT NULL,
|
||||
role_id INTEGER NOT NULL REFERENCES roles (id) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_users_username ON users (username);
|
||||
CREATE INDEX IF NOT EXISTS ix_users_email ON users (email);
|
||||
|
||||
-- Theme settings configuration table
|
||||
CREATE TABLE IF NOT EXISTS theme_settings (
|
||||
id SERIAL PRIMARY KEY,
|
||||
theme_name VARCHAR(255) UNIQUE NOT NULL,
|
||||
primary_color VARCHAR(7) NOT NULL,
|
||||
secondary_color VARCHAR(7) NOT NULL,
|
||||
accent_color VARCHAR(7) NOT NULL,
|
||||
background_color VARCHAR(7) NOT NULL,
|
||||
text_color VARCHAR(7) NOT NULL
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
-- Migration: Create application_setting table for configurable application options
|
||||
-- Date: 2025-10-25
|
||||
-- Description: Introduces persistent storage for application-level settings such as theme colors.
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS application_setting (
|
||||
id SERIAL PRIMARY KEY,
|
||||
key VARCHAR(128) NOT NULL UNIQUE,
|
||||
value TEXT NOT NULL,
|
||||
value_type VARCHAR(32) NOT NULL DEFAULT 'string',
|
||||
category VARCHAR(32) NOT NULL DEFAULT 'general',
|
||||
description TEXT,
|
||||
is_editable BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_application_setting_key
|
||||
ON application_setting (key);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_application_setting_category
|
||||
ON application_setting (category);
|
||||
|
||||
COMMIT;
|
||||
@@ -1,11 +0,0 @@
|
||||
-- Migration: 20251027_create_theme_settings_table.sql
|
||||
|
||||
CREATE TABLE theme_settings (
|
||||
id SERIAL PRIMARY KEY,
|
||||
theme_name VARCHAR(255) UNIQUE NOT NULL,
|
||||
primary_color VARCHAR(7) NOT NULL,
|
||||
secondary_color VARCHAR(7) NOT NULL,
|
||||
accent_color VARCHAR(7) NOT NULL,
|
||||
background_color VARCHAR(7) NOT NULL,
|
||||
text_color VARCHAR(7) NOT NULL
|
||||
);
|
||||
@@ -1,15 +0,0 @@
|
||||
-- Migration: 20251027_create_user_and_role_tables.sql
|
||||
|
||||
CREATE TABLE roles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(255) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
hashed_password VARCHAR(255) NOT NULL,
|
||||
role_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (role_id) REFERENCES roles(id)
|
||||
);
|
||||
Reference in New Issue
Block a user