база rpt сделана из базы billing (название изменено, чтобы избежать путаницы)
-- удалены последовательности, переназначены владельцы и права
-- удалены внешние ключи

-- создать роль dbo (владелец), без connect
-- создать пользователя nifi, с правом логина 
-- создать пользователя appserver, с правом логина 
-- дать права пользователю nifi на схемы и таблицы
-- дать права пользователю appserver на схемы и таблицы на чтение

SET ROLE postgres;

CREATE SCHEMA IF NOT EXISTS s3billing;
CREATE SCHEMA IF NOT EXISTS ngcloud_ru;

ALTER SCHEMA s3billing OWNER TO dbo;
ALTER SCHEMA ngcloud_ru OWNER TO dbo;
ALTER DATABASE rpt SET search_path TO s3billing, ngcloud_ru; 

ALTER DEFAULT PRIVILEGES FOR ROLE dbo, postgres GRANT ALL ON TABLES TO nifi;
ALTER DEFAULT PRIVILEGES FOR ROLE dbo, postgres GRANT SELECT ON TABLES TO appserver;

SET ROLE dbo;

GRANT USAGE ON SCHEMA s3billing TO appserver,nifi;
GRANT USAGE ON SCHEMA ngcloud_ru TO appserver,nifi;

GRANT ALL ON ALL TABLES IN SCHEMA s3billing TO nifi;
GRANT SELECT ON ALL TABLES IN SCHEMA s3billing TO appserver;

GRANT ALL ON ALL TABLES IN SCHEMA ngcloud_ru TO nifi;
GRANT SELECT ON ALL TABLES IN SCHEMA ngcloud_ru TO appserver;

--GRANT ALL ON ALL SEQUENCES IN SCHEMA s3billing TO appserver,nifi;
--GRANT ALL ON ALL SEQUENCES IN SCHEMA ngcloud_ru TO appserver,nifi;


--ALTER DEFAULT PRIVILEGES FOR ROLE dbo GRANT ALL ON SEQUENCES TO appserver,nifi;

--
-- PostgreSQL database dump
--

-- Dumped from database version 16.0
-- Dumped by pg_dump version 16.4

-- Started on 2025-09-15 09:50:58

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- TOC entry 230 (class 1259 OID 2160668)
-- Name: bucket_info; Type: TABLE; Schema: s3billing; Owner: s3billing
--

DROP TABLE IF EXISTS s3billing.bucket_info;
CREATE TABLE s3billing.bucket_info (
    id integer NOT NULL,
    bucket_id character varying(255) NOT NULL,
    name character varying(255) NOT NULL,
    marker character varying(255) NOT NULL,
    placement_id bigint DEFAULT 0 NOT NULL
);




--
-- TOC entry 226 (class 1259 OID 2160642)
-- Name: bucket_stat; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.bucket_stat;
CREATE TABLE s3billing.bucket_stat (
    bucket_id bigint,
    num_shards bigint NOT NULL,
    tenant character varying(255) DEFAULT NULL::character varying,
    zone_group bigint NOT NULL,
    placement_id bigint NOT NULL,
    explicit_placement_data_pool character varying(255) DEFAULT NULL::character varying,
    explicit_placement_data_extra_pool character varying(255) DEFAULT NULL::character varying,
    explicit_placement_index_pool character varying(255) DEFAULT NULL::character varying,
    index_type_id bigint NOT NULL,
    versioned boolean DEFAULT false,
    versioning_enabled boolean DEFAULT false,
    object_lock_enabled boolean DEFAULT false,
    mfa_enabled boolean DEFAULT false,
    owner character varying(255) NOT NULL,
    bucket_quota_enabled boolean DEFAULT false,
    bucket_quota_check_on_raw boolean DEFAULT false,
    bucket_quota_max_size bigint NOT NULL,
    bucket_quota_max_size_kb bigint NOT NULL,
    bucket_quota_max_objects bigint NOT NULL,
    usage_rgw_main_size bigint NOT NULL,
    usage_rgw_main_size_actual bigint NOT NULL,
    usage_rgw_main_size_utilized bigint NOT NULL,
    usage_rgw_main_size_kb bigint NOT NULL,
    usage_rgw_main_size_kb_actual bigint NOT NULL,
    usage_rgw_main_size_kb_utilized bigint NOT NULL,
    usage_rgw_main_num_objects bigint NOT NULL,
    usage_rgw_multimeta_size bigint,
    usage_rgw_multimeta_size_actual bigint,
    usage_rgw_multimeta_size_utilized bigint,
    usage_rgw_multimeta_size_kb bigint,
    usage_rgw_multimeta_size_kb_actual bigint,
    usage_rgw_multimeta_size_kb_utilized bigint,
    usage_rgw_multimeta_num_objects bigint,
    creation_time timestamp without time zone NOT NULL,
    mtime timestamp without time zone NOT NULL,
    timestamp_addition timestamp without time zone DEFAULT date_trunc('hour'::text, CURRENT_TIMESTAMP)
);

