-- Skrypt migracji tabel zależnych
-- Data: 10.03.2025

-- 1. Migracja kosztów
INSERT INTO domopieki_dev.costs (id, company_id, cost_type_id, amount, date, description, 
                                is_general, status, created_by, created_at, updated_at)
SELECT id, company_id, cost_type_id, amount, date, description, 
       is_general, status, created_by, created_at, updated_at
FROM domopieki.costs;

-- 2. Migracja relacji kosztów
INSERT INTO domopieki_dev.cost_relations (id, cost_id, related_id, relation_type, created_at)
SELECT id, cost_id, related_id, relation_type, created_at
FROM domopieki.cost_relations;

-- 3. Migracja dokumentów
INSERT INTO domopieki_dev.documents (id, title, description, file_path, file_type, category_id, 
                                    company_id, related_entity_type, related_entity_id, created_at, 
                                    updated_at, created_by, policy_number, policy_start_date, 
                                    policy_end_date, insurance_company, is_generated, template_id)
SELECT id, title, description, file_path, file_type, category_id, 
       company_id, related_entity_type, related_entity_id, created_at, 
       updated_at, created_by, policy_number, policy_start_date, 
       policy_end_date, insurance_company, is_generated, template_id
FROM domopieki.documents;

-- 4. Migracja zadań
INSERT INTO domopieki_dev.tasks (id, title, description, priority, due_date, 
                                status, assigned_to, created_by, created_at, updated_at)
SELECT id, title, description, priority, due_date, 
       status, assigned_to, created_by, created_at, updated_at
FROM domopieki.tasks;

-- 5. Migracja preferencji użytkowników
INSERT INTO domopieki_dev.user_preferences (id, user_id, preference_key, value, created_at, updated_at)
SELECT id, user_id, preference_key, value, created_at, updated_at
FROM domopieki.user_preferences; 