-- AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
-- Generated from Jira Assets Schema via REST API
-- PostgreSQL version
-- Generated at: 2026-01-09T02:12:50.973Z
--
-- Re-generate with: npm run generate-schema

-- =============================================================================
-- Core Tables
-- =============================================================================
--
-- NOTE: This schema is LEGACY and deprecated.
-- The current system uses the normalized schema defined in
-- backend/src/services/database/normalized-schema.ts
--
-- This file is kept for reference and migration purposes only.

-- Object relations (references between objects)
CREATE TABLE IF NOT EXISTS object_relations (
  id SERIAL PRIMARY KEY,
  source_id TEXT NOT NULL,
  target_id TEXT NOT NULL,
  attribute_name TEXT NOT NULL,
  source_type TEXT NOT NULL,
  target_type TEXT NOT NULL,
  UNIQUE(source_id, target_id, attribute_name)
);

-- Sync metadata (tracks sync state)
CREATE TABLE IF NOT EXISTS sync_metadata (
  key TEXT PRIMARY KEY,
  value TEXT NOT NULL,
  updated_at TEXT NOT NULL
);

-- =============================================================================
-- Indices for Performance
-- =============================================================================

CREATE INDEX IF NOT EXISTS idx_relations_source ON object_relations(source_id);
CREATE INDEX IF NOT EXISTS idx_relations_target ON object_relations(target_id);
CREATE INDEX IF NOT EXISTS idx_relations_source_type ON object_relations(source_type);
CREATE INDEX IF NOT EXISTS idx_relations_target_type ON object_relations(target_type);
CREATE INDEX IF NOT EXISTS idx_relations_attr ON object_relations(attribute_name);