--
-- TOC entry 245 (class 1259 OID 2160763)
-- Name: category; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.category;
CREATE TABLE s3billing.category (
    id integer NOT NULL,
    name character varying(255) NOT NULL
);

--
-- TOC entry 225 (class 1259 OID 2160635)
-- Name: goose_db_version; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.goose_db_version;
CREATE TABLE s3billing.goose_db_version (
    id integer NOT NULL,
    version_id bigint NOT NULL,
    is_applied boolean NOT NULL,
    tstamp timestamp without time zone DEFAULT now() NOT NULL
);


--
-- TOC entry 234 (class 1259 OID 2160684)
-- Name: index_type; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS index_type;
CREATE TABLE s3billing.index_type (
    id integer NOT NULL,
    name character varying(255) NOT NULL
);


--
-- TOC entry 232 (class 1259 OID 2160677)
-- Name: placement; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.placement;
CREATE TABLE s3billing.placement (
    id integer NOT NULL,
    name character varying(255) NOT NULL
);



--
-- TOC entry 239 (class 1259 OID 2160705)
-- Name: usage_bucket_by_user; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.usage_bucket_by_user;
CREATE TABLE s3billing.usage_bucket_by_user (
    bucketid bigint,
    "time" timestamp without time zone NOT NULL,
    bytes_sent bigint NOT NULL,
    bytes_received bigint NOT NULL,
    ops bigint NOT NULL,
    successful_ops bigint NOT NULL,
    date_start timestamp without time zone NOT NULL,
    date_end timestamp without time zone NOT NULL,
    user_id bigint NOT NULL,
    category_id bigint NOT NULL
);


--
-- TOC entry 238 (class 1259 OID 2160698)
-- Name: usage_stat_summary; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.usage_stat_summary;
CREATE TABLE s3billing.usage_stat_summary (
    id integer NOT NULL,
    userid character varying(255) NOT NULL,
    category character varying(255) NOT NULL,
    bytes_sent bigint NOT NULL,
    bytes_received bigint NOT NULL,
    ops bigint NOT NULL,
    successful_ops bigint NOT NULL,
    date_start timestamp without time zone NOT NULL,
    date_end timestamp without time zone NOT NULL
);


--
-- TOC entry 236 (class 1259 OID 2160691)
-- Name: usage_stat_total; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.usage_stat_total;
CREATE TABLE s3billing.usage_stat_total (
    id integer NOT NULL,
    userid character varying(255) NOT NULL,
    bytes_sent bigint NOT NULL,
    bytes_received bigint NOT NULL,
    ops bigint NOT NULL,
    successful_ops bigint NOT NULL,
    date_start timestamp without time zone NOT NULL,
    date_end timestamp without time zone NOT NULL
);

--
-- TOC entry 243 (class 1259 OID 2160751)
-- Name: user_info; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.user_info;
CREATE TABLE s3billing.user_info (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    owner character varying(255) NOT NULL
);


