225 lines
7.9 KiB
PL/PgSQL
225 lines
7.9 KiB
PL/PgSQL
-- =============================================================================
|
|
-- DEVELOPMENT SEED DATA
|
|
-- =============================================================================
|
|
-- WARNING: DO NOT RUN IN PRODUCTION!
|
|
-- =============================================================================
|
|
-- =============================================================================
|
|
-- Temporarily disable RLS inside the seed script
|
|
-- =============================================================================
|
|
ALTER TABLE tenants DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE users DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE contracts DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE deliverables DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE milestones DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE comments DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE attachments DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE audit_logs DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE analytics_events DISABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE notifications DISABLE ROW LEVEL SECURITY;
|
|
-- =============================================================================
|
|
|
|
BEGIN;
|
|
|
|
-- =============================================================================
|
|
-- Create test tenants
|
|
-- =============================================================================
|
|
|
|
-- Permanent tenant 1: ACME Corporation
|
|
INSERT INTO tenants (id, name, type) VALUES
|
|
('10000000-0000-0000-0000-000000000001', 'ACME Corporation', 'permanent');
|
|
|
|
-- Permanent tenant 2: TechStart Inc
|
|
INSERT INTO tenants (id, name, type) VALUES
|
|
('20000000-0000-0000-0000-000000000002', 'TechStart Inc', 'permanent');
|
|
|
|
-- Temporary tenant (project workspace)
|
|
INSERT INTO tenants (id, name, type, parent_tenant_id, expires_at) VALUES
|
|
('30000000-0000-0000-0000-000000000003',
|
|
'ACME-Website-Project',
|
|
'temporary',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
NOW() + INTERVAL '6 months');
|
|
|
|
-- =============================================================================
|
|
-- Create test users
|
|
-- =============================================================================
|
|
|
|
-- ACME Corporation users
|
|
-- Password for all: "password123" (hashed with bcrypt cost 12)
|
|
INSERT INTO users (id, tenant_id, email, password_hash, name, role) VALUES
|
|
-- Admin
|
|
('11000000-0000-0000-0000-000000000001',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'admin@acme.com',
|
|
'$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYKU.PN5Hyu',
|
|
'Alice Admin',
|
|
'admin'),
|
|
|
|
-- Vendor
|
|
('11000000-0000-0000-0000-000000000002',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'vendor@acme.com',
|
|
'$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYKU.PN5Hyu',
|
|
'Bob Vendor',
|
|
'vendor'),
|
|
|
|
-- Consumer
|
|
('11000000-0000-0000-0000-000000000003',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'consumer@acme.com',
|
|
'$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYKU.PN5Hyu',
|
|
'Charlie Consumer',
|
|
'consumer');
|
|
|
|
-- TechStart Inc users
|
|
INSERT INTO users (id, tenant_id, email, password_hash, name, role) VALUES
|
|
('21000000-0000-0000-0000-000000000001',
|
|
'20000000-0000-0000-0000-000000000002',
|
|
'admin@techstart.com',
|
|
'$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYKU.PN5Hyu',
|
|
'Diana Director',
|
|
'admin');
|
|
|
|
-- =============================================================================
|
|
-- Create test contracts
|
|
-- =============================================================================
|
|
|
|
INSERT INTO contracts (
|
|
id, tenant_id, vendor_id, consumer_id,
|
|
title, description, status,
|
|
start_date, end_date, total_amount, created_by
|
|
) VALUES
|
|
-- Active contract
|
|
('c1000000-0000-0000-0000-000000000001',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'11000000-0000-0000-0000-000000000002',
|
|
'11000000-0000-0000-0000-000000000003',
|
|
'Website Redesign Project',
|
|
'Complete overhaul of company website with modern design and responsive layout.',
|
|
'active',
|
|
CURRENT_DATE - INTERVAL '1 month',
|
|
CURRENT_DATE + INTERVAL '5 months',
|
|
50000.00,
|
|
'11000000-0000-0000-0000-000000000003'),
|
|
|
|
-- Draft contract
|
|
('c2000000-0000-0000-0000-000000000002',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'11000000-0000-0000-0000-000000000002',
|
|
'11000000-0000-0000-0000-000000000003',
|
|
'Mobile App Development',
|
|
'Native mobile application for iOS and Android platforms.',
|
|
'draft',
|
|
CURRENT_DATE + INTERVAL '1 month',
|
|
CURRENT_DATE + INTERVAL '7 months',
|
|
75000.00,
|
|
'11000000-0000-0000-0000-000000000003');
|
|
|
|
-- =============================================================================
|
|
-- Create test deliverables
|
|
-- =============================================================================
|
|
|
|
INSERT INTO deliverables (
|
|
id, tenant_id, contract_id,
|
|
title, description, sequence_number, status, deadline
|
|
) VALUES
|
|
-- Website project deliverables
|
|
('d1000000-0000-0000-0000-000000000001',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'c1000000-0000-0000-0000-000000000001',
|
|
'Homepage Design',
|
|
'Design mockups for the homepage including desktop and mobile views.',
|
|
1,
|
|
'approved',
|
|
CURRENT_DATE - INTERVAL '2 weeks'),
|
|
|
|
('d2000000-0000-0000-0000-000000000002',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'c1000000-0000-0000-0000-000000000001',
|
|
'Backend API Development',
|
|
'RESTful API for content management and user authentication.',
|
|
2,
|
|
'in_progress',
|
|
CURRENT_DATE + INTERVAL '1 month'),
|
|
|
|
('d3000000-0000-0000-0000-000000000003',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'c1000000-0000-0000-0000-000000000001',
|
|
'Frontend Implementation',
|
|
'React-based frontend with responsive design.',
|
|
3,
|
|
'pending',
|
|
CURRENT_DATE + INTERVAL '2 months');
|
|
|
|
-- =============================================================================
|
|
-- Create test milestones
|
|
-- =============================================================================
|
|
|
|
INSERT INTO milestones (
|
|
id, tenant_id, deliverable_id,
|
|
title, type, condition_value, amount, status
|
|
) VALUES
|
|
-- Homepage milestones
|
|
('10000000-0000-4000-8000-000000000101',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'd1000000-0000-0000-0000-000000000001',
|
|
'Design approval',
|
|
'fixed_date',
|
|
(CURRENT_DATE - INTERVAL '2 weeks')::TEXT,
|
|
5000.00,
|
|
'completed'),
|
|
|
|
-- Backend milestones
|
|
('20000000-0000-4000-8000-000000000102',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'd2000000-0000-0000-0000-000000000002',
|
|
'API endpoints complete',
|
|
'duration_from_start',
|
|
'30',
|
|
15000.00,
|
|
'in_progress');
|
|
|
|
-- =============================================================================
|
|
-- Create test comments
|
|
-- =============================================================================
|
|
|
|
INSERT INTO comments (
|
|
id, tenant_id, entity_type, entity_id,
|
|
content, user_id
|
|
) VALUES
|
|
('30000000-0000-4000-8000-000000000201',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'contract',
|
|
'c1000000-0000-0000-0000-000000000001',
|
|
'Looking forward to starting this project!',
|
|
'11000000-0000-0000-0000-000000000003'),
|
|
|
|
('30000000-0000-4000-8000-000000000202',
|
|
'10000000-0000-0000-0000-000000000001',
|
|
'deliverable',
|
|
'd1000000-0000-0000-0000-000000000001',
|
|
'Great work on the designs! Approved.',
|
|
'11000000-0000-0000-0000-000000000003');
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
|
|
-- =============================================================================
|
|
-- Re-enable RLS after the seed script
|
|
-- =============================================================================
|
|
|
|
ALTER TABLE tenants ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE contracts ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE deliverables ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE milestones ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE comments ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE attachments ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE audit_logs ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE analytics_events ENABLE ROW LEVEL SECURITY;
|
|
ALTER TABLE notifications ENABLE ROW LEVEL SECURITY;
|
|
|
|
-- =============================================================================
|