fixing bugs

This commit is contained in:
DioCrafts
2025-03-23 22:44:18 +01:00
parent 72de043184
commit 9a9fd72f61
54 changed files with 2593 additions and 513 deletions
+4 -1
View File
@@ -1,13 +1,16 @@
-- Create the auth schema
CREATE SCHEMA IF NOT EXISTS auth;
-- Create UserRole enum type
CREATE TYPE auth.userrole AS ENUM ('admin', 'user');
-- Create the users table
CREATE TABLE IF NOT EXISTS auth.users (
id VARCHAR(36) PRIMARY KEY,
username VARCHAR(32) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
role VARCHAR(10) NOT NULL,
role auth.userrole NOT NULL,
storage_quota_bytes BIGINT NOT NULL,
storage_used_bytes BIGINT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL,
+25
View File
@@ -0,0 +1,25 @@
-- Fix the missing UserRole enum type
CREATE TYPE auth.userrole AS ENUM ('admin', 'user');
-- If the table already exists but has a different role column type,
-- we need to update it to use the new enum type
DO $$
BEGIN
-- Check if the users table exists
IF EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'auth' AND table_name = 'users'
) THEN
-- Try to convert the role column to the new enum type
-- This will work if the column currently contains 'admin' or 'user' values
BEGIN
ALTER TABLE auth.users ALTER COLUMN role TYPE auth.userrole USING
CASE WHEN role = 'admin' THEN 'admin'::auth.userrole
WHEN role = 'user' THEN 'user'::auth.userrole
ELSE 'user'::auth.userrole END;
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'Error converting role column: %', SQLERRM;
END;
END IF;
END
$$;