--
-- TOC entry 241 (class 1259 OID 2160712)
-- Name: user_quota_bucket; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.user_quota_bucket;
CREATE TABLE s3billing.user_quota_bucket (
    id integer NOT NULL,
    userid character varying(255) NOT NULL,
    enabled boolean DEFAULT false,
    check_on_raw boolean DEFAULT false,
    max_size bigint NOT NULL,
    max_size_kb bigint NOT NULL,
    max_objects bigint NOT NULL
);


--
-- TOC entry 228 (class 1259 OID 2160661)
-- Name: zone_group; Type: TABLE; Schema: s3billing; Owner: s3billing
--
DROP TABLE IF EXISTS s3billing.zone_group;
CREATE TABLE s3billing.zone_group (
    id integer NOT NULL,
    name uuid NOT NULL
);

--
-- TOC entry 3278 (class 2606 OID 2160675)
-- Name: bucket_info bucket_info_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.bucket_info
    ADD CONSTRAINT bucket_info_pkey PRIMARY KEY (id);


--
-- TOC entry 3273 (class 2606 OID 2476484)
-- Name: bucket_stat bucket_stat_unique; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

--ALTER TABLE ONLY s3billing.bucket_stat
--    ADD CONSTRAINT bucket_stat_unique UNIQUE (bucket_id, placement_id, timestamp_addition);
	
ALTER TABLE ONLY s3billing.bucket_stat
    ADD CONSTRAINT bucket_stat_pkey PRIMARY KEY (bucket_id, placement_id, timestamp_addition);


--
-- TOC entry 3298 (class 2606 OID 2160768)
-- Name: category category_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.category
    ADD CONSTRAINT category_pkey PRIMARY KEY (id);


--
-- TOC entry 3270 (class 2606 OID 2160640)
-- Name: goose_db_version goose_db_version_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.goose_db_version
    ADD CONSTRAINT goose_db_version_pkey PRIMARY KEY (id);


--
-- TOC entry 3284 (class 2606 OID 2160689)
-- Name: index_type index_type_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.index_type
    ADD CONSTRAINT index_type_pkey PRIMARY KEY (id);


--
-- TOC entry 3282 (class 2606 OID 2160682)
-- Name: placement placement_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.placement
    ADD CONSTRAINT placement_pkey PRIMARY KEY (id);


--
-- TOC entry 3290 (class 2606 OID 2476705)
-- Name: usage_bucket_by_user usage_bucket_by_user_unique; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

--ALTER TABLE ONLY s3billing.usage_bucket_by_user
--    ADD CONSTRAINT usage_bucket_by_user_unique UNIQUE (bucketid, date_start, date_end, user_id, category_id);
ALTER TABLE ONLY s3billing.usage_bucket_by_user
    ADD CONSTRAINT usage_bucket_by_user_pkey PRIMARY KEY (bucketid, date_start, date_end, user_id, category_id);


--
-- TOC entry 3288 (class 2606 OID 2160703)
-- Name: usage_stat_summary usage_stat_summary_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.usage_stat_summary
    ADD CONSTRAINT usage_stat_summary_pkey PRIMARY KEY (id);


--
-- TOC entry 3286 (class 2606 OID 2160696)
-- Name: usage_stat_total usage_stat_total_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.usage_stat_total
    ADD CONSTRAINT usage_stat_total_pkey PRIMARY KEY (id);


--
-- TOC entry 3295 (class 2606 OID 2160758)
-- Name: user_info user_info_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.user_info
    ADD CONSTRAINT user_info_pkey PRIMARY KEY (id);


--
-- TOC entry 3292 (class 2606 OID 2160719)
-- Name: user_quota_bucket user_quota_bucket_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.user_quota_bucket
    ADD CONSTRAINT user_quota_bucket_pkey PRIMARY KEY (id);


--
-- TOC entry 3275 (class 2606 OID 2160666)
-- Name: zone_group zone_group_pkey; Type: CONSTRAINT; Schema: s3billing; Owner: s3billing
--

