add user-project relation and role-based filtering
This commit is contained in:
27
water-api/sql/add_user_project_relation.sql
Normal file
27
water-api/sql/add_user_project_relation.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- ============================================================================
|
||||
-- Add project_id to users table
|
||||
-- This allows assigning a specific project to OPERATOR users
|
||||
-- ADMIN users don't need a project assignment (can see all projects)
|
||||
-- ============================================================================
|
||||
|
||||
-- Add project_id column to users table
|
||||
ALTER TABLE users
|
||||
ADD COLUMN project_id UUID REFERENCES projects(id) ON DELETE SET NULL;
|
||||
|
||||
-- Add index for better query performance
|
||||
CREATE INDEX idx_users_project_id ON users(project_id);
|
||||
|
||||
-- Add comment
|
||||
COMMENT ON COLUMN users.project_id IS 'Assigned project for OPERATOR users. NULL for ADMIN users who can access all projects.';
|
||||
|
||||
-- ============================================================================
|
||||
-- Verify the change
|
||||
-- ============================================================================
|
||||
SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'users'
|
||||
AND column_name = 'project_id';
|
||||
Reference in New Issue
Block a user