mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Initial commit
This commit is contained in:
53
.bolt/supabase_discarded_migrations/0003_proud_cloud.sql
Normal file
53
.bolt/supabase_discarded_migrations/0003_proud_cloud.sql
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
# Fix Authentication Table Structure
|
||||
|
||||
1. Changes
|
||||
- Recreate employees table with correct structure
|
||||
- Add proper indexes
|
||||
- Insert admin user
|
||||
|
||||
2. Security
|
||||
- Enable RLS
|
||||
- Add proper policies
|
||||
*/
|
||||
|
||||
-- Recreate the employees table with correct structure
|
||||
CREATE TABLE IF NOT EXISTS employees (
|
||||
username text PRIMARY KEY,
|
||||
last_name text NOT NULL,
|
||||
department text NOT NULL,
|
||||
last_login_timestamp timestamptz,
|
||||
created_at timestamptz DEFAULT now()
|
||||
);
|
||||
|
||||
-- Enable RLS
|
||||
ALTER TABLE employees ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Create policies
|
||||
CREATE POLICY "Users can read own data"
|
||||
ON employees
|
||||
FOR SELECT
|
||||
TO authenticated
|
||||
USING (auth.uid()::text = username);
|
||||
|
||||
CREATE POLICY "Users can update their own data"
|
||||
ON employees
|
||||
FOR UPDATE
|
||||
TO authenticated
|
||||
USING (auth.uid()::text = username)
|
||||
WITH CHECK (auth.uid()::text = username);
|
||||
|
||||
-- Add indexes
|
||||
CREATE INDEX IF NOT EXISTS idx_employees_username
|
||||
ON employees(username);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_employees_last_login
|
||||
ON employees(last_login_timestamp);
|
||||
|
||||
-- Insert admin user (if not exists)
|
||||
INSERT INTO employees (username, last_name, department)
|
||||
VALUES (
|
||||
'admin',
|
||||
'Administrator',
|
||||
'IT'
|
||||
) ON CONFLICT (username) DO NOTHING;
|
Reference in New Issue
Block a user