ALTER TABLE ONLY s3billing.zone_group
    ADD CONSTRAINT zone_group_pkey PRIMARY KEY (id);


--
-- TOC entry 3276 (class 1259 OID 2474077)
-- Name: bucket_info_name_idx; Type: INDEX; Schema: s3billing; Owner: s3billing
--

CREATE INDEX bucket_info_name_idx ON s3billing.bucket_info USING btree (name);


--
-- TOC entry 3279 (class 1259 OID 2474078)
-- Name: bucket_info_placement_id_idx; Type: INDEX; Schema: s3billing; Owner: s3billing
--

CREATE INDEX bucket_info_placement_id_idx ON s3billing.bucket_info USING btree (placement_id);


--
-- TOC entry 3271 (class 1259 OID 2474094)
-- Name: bucket_stat_owner_idx; Type: INDEX; Schema: s3billing; Owner: s3billing
--

CREATE INDEX bucket_stat_owner_idx ON s3billing.bucket_stat USING btree (owner);


--
-- TOC entry 3296 (class 1259 OID 2474445)
-- Name: category_name_idx; Type: INDEX; Schema: s3billing; Owner: s3billing
--

CREATE UNIQUE INDEX category_name_idx ON s3billing.category USING btree (name);


--
-- TOC entry 3280 (class 1259 OID 2474468)
-- Name: placement_name_idx; Type: INDEX; Schema: s3billing; Owner: s3billing
--

CREATE UNIQUE INDEX placement_name_idx ON s3billing.placement USING btree (name);


--
-- TOC entry 3293 (class 1259 OID 2474438)
-- Name: user_info_name_idx; Type: INDEX; Schema: s3billing; Owner: s3billing
--

CREATE INDEX user_info_name_idx ON s3billing.user_info USING btree (name);



-- Completed on 2025-09-15 09:50:59

--
-- PostgreSQL database dump complete
--

-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------

DROP TABLE IF EXISTS ngcloud_ru.capacity_resource;
CREATE TABLE ngcloud_ru.capacity_resource (
    vdc_id uuid NOT NULL,
    "timestamp" timestamp with time zone NOT NULL,
    cpu_allocated integer NOT NULL,
    cpu_limit integer NOT NULL,
    cpu_reserved integer NOT NULL,
    cpu_used integer NOT NULL,
    cpu_speed integer NOT NULL,
    mem_allocated integer NOT NULL,
    mem_limit integer NOT NULL,
    mem_reserved integer NOT NULL,
    mem_used integer NOT NULL
);

--
-- TOC entry 223 (class 1259 OID 1893993)
-- Name: capacity_storage; Type: TABLE; Schema: ngcloud_ru; Owner: vc_billing
--
DROP TABLE IF EXISTS ngcloud_ru.capacity_storage;
CREATE TABLE ngcloud_ru.capacity_storage (
    vdc_id uuid NOT NULL,
    storage_profile_types_id integer NOT NULL,
    "timestamp" timestamp with time zone NOT NULL,
    id uuid NOT NULL,
    "limit" integer NOT NULL,
    used integer NOT NULL
);

--
-- TOC entry 220 (class 1259 OID 1893965)
-- Name: storage_profile_types; Type: TABLE; Schema: ngcloud_ru; Owner: vc_billing
--
DROP TABLE IF EXISTS ngcloud_ru.storage_profile_types;
CREATE TABLE ngcloud_ru.storage_profile_types (
    id integer NOT NULL,
    name character varying(255) NOT NULL
);

--
-- TOC entry 218 (class 1259 OID 1893959)
-- Name: tenant; Type: TABLE; Schema: ngcloud_ru; Owner: vc_billing
--
DROP TABLE IF EXISTS ngcloud_ru.tenant;
CREATE TABLE ngcloud_ru.tenant (
    id uuid NOT NULL,
    name character varying(255) NOT NULL,
    wzcode bigint
);


