Axium/migrations/20250128160043_create_roles_table.sql
2025-01-30 22:43:30 +01:00

20 lines
854 B
SQL

-- Create the roles table
CREATE TABLE IF NOT EXISTS roles (
id SERIAL PRIMARY KEY,
level INT NOT NULL,
role VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
CONSTRAINT unique_role UNIQUE (role) -- Add a unique constraint to the 'role' column
);
-- Insert a role into the roles table (this assumes role_id=1 is for 'user')
INSERT INTO roles (level, role, name, description)
VALUES (1, 'user', 'User', 'A regular user with basic access.')
ON CONFLICT (role) DO NOTHING; -- Prevent duplicate insertions if role already exists
-- Insert a role into the roles table (this assumes role_id=2 is for 'admin')
INSERT INTO roles (level, role, name, description)
VALUES (2, 'admin', 'Administrator', 'An administrator.')
ON CONFLICT (role) DO NOTHING; -- Prevent duplicate insertions if role already exists