CREATE TABLE IF NOT EXISTS public.penugasan_staf_skpd (
	id_unik_penugasan_staf_skpd uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    id_staf_sub_bl_lama integer DEFAULT 0 NOT NULL,
    tahun integer DEFAULT 0 NOT NULL,
    id_daerah integer DEFAULT 0 NOT NULL,
    id_unik_pegawai uuid DEFAULT '00000000-0000-0000-0000-000000000000' NOT NULL,
    id_unik_skpd uuid DEFAULT '00000000-0000-0000-0000-000000000000' NOT NULL,
	id_unik_sub_skpd uuid DEFAULT '00000000-0000-0000-0000-000000000000' NOT NULL,
	id_unik_sub_kegiatan uuid DEFAULT '00000000-0000-0000-0000-000000000000' 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.penugasan_staf_skpd ADD CONSTRAINT penugasan_staf_skpd_pkey PRIMARY KEY (id_unik_penugasan_staf_skpd, tahun, id_daerah);
ALTER TABLE public.penugasan_staf_skpd ADD CONSTRAINT penugasan_staf_skpd_unique_key UNIQUE (tahun, id_daerah, id_unik_pegawai, id_unik_skpd, id_unik_sub_skpd, id_unik_sub_kegiatan);

COMMENT ON TABLE public.penugasan_staf_skpd IS 'Tabel berisi penugasan input belanja sub kegiatan pada pegawai (staf) perangkat daerah.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_unik_penugasan_staf_skpd IS 'ID unik UUID sebagai ID primary key.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_staf_sub_bl_lama IS 'Primary key tabel lama.';
COMMENT ON COLUMN public.penugasan_staf_skpd.tahun IS 'Tahun anggaran.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_daerah IS 'ID Pemerintah daerah.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_unik_skpd IS 'ID SKPD induk yang membawahi pelaksana kegiatan.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_unik_sub_skpd IS 'ID SKPD pelaksana kegiatan.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_unik_sub_kegiatan IS 'ID sub kegiatan yang sudah diinput dalam rencana kerja.';
COMMENT ON COLUMN public.penugasan_staf_skpd.id_unik_pegawai IS 'ID pegawai dari staf yang ditugaskan.';
COMMENT ON COLUMN public.penugasan_staf_skpd.created_at IS 'Tanggal dan waktu data dibuat.';
COMMENT ON COLUMN public.penugasan_staf_skpd.created_by IS 'ID pengguna yang membuat data.';
COMMENT ON COLUMN public.penugasan_staf_skpd.updated_at IS 'Tanggal dan waktu terakhir data diperbarui.';
COMMENT ON COLUMN public.penugasan_staf_skpd.updated_by IS 'ID pengguna yang memperbarui data.';
COMMENT ON COLUMN public.penugasan_staf_skpd.deleted_at IS 'Tanggal dan waktu data dihapus (soft delete).';
COMMENT ON COLUMN public.penugasan_staf_skpd.deleted_by IS 'ID pengguna yang menghapus data.';

CREATE INDEX penugasan_staf_skpd_id_unik_penugasan_staf_skpd_idx ON public.penugasan_staf_skpd USING btree (id_unik_penugasan_staf_skpd);
CREATE INDEX penugasan_staf_skpd_tahun_idx ON public.penugasan_staf_skpd USING btree (tahun);
CREATE INDEX penugasan_staf_skpd_id_daerah_idx ON public.penugasan_staf_skpd USING btree (id_daerah);
CREATE INDEX penugasan_staf_skpd_id_unik_pegawai_idx ON public.penugasan_staf_skpd USING btree (id_unik_pegawai);
CREATE INDEX penugasan_staf_skpd_id_unik_skpd_idx ON public.penugasan_staf_skpd USING btree (id_unik_skpd);
CREATE INDEX penugasan_staf_skpd_id_unik_sub_skpd_idx ON public.penugasan_staf_skpd USING btree (id_unik_sub_skpd);
CREATE INDEX penugasan_staf_skpd_id_unik_sub_kegiatan_idx ON public.penugasan_staf_skpd USING btree (id_unik_sub_kegiatan);