--
-- TOC entry 221 (class 1259 OID 1893973)
-- Name: vdc; Type: TABLE; Schema: ngcloud_ru; Owner: vc_billing
--
DROP TABLE IF EXISTS ngcloud_ru.vdc;
CREATE TABLE ngcloud_ru.vdc (
    id uuid NOT NULL,
    tenant_id uuid NOT NULL,
    name character varying(255) NOT NULL
);





--
-- TOC entry 3255 (class 2606 OID 1893987)
-- Name: capacity_resource capacity_resource_pkey; Type: CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

ALTER TABLE ONLY ngcloud_ru.capacity_resource
    ADD CONSTRAINT capacity_resource_pkey PRIMARY KEY (vdc_id, "timestamp");


--
-- TOC entry 3257 (class 2606 OID 1893997)
-- Name: capacity_storage capacity_storage_pkey; Type: CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

ALTER TABLE ONLY ngcloud_ru.capacity_storage
    ADD CONSTRAINT capacity_storage_pkey PRIMARY KEY (vdc_id, id, "timestamp");


--
-- TOC entry 3249 (class 2606 OID 1893972)
-- Name: storage_profile_types storage_profile_types_name_key; Type: CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

ALTER TABLE ONLY ngcloud_ru.storage_profile_types
    ADD CONSTRAINT storage_profile_types_name_key UNIQUE (name);


--
-- TOC entry 3251 (class 2606 OID 1893970)
-- Name: storage_profile_types storage_profile_types_pkey; Type: CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

ALTER TABLE ONLY ngcloud_ru.storage_profile_types
    ADD CONSTRAINT storage_profile_types_pkey PRIMARY KEY (id);


--
-- TOC entry 3247 (class 2606 OID 1893963)
-- Name: tenant tenant_pkey; Type: CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

ALTER TABLE ONLY ngcloud_ru.tenant
    ADD CONSTRAINT tenant_pkey PRIMARY KEY (id);


--
-- TOC entry 3253 (class 2606 OID 1893977)
-- Name: vdc vdc_pkey; Type: CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

ALTER TABLE ONLY ngcloud_ru.vdc
    ADD CONSTRAINT vdc_pkey PRIMARY KEY (id);


--
-- TOC entry 3259 (class 2606 OID 1893988)
-- Name: capacity_resource capacity_resource_vdc_id_fkey; Type: FK CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

--ALTER TABLE ONLY ngcloud_ru.capacity_resource
--    ADD CONSTRAINT capacity_resource_vdc_id_fkey FOREIGN KEY (vdc_id) REFERENCES ngcloud_ru.vdc(id) ON DELETE CASCADE;


--
-- TOC entry 3260 (class 2606 OID 1894003)
-- Name: capacity_storage capacity_storage_storage_profile_types_id_fkey; Type: FK CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

--ALTER TABLE ONLY ngcloud_ru.capacity_storage
--   ADD CONSTRAINT capacity_storage_storage_profile_types_id_fkey FOREIGN KEY (storage_profile_types_id) REFERENCES ngcloud_ru.storage_profile_types(id);


--
-- TOC entry 3261 (class 2606 OID 1893998)
-- Name: capacity_storage capacity_storage_vdc_id_fkey; Type: FK CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

--ALTER TABLE ONLY ngcloud_ru.capacity_storage
--    ADD CONSTRAINT capacity_storage_vdc_id_fkey FOREIGN KEY (vdc_id) REFERENCES ngcloud_ru.vdc(id) ON DELETE CASCADE;


--
-- TOC entry 3258 (class 2606 OID 1893978)
-- Name: vdc vdc_tenant_id_fkey; Type: FK CONSTRAINT; Schema: ngcloud_ru; Owner: vc_billing
--

--ALTER TABLE ONLY ngcloud_ru.vdc
--    ADD CONSTRAINT vdc_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES ngcloud_ru.tenant(id);


-- Completed on 2025-09-15 09:53:18

--
-- PostgreSQL database dump complete
--

