memleketmeselesi/migrations/0007_permissions_refactor.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

75 lines
3.2 KiB
SQL
Raw Permalink 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.

-- Eski permissions tablosunu yeniden yapılandır
DROP TABLE IF EXISTS group_permissions CASCADE;
DROP TABLE IF EXISTS permissions CASCADE;
CREATE TABLE permissions (
id BIGSERIAL PRIMARY KEY,
module TEXT NOT NULL, -- "issue", "kyc", "location", "comment", "*"
action TEXT NOT NULL, -- "create", "read", "update", "delete", "approve", "assign", "*"
description TEXT,
UNIQUE (module, action)
);
CREATE TABLE group_permissions (
group_id BIGINT NOT NULL REFERENCES permission_groups(id) ON DELETE CASCADE,
permission_id BIGINT NOT NULL REFERENCES permissions(id) ON DELETE CASCADE,
PRIMARY KEY (group_id, permission_id)
);
-- is_superuser flag — bu gruptaki herkes tüm izinlere sahip
ALTER TABLE permission_groups ADD COLUMN IF NOT EXISTS is_superuser BOOLEAN NOT NULL DEFAULT FALSE;
-- Temel izinleri seed et
INSERT INTO permissions (module, action, description) VALUES
-- wildcard
('*', '*', 'Tüm modüllerde tüm eylemler'),
-- location
('location', 'create', 'Yeni lokasyon ekle'),
('location', 'read', 'Lokasyon detayını gör'),
('location', 'update', 'Lokasyon bilgisi güncelle'),
('location', 'delete', 'Lokasyon sil'),
('location', 'retype', 'Lokasyon tipini değiştir'),
('location', 'reparent', 'Lokasyon hiyerarşisini değiştir'),
('location', 'merge', 'Lokasyonları birleştir'),
('location', 'split', 'Lokasyon ayrılma kaydı ekle'),
-- admin_unit
('admin_unit', 'create', 'Yeni idari birim ekle'),
('admin_unit', 'update', 'İdari birim güncelle'),
('admin_unit', 'close', 'İdari birimi kapat'),
('admin_unit', 'assign', 'Lokasyona idari birim ata'),
-- issue
('issue', 'create', 'Sorun bildir'),
('issue', 'read', 'Sorun detayını gör'),
('issue', 'update', 'Sorun güncelle'),
('issue', 'delete', 'Sorun sil'),
('issue', 'assign', 'Sorumlu ata'),
('issue', 'resolve', 'Sorunu çözüldü işaretle'),
('issue', 'reject', 'Sorunu reddet'),
-- comment
('comment', 'create', 'Yorum yap'),
('comment', 'delete', 'Yorum sil'),
-- kyc
('kyc', 'approve', 'KYC başvurusu onayla'),
('kyc', 'reject', 'KYC başvurusu reddet'),
('kyc', 'view', 'KYC belgelerini gör'),
-- user
('user', 'read', 'Kullanıcı listesi ve detayı'),
('user', 'suspend', 'Kullanıcıyı askıya al'),
('user', 'assign_group', 'Kullanıcıya grup ata'),
-- profile
('profile', 'create', 'Kişi/organizasyon profili oluştur'),
('profile', 'update', 'Profil güncelle'),
('profile', 'delete', 'Profil sil'),
-- report
('report', 'create', 'Rapor oluştur'),
('report', 'read', 'Rapor görüntüle'),
('report', 'manage', 'Rapor tiplerini ve fiyatları yönet'),
-- moderation
('moderation', 'review', 'İçerik inceleme kuyruğunu gör'),
('moderation', 'action', 'Moderasyon aksiyonu uygula')
ON CONFLICT (module, action) DO NOTHING;
-- İlk süper kullanıcı grubu
INSERT INTO permission_groups (name, description, is_superuser)
VALUES ('Süper Yönetici', 'Tüm izinlere sahip grup', TRUE)
ON CONFLICT DO NOTHING;