81 lines
3.3 KiB
SQL
81 lines
3.3 KiB
SQL
-- ============================================================
|
|
-- P&ID Data Schema for PostgreSQL
|
|
-- For Asset Excellence (AX) integration
|
|
-- ============================================================
|
|
|
|
-- Main equipment/instrument table
|
|
CREATE TABLE IF NOT EXISTS pid_equipment (
|
|
id SERIAL PRIMARY KEY,
|
|
pid_drawing_no VARCHAR(100), -- P&ID 도면번호
|
|
tag_no VARCHAR(100), -- 태그번호 (e.g. FT-1001)
|
|
equipment_name VARCHAR(255), -- 장비명
|
|
instrument_type VARCHAR(50), -- 계기타입 (FT, PT, LT ...)
|
|
line_number VARCHAR(100), -- 라인번호
|
|
service_description TEXT, -- 서비스 설명
|
|
confidence FLOAT DEFAULT 1.0, -- AI 신뢰도 (0.0~1.0)
|
|
source_file VARCHAR(255), -- 원본 파일명
|
|
extracted_at TIMESTAMPTZ, -- 추출 일시
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
review_status VARCHAR(20) DEFAULT 'pending', -- pending/approved/rejected
|
|
reviewer_note TEXT
|
|
);
|
|
|
|
-- Indexes for fast lookup
|
|
CREATE INDEX IF NOT EXISTS idx_pid_tag_no ON pid_equipment(tag_no);
|
|
CREATE INDEX IF NOT EXISTS idx_pid_drawing_no ON pid_equipment(pid_drawing_no);
|
|
CREATE INDEX IF NOT EXISTS idx_pid_instrument_type ON pid_equipment(instrument_type);
|
|
CREATE INDEX IF NOT EXISTS idx_pid_review_status ON pid_equipment(review_status);
|
|
|
|
-- Drawing register table (도면 목록)
|
|
CREATE TABLE IF NOT EXISTS pid_drawings (
|
|
id SERIAL PRIMARY KEY,
|
|
drawing_no VARCHAR(100) UNIQUE NOT NULL,
|
|
drawing_title VARCHAR(255),
|
|
revision VARCHAR(20),
|
|
area VARCHAR(100),
|
|
unit_no VARCHAR(50),
|
|
source_file VARCHAR(255),
|
|
processed_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_drawing_no ON pid_drawings(drawing_no);
|
|
|
|
-- ============================================================
|
|
-- AX Export View (Asset Excellence import format)
|
|
-- ============================================================
|
|
|
|
CREATE OR REPLACE VIEW ax_export AS
|
|
SELECT
|
|
tag_no AS "Tag Number",
|
|
equipment_name AS "Asset Description",
|
|
instrument_type AS "Equipment Class",
|
|
pid_drawing_no AS "P&ID Reference",
|
|
line_number AS "Line Reference",
|
|
service_description AS "Service",
|
|
review_status AS "Review Status",
|
|
confidence AS "Confidence Score",
|
|
source_file AS "Source Drawing",
|
|
extracted_at AS "Extracted Date"
|
|
FROM pid_equipment
|
|
WHERE review_status != 'rejected'
|
|
ORDER BY pid_drawing_no, tag_no;
|
|
|
|
-- ============================================================
|
|
-- Useful Queries
|
|
-- ============================================================
|
|
|
|
-- 전체 태그 현황
|
|
-- SELECT instrument_type, COUNT(*) as count
|
|
-- FROM pid_equipment GROUP BY instrument_type ORDER BY count DESC;
|
|
|
|
-- 신뢰도 낮은 항목 검토 필요
|
|
-- SELECT * FROM pid_equipment WHERE confidence < 0.7 AND review_status = 'pending';
|
|
|
|
-- 도면번호별 태그 수
|
|
-- SELECT pid_drawing_no, COUNT(*) as tag_count
|
|
-- FROM pid_equipment GROUP BY pid_drawing_no ORDER BY pid_drawing_no;
|
|
|
|
-- AX 가져오기용 CSV 추출
|
|
-- COPY (SELECT * FROM ax_export) TO '/tmp/ax_import.csv' CSV HEADER;
|