sipd-transaksi-master/migrations/000003_create_mst_skpd_table.up.sql
2025-09-16 08:42:27 +07:00

57 lines
4.2 KiB
SQL

CREATE TABLE IF NOT EXISTS public.mst_skpd (
id_unik_skpd uuid DEFAULT public.uuid_generate_v7() NOT NULL,
id_skpd_lama integer DEFAULT 0 NOT NULL,
tahun integer DEFAULT 0 NOT NULL,
id_daerah integer DEFAULT 0 NOT NULL,
locked boolean DEFAULT false NOT NULL,
id_skpd_induk integer DEFAULT 0 NOT NULL,
id_kecamatan integer DEFAULT 0 NOT NULL,
id_kelurahan integer DEFAULT 0 NOT NULL,
status_induk boolean DEFAULT false NOT NULL,
status_blud boolean DEFAULT false NOT NULL,
status_pendapatan boolean DEFAULT false NOT NULL,
status_pembiayaan boolean DEFAULT false NOT NULL,
status_uobk boolean DEFAULT false NOT NULL,
kode_skpd character varying(50) DEFAULT ''::character varying NOT NULL,
nama_skpd text DEFAULT ''::text NOT NULL,
hist_data jsonb DEFAULT '[]'::jsonb NOT NULL,
created_at timestamp(6) without time zone DEFAULT now() NOT NULL,
created_by integer DEFAULT 0 NOT NULL,
updated_at timestamp(6) without time zone DEFAULT '0001-01-01 00:00:00'::timestamp without time zone NOT NULL,
updated_by integer DEFAULT 0 NOT NULL,
deleted_at timestamp(6) without time zone DEFAULT '0001-01-01 00:00:00'::timestamp without time zone NOT NULL,
deleted_by integer DEFAULT 0 NOT NULL
);
ALTER TABLE public.mst_skpd ADD CONSTRAINT mst_skpd_pkey PRIMARY KEY (id_unik_skpd, tahun, id_daerah);
ALTER TABLE public.mst_skpd ADD CONSTRAINT mst_skpd_unique_key UNIQUE (id_unik_skpd, tahun, id_daerah, id_skpd_induk, kode_skpd);
COMMENT ON TABLE public.mst_skpd IS 'Tabel master yang menyimpan data Satuan Kerja Perangkat Daerah (SKPD) per tahun dan daerah. Digunakan untuk identifikasi dan pengelompokan unit kerja pemerintahan.';
COMMENT ON COLUMN public.mst_skpd.id_unik_skpd IS 'ID unik UUID sebagai ID primary key.';
COMMENT ON COLUMN public.mst_skpd.id_skpd_lama IS 'Primary key tabel lama.';
COMMENT ON COLUMN public.mst_skpd.tahun IS 'Tahun data SKPD.';
COMMENT ON COLUMN public.mst_skpd.id_daerah IS 'Pemda asal SKPD.';
COMMENT ON COLUMN public.mst_skpd.locked IS 'Status aktivitas skpd dikunci atau tidak (true/false).';
COMMENT ON COLUMN public.mst_skpd.id_skpd_induk IS 'Induk dari Sub SKPD (induk dari Biro/Puskesmas/UPTD).';
COMMENT ON COLUMN public.mst_skpd.id_kecamatan IS 'Lokasi alamat kecamatan dari SKPD.';
COMMENT ON COLUMN public.mst_skpd.id_kelurahan IS 'Lokasi alamat kelurahan dari SKPD.';
COMMENT ON COLUMN public.mst_skpd.status_induk IS 'Status SKPD merupakan Organisasi Induk.';
COMMENT ON COLUMN public.mst_skpd.status_blud IS 'Status SKPD merupakan Badan Layanan Umum Daerah (BLUD).';
COMMENT ON COLUMN public.mst_skpd.status_pendapatan IS 'Status SKPD memiliki anggaran pendapatan.';
COMMENT ON COLUMN public.mst_skpd.status_pembiayaan IS 'Status SKPD memiliki anggaran pembiayaan.';
COMMENT ON COLUMN public.mst_skpd.status_uobk IS 'Status Sub SKPD bersifat unit organisasi khusus sebagaimana dimaksud pada ayat (1) rumah sakit daerah kabupaten/ kota memiliki otonomi dalam pengelolaan keuangan dan barang milik daerah serta bidang kepegawaian. (PERATURAN PEMERINTAH REPUBLIK INDONESIA NOMOR 72 TAHUN 2019)';
COMMENT ON COLUMN public.mst_skpd.kode_skpd IS 'Kode perangkat daerah berdasarkan SOTK.';
COMMENT ON COLUMN public.mst_skpd.nama_skpd IS 'Nama perangkat daerah berdasarkan SOTK.';
COMMENT ON COLUMN public.mst_skpd.hist_data IS 'Riwayat perubahan data SKPD dalam format JSON.';
COMMENT ON COLUMN public.mst_skpd.created_at IS 'Tanggal dan waktu data dibuat.';
COMMENT ON COLUMN public.mst_skpd.created_by IS 'ID pengguna yang membuat data.';
COMMENT ON COLUMN public.mst_skpd.updated_at IS 'Tanggal dan waktu terakhir data diperbarui.';
COMMENT ON COLUMN public.mst_skpd.updated_by IS 'ID pengguna yang memperbarui data.';
COMMENT ON COLUMN public.mst_skpd.deleted_at IS 'Tanggal dan waktu data dihapus (soft delete).';
COMMENT ON COLUMN public.mst_skpd.deleted_by IS 'ID pengguna yang menghapus data.';
CREATE INDEX mst_skpd_id_unik_skpd_idx ON public.mst_skpd USING btree (id_unik_skpd);
CREATE INDEX mst_skpd_tahun_idx ON public.mst_skpd USING btree (tahun);
CREATE INDEX mst_skpd_id_daerah_idx ON public.mst_skpd USING btree (id_daerah);
CREATE INDEX mst_skpd_id_skpd_induk_idx ON public.mst_skpd USING btree (id_skpd_induk);
CREATE INDEX mst_skpd_kode_skpd_idx ON public.mst_skpd USING btree (kode_skpd);