memleketmeselesi/migrations/0005_location_changes.sql
Mukan Erkin 2498e75594 init: memleketmeselesi platform — API + migrations
FastAPI + PostgreSQL 16. KYC, issue sistemi, permission/group yönetimi,
session yönetimi, API client auth (kışla kapısı), officials/persons CRUD.
Migration 0001–0013 dahil.
2026-04-27 23:06:59 +03:00

30 lines
1.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Lokasyon ayrılma kayıtları
-- Bir lokasyonun hangi kaynaktan ayrıldığını tutar.
-- Tek kaynaktan ayrılma (Osmaniye←Adana) veya
-- çok kaynaktan birleşme (Elbistan ili←KMaraş+Malatya+Kayseri) için çoklu satır.
CREATE TABLE location_splits (
id BIGSERIAL PRIMARY KEY,
location_id BIGINT NOT NULL REFERENCES locations(id) ON DELETE RESTRICT,
source_id BIGINT NOT NULL REFERENCES locations(id) ON DELETE RESTRICT,
effective_at DATE NOT NULL,
notes TEXT,
UNIQUE (location_id, source_id, effective_at)
);
CREATE INDEX idx_location_splits_location ON location_splits(location_id);
CREATE INDEX idx_location_splits_source ON location_splits(source_id);
-- Lokasyon birleşme kayıtları
-- Bir lokasyonun hangi hedefe birleştirildiğini tutar.
-- Beyoğlu+Şekeroba→Yeniİlçe gibi çok kaynak tek hedef için çoklu satır.
CREATE TABLE location_merges (
id BIGSERIAL PRIMARY KEY,
source_id BIGINT NOT NULL REFERENCES locations(id) ON DELETE RESTRICT,
target_id BIGINT NOT NULL REFERENCES locations(id) ON DELETE RESTRICT,
effective_at DATE NOT NULL,
notes TEXT,
UNIQUE (source_id, target_id, effective_at)
);
CREATE INDEX idx_location_merges_source ON location_merges(source_id);
CREATE INDEX idx_location_merges_target ON location_merges(target_id);