--
-- PostgreSQL database dump
--

\restrict EyRcpjsnvnw9n7b8so76p7PAg1NWhmLAPEQh1liAhf6RheNHVbJBA0Z7sA2gWiQ

-- Dumped from database version 18.3 (Ubuntu 18.3-1.pgdg24.04+1)
-- Dumped by pg_dump version 18.3 (Ubuntu 18.3-1.pgdg24.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_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;

--
-- Name: audit_events; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.audit_events (
    id bigint NOT NULL,
    user_id integer,
    action text NOT NULL,
    resource_type text,
    resource_id integer,
    meta jsonb,
    ip_address inet,
    user_agent text,
    ts timestamp with time zone DEFAULT now()
);


ALTER TABLE pgz_sport.audit_events OWNER TO rinet;

--
-- Name: audit_events_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.audit_events_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.audit_events_id_seq OWNER TO rinet;

--
-- Name: audit_events_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.audit_events_id_seq OWNED BY pgz_sport.audit_events.id;


--
-- Name: audit_log; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.audit_log (
    id bigint NOT NULL,
    "timestamp" timestamp with time zone DEFAULT now(),
    tablica text NOT NULL,
    operacija text NOT NULL,
    record_id integer,
    korisnik text,
    ip text,
    promijenjeno_polje text,
    stara_vrijednost text,
    nova_vrijednost text
);


ALTER TABLE pgz_sport.audit_log OWNER TO rinet;

--
-- Name: audit_log_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.audit_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.audit_log_id_seq OWNER TO rinet;

--
-- Name: audit_log_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.audit_log_id_seq OWNED BY pgz_sport.audit_log.id;


--
-- Name: roles; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.roles (
    id integer NOT NULL,
    code text NOT NULL,
    naziv text NOT NULL,
    opis text,
    permissions jsonb DEFAULT '{}'::jsonb,
    created_at timestamp with time zone DEFAULT now()
);


ALTER TABLE pgz_sport.roles OWNER TO rinet;

--
-- Name: roles_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.roles_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.roles_id_seq OWNER TO rinet;

--
-- Name: roles_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.roles_id_seq OWNED BY pgz_sport.roles.id;


--
-- Name: sys_audit; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_audit (
    id bigint NOT NULL,
    user_id integer,
    user_email character varying(200),
    action character varying(100) NOT NULL,
    target_type character varying(50),
    target_id integer,
    target_text text,
    payload jsonb,
    ip_address inet,
    user_agent text,
    created_at timestamp with time zone DEFAULT now(),
    prev_hash text,
    row_hash text,
    chain_idx bigint
);


ALTER TABLE pgz_sport.sys_audit OWNER TO rinet;

--
-- Name: sys_audit_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.sys_audit_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.sys_audit_id_seq OWNER TO rinet;

--
-- Name: sys_audit_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.sys_audit_id_seq OWNED BY pgz_sport.sys_audit.id;


--
-- Name: sys_permissions; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_permissions (
    id integer NOT NULL,
    code character varying(50) NOT NULL,
    naziv character varying(200),
    opis text,
    kategorija character varying(50)
);


ALTER TABLE pgz_sport.sys_permissions OWNER TO rinet;

--
-- Name: sys_permissions_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.sys_permissions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.sys_permissions_id_seq OWNER TO rinet;

--
-- Name: sys_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.sys_permissions_id_seq OWNED BY pgz_sport.sys_permissions.id;


--
-- Name: sys_role_permissions; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_role_permissions (
    user_type character varying(30) NOT NULL,
    permission_code character varying(50) NOT NULL,
    granted boolean DEFAULT true
);


ALTER TABLE pgz_sport.sys_role_permissions OWNER TO rinet;

--
-- Name: sys_sessions; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_sessions (
    id bigint NOT NULL,
    user_id integer,
    session_token character varying(100) NOT NULL,
    ip_address inet,
    user_agent text,
    expires_at timestamp with time zone NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    last_activity timestamp with time zone DEFAULT now(),
    revoked boolean DEFAULT false
);


ALTER TABLE pgz_sport.sys_sessions OWNER TO rinet;

--
-- Name: sys_sessions_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.sys_sessions_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.sys_sessions_id_seq OWNER TO rinet;

--
-- Name: sys_sessions_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.sys_sessions_id_seq OWNED BY pgz_sport.sys_sessions.id;


--
-- Name: sys_user_klub_links; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_user_klub_links (
    id integer NOT NULL,
    user_id integer,
    klub_id integer,
    savez_id integer,
    role character varying(50),
    primary_link boolean DEFAULT false,
    od_datuma date,
    do_datuma date,
    aktivan boolean DEFAULT true,
    granted_by integer,
    granted_at timestamp with time zone DEFAULT now(),
    note text
);


ALTER TABLE pgz_sport.sys_user_klub_links OWNER TO rinet;

--
-- Name: sys_user_klub_links_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.sys_user_klub_links_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.sys_user_klub_links_id_seq OWNER TO rinet;

--
-- Name: sys_user_klub_links_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.sys_user_klub_links_id_seq OWNED BY pgz_sport.sys_user_klub_links.id;


--
-- Name: sys_user_permissions; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_user_permissions (
    user_id integer NOT NULL,
    permission_code character varying(50) NOT NULL,
    granted boolean DEFAULT true,
    granted_by integer,
    granted_at timestamp with time zone DEFAULT now()
);


ALTER TABLE pgz_sport.sys_user_permissions OWNER TO rinet;

--
-- Name: sys_users; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.sys_users (
    id integer NOT NULL,
    email character varying(200) NOT NULL,
    password_hash character varying(200),
    ime character varying(100),
    prezime character varying(100),
    oib character varying(11),
    telefon character varying(50),
    user_type character varying(30) NOT NULL,
    klub_id integer,
    savez_id integer,
    permissions jsonb DEFAULT '{}'::jsonb,
    aktivan boolean DEFAULT true,
    last_login timestamp with time zone,
    failed_login_count integer DEFAULT 0,
    locked_until timestamp with time zone,
    auth_provider character varying(20) DEFAULT 'local'::character varying,
    google_sub character varying(100),
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now(),
    created_by integer,
    note text,
    CONSTRAINT sys_users_user_type_check CHECK (((user_type)::text = ANY ((ARRAY['super_admin'::character varying, 'pgz_admin'::character varying, 'pgz_user'::character varying, 'pgz_finance'::character varying, 'pgz_zzjz'::character varying, 'savez_admin'::character varying, 'savez_user'::character varying, 'klub_admin'::character varying, 'klub_user'::character varying, 'klub_clan'::character varying, 'guest'::character varying])::text[])))
);


ALTER TABLE pgz_sport.sys_users OWNER TO rinet;

--
-- Name: sys_users_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.sys_users_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.sys_users_id_seq OWNER TO rinet;

--
-- Name: sys_users_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.sys_users_id_seq OWNED BY pgz_sport.sys_users.id;


--
-- Name: user_klub_links; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.user_klub_links (
    id integer NOT NULL,
    user_id integer,
    klub_id integer,
    clan_id integer,
    link_type text NOT NULL,
    od_datuma date,
    do_datuma date,
    primary_klub boolean DEFAULT true,
    napomena text,
    created_at timestamp with time zone DEFAULT now()
);


ALTER TABLE pgz_sport.user_klub_links OWNER TO rinet;

--
-- Name: user_klub_links_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.user_klub_links_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.user_klub_links_id_seq OWNER TO rinet;

--
-- Name: user_klub_links_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.user_klub_links_id_seq OWNED BY pgz_sport.user_klub_links.id;


--
-- Name: user_roles; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.user_roles (
    id integer NOT NULL,
    user_id integer,
    role_id integer,
    scope_type text,
    scope_id integer,
    granted_by integer,
    granted_at timestamp with time zone DEFAULT now(),
    expires_at timestamp with time zone,
    active boolean DEFAULT true
);


ALTER TABLE pgz_sport.user_roles OWNER TO rinet;

--
-- Name: user_roles_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.user_roles_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.user_roles_id_seq OWNER TO rinet;

--
-- Name: user_roles_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.user_roles_id_seq OWNED BY pgz_sport.user_roles.id;


--
-- Name: user_sessions; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.user_sessions (
    id integer NOT NULL,
    user_id integer,
    token_hash text NOT NULL,
    device_info text,
    ip_address inet,
    created_at timestamp with time zone DEFAULT now(),
    expires_at timestamp with time zone NOT NULL,
    revoked boolean DEFAULT false
);


ALTER TABLE pgz_sport.user_sessions OWNER TO rinet;

--
-- Name: user_sessions_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.user_sessions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.user_sessions_id_seq OWNER TO rinet;

--
-- Name: user_sessions_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.user_sessions_id_seq OWNED BY pgz_sport.user_sessions.id;


--
-- Name: users; Type: TABLE; Schema: pgz_sport; Owner: rinet
--

CREATE TABLE pgz_sport.users (
    id integer NOT NULL,
    email text NOT NULL,
    full_name text,
    oib text,
    phone text,
    password_hash text,
    google_sub text,
    google_picture text,
    status text DEFAULT 'active'::text,
    email_verified boolean DEFAULT false,
    billing_user_id integer,
    preferred_language text DEFAULT 'hr'::text,
    last_login timestamp with time zone,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now()
);


ALTER TABLE pgz_sport.users OWNER TO rinet;

--
-- Name: users_id_seq; Type: SEQUENCE; Schema: pgz_sport; Owner: rinet
--

CREATE SEQUENCE pgz_sport.users_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE pgz_sport.users_id_seq OWNER TO rinet;

--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: pgz_sport; Owner: rinet
--

ALTER SEQUENCE pgz_sport.users_id_seq OWNED BY pgz_sport.users.id;


--
-- Name: audit_events id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.audit_events ALTER COLUMN id SET DEFAULT nextval('pgz_sport.audit_events_id_seq'::regclass);


--
-- Name: audit_log id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.audit_log ALTER COLUMN id SET DEFAULT nextval('pgz_sport.audit_log_id_seq'::regclass);


--
-- Name: roles id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.roles ALTER COLUMN id SET DEFAULT nextval('pgz_sport.roles_id_seq'::regclass);


--
-- Name: sys_audit id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_audit ALTER COLUMN id SET DEFAULT nextval('pgz_sport.sys_audit_id_seq'::regclass);


--
-- Name: sys_permissions id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_permissions ALTER COLUMN id SET DEFAULT nextval('pgz_sport.sys_permissions_id_seq'::regclass);


--
-- Name: sys_sessions id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_sessions ALTER COLUMN id SET DEFAULT nextval('pgz_sport.sys_sessions_id_seq'::regclass);


--
-- Name: sys_user_klub_links id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links ALTER COLUMN id SET DEFAULT nextval('pgz_sport.sys_user_klub_links_id_seq'::regclass);


--
-- Name: sys_users id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_users ALTER COLUMN id SET DEFAULT nextval('pgz_sport.sys_users_id_seq'::regclass);


--
-- Name: user_klub_links id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_klub_links ALTER COLUMN id SET DEFAULT nextval('pgz_sport.user_klub_links_id_seq'::regclass);


--
-- Name: user_roles id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_roles ALTER COLUMN id SET DEFAULT nextval('pgz_sport.user_roles_id_seq'::regclass);


--
-- Name: user_sessions id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_sessions ALTER COLUMN id SET DEFAULT nextval('pgz_sport.user_sessions_id_seq'::regclass);


--
-- Name: users id; Type: DEFAULT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.users ALTER COLUMN id SET DEFAULT nextval('pgz_sport.users_id_seq'::regclass);


--
-- Name: audit_events audit_events_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.audit_events
    ADD CONSTRAINT audit_events_pkey PRIMARY KEY (id);


--
-- Name: audit_log audit_log_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.audit_log
    ADD CONSTRAINT audit_log_pkey PRIMARY KEY (id);


--
-- Name: roles roles_code_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.roles
    ADD CONSTRAINT roles_code_key UNIQUE (code);


--
-- Name: roles roles_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.roles
    ADD CONSTRAINT roles_pkey PRIMARY KEY (id);


--
-- Name: sys_audit sys_audit_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_audit
    ADD CONSTRAINT sys_audit_pkey PRIMARY KEY (id);


--
-- Name: sys_permissions sys_permissions_code_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_permissions
    ADD CONSTRAINT sys_permissions_code_key UNIQUE (code);


--
-- Name: sys_permissions sys_permissions_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_permissions
    ADD CONSTRAINT sys_permissions_pkey PRIMARY KEY (id);


--
-- Name: sys_role_permissions sys_role_permissions_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_role_permissions
    ADD CONSTRAINT sys_role_permissions_pkey PRIMARY KEY (user_type, permission_code);


--
-- Name: sys_sessions sys_sessions_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_sessions
    ADD CONSTRAINT sys_sessions_pkey PRIMARY KEY (id);


--
-- Name: sys_sessions sys_sessions_session_token_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_sessions
    ADD CONSTRAINT sys_sessions_session_token_key UNIQUE (session_token);


--
-- Name: sys_user_klub_links sys_user_klub_links_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links
    ADD CONSTRAINT sys_user_klub_links_pkey PRIMARY KEY (id);


--
-- Name: sys_user_klub_links sys_user_klub_links_user_id_klub_id_savez_id_role_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links
    ADD CONSTRAINT sys_user_klub_links_user_id_klub_id_savez_id_role_key UNIQUE (user_id, klub_id, savez_id, role);


--
-- Name: sys_user_permissions sys_user_permissions_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_permissions
    ADD CONSTRAINT sys_user_permissions_pkey PRIMARY KEY (user_id, permission_code);


--
-- Name: sys_users sys_users_email_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_users
    ADD CONSTRAINT sys_users_email_key UNIQUE (email);


--
-- Name: sys_users sys_users_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_users
    ADD CONSTRAINT sys_users_pkey PRIMARY KEY (id);


--
-- Name: user_klub_links user_klub_links_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_klub_links
    ADD CONSTRAINT user_klub_links_pkey PRIMARY KEY (id);


--
-- Name: user_klub_links user_klub_links_user_id_klub_id_link_type_od_datuma_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_klub_links
    ADD CONSTRAINT user_klub_links_user_id_klub_id_link_type_od_datuma_key UNIQUE (user_id, klub_id, link_type, od_datuma);


--
-- Name: user_roles user_roles_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_roles
    ADD CONSTRAINT user_roles_pkey PRIMARY KEY (id);


--
-- Name: user_roles user_roles_user_id_role_id_scope_type_scope_id_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_roles
    ADD CONSTRAINT user_roles_user_id_role_id_scope_type_scope_id_key UNIQUE (user_id, role_id, scope_type, scope_id);


--
-- Name: user_sessions user_sessions_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_sessions
    ADD CONSTRAINT user_sessions_pkey PRIMARY KEY (id);


--
-- Name: user_sessions user_sessions_token_hash_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_sessions
    ADD CONSTRAINT user_sessions_token_hash_key UNIQUE (token_hash);


--
-- Name: users users_email_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.users
    ADD CONSTRAINT users_email_key UNIQUE (email);


--
-- Name: users users_google_sub_key; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.users
    ADD CONSTRAINT users_google_sub_key UNIQUE (google_sub);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: idx_audit_resource; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX idx_audit_resource ON pgz_sport.audit_events USING btree (resource_type, resource_id, ts DESC);


--
-- Name: idx_audit_tablica; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX idx_audit_tablica ON pgz_sport.audit_log USING btree (tablica);


--
-- Name: idx_audit_ts; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX idx_audit_ts ON pgz_sport.audit_log USING btree ("timestamp");


--
-- Name: idx_audit_user_ts; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX idx_audit_user_ts ON pgz_sport.audit_events USING btree (user_id, ts DESC);


--
-- Name: idx_sessions_token; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX idx_sessions_token ON pgz_sport.user_sessions USING btree (token_hash);


--
-- Name: idx_sessions_user; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX idx_sessions_user ON pgz_sport.user_sessions USING btree (user_id);


--
-- Name: ix_sys_audit_action; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_audit_action ON pgz_sport.sys_audit USING btree (action, created_at DESC);


--
-- Name: ix_sys_audit_chain; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_audit_chain ON pgz_sport.sys_audit USING btree (chain_idx);


--
-- Name: ix_sys_audit_row_hash; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_audit_row_hash ON pgz_sport.sys_audit USING btree (row_hash);


--
-- Name: ix_sys_audit_target; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_audit_target ON pgz_sport.sys_audit USING btree (target_type, target_id);


--
-- Name: ix_sys_audit_user; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_audit_user ON pgz_sport.sys_audit USING btree (user_id, created_at DESC);


--
-- Name: ix_sys_sessions_token; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_sessions_token ON pgz_sport.sys_sessions USING btree (session_token) WHERE (revoked = false);


--
-- Name: ix_sys_sessions_user; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_sessions_user ON pgz_sport.sys_sessions USING btree (user_id);


--
-- Name: ix_sys_ukl_klub; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_ukl_klub ON pgz_sport.sys_user_klub_links USING btree (klub_id);


--
-- Name: ix_sys_ukl_savez; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_ukl_savez ON pgz_sport.sys_user_klub_links USING btree (savez_id);


--
-- Name: ix_sys_ukl_user; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_ukl_user ON pgz_sport.sys_user_klub_links USING btree (user_id);


--
-- Name: ix_sys_users_email; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_users_email ON pgz_sport.sys_users USING btree (email);


--
-- Name: ix_sys_users_klub; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_users_klub ON pgz_sport.sys_users USING btree (klub_id);


--
-- Name: ix_sys_users_savez; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_users_savez ON pgz_sport.sys_users USING btree (savez_id);


--
-- Name: ix_sys_users_type; Type: INDEX; Schema: pgz_sport; Owner: rinet
--

CREATE INDEX ix_sys_users_type ON pgz_sport.sys_users USING btree (user_type);


--
-- Name: sys_audit trg_audit_chain; Type: TRIGGER; Schema: pgz_sport; Owner: rinet
--

CREATE TRIGGER trg_audit_chain BEFORE INSERT ON pgz_sport.sys_audit FOR EACH ROW EXECUTE FUNCTION pgz_sport.audit_chain_hash();


--
-- Name: audit_events audit_events_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.audit_events
    ADD CONSTRAINT audit_events_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.users(id);


--
-- Name: sys_audit sys_audit_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_audit
    ADD CONSTRAINT sys_audit_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.sys_users(id) ON DELETE SET NULL;


--
-- Name: sys_role_permissions sys_role_permissions_permission_code_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_role_permissions
    ADD CONSTRAINT sys_role_permissions_permission_code_fkey FOREIGN KEY (permission_code) REFERENCES pgz_sport.sys_permissions(code);


--
-- Name: sys_sessions sys_sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_sessions
    ADD CONSTRAINT sys_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.sys_users(id) ON DELETE CASCADE;


--
-- Name: sys_user_klub_links sys_user_klub_links_granted_by_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links
    ADD CONSTRAINT sys_user_klub_links_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES pgz_sport.sys_users(id);


--
-- Name: sys_user_klub_links sys_user_klub_links_klub_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links
    ADD CONSTRAINT sys_user_klub_links_klub_id_fkey FOREIGN KEY (klub_id) REFERENCES pgz_sport.klubovi(id) ON DELETE CASCADE;


--
-- Name: sys_user_klub_links sys_user_klub_links_savez_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links
    ADD CONSTRAINT sys_user_klub_links_savez_id_fkey FOREIGN KEY (savez_id) REFERENCES pgz_sport.savezi(id) ON DELETE CASCADE;


--
-- Name: sys_user_klub_links sys_user_klub_links_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_klub_links
    ADD CONSTRAINT sys_user_klub_links_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.sys_users(id) ON DELETE CASCADE;


--
-- Name: sys_user_permissions sys_user_permissions_granted_by_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_permissions
    ADD CONSTRAINT sys_user_permissions_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES pgz_sport.sys_users(id);


--
-- Name: sys_user_permissions sys_user_permissions_permission_code_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_permissions
    ADD CONSTRAINT sys_user_permissions_permission_code_fkey FOREIGN KEY (permission_code) REFERENCES pgz_sport.sys_permissions(code);


--
-- Name: sys_user_permissions sys_user_permissions_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_user_permissions
    ADD CONSTRAINT sys_user_permissions_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.sys_users(id) ON DELETE CASCADE;


--
-- Name: sys_users sys_users_klub_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_users
    ADD CONSTRAINT sys_users_klub_id_fkey FOREIGN KEY (klub_id) REFERENCES pgz_sport.klubovi(id) ON DELETE SET NULL;


--
-- Name: sys_users sys_users_savez_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.sys_users
    ADD CONSTRAINT sys_users_savez_id_fkey FOREIGN KEY (savez_id) REFERENCES pgz_sport.savezi(id) ON DELETE SET NULL;


--
-- Name: user_klub_links user_klub_links_clan_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_klub_links
    ADD CONSTRAINT user_klub_links_clan_id_fkey FOREIGN KEY (clan_id) REFERENCES pgz_sport.clanovi(id);


--
-- Name: user_klub_links user_klub_links_klub_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_klub_links
    ADD CONSTRAINT user_klub_links_klub_id_fkey FOREIGN KEY (klub_id) REFERENCES pgz_sport.klubovi(id) ON DELETE CASCADE;


--
-- Name: user_klub_links user_klub_links_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_klub_links
    ADD CONSTRAINT user_klub_links_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.users(id) ON DELETE CASCADE;


--
-- Name: user_roles user_roles_granted_by_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_roles
    ADD CONSTRAINT user_roles_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES pgz_sport.users(id);


--
-- Name: user_roles user_roles_role_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_roles
    ADD CONSTRAINT user_roles_role_id_fkey FOREIGN KEY (role_id) REFERENCES pgz_sport.roles(id) ON DELETE RESTRICT;


--
-- Name: user_roles user_roles_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_roles
    ADD CONSTRAINT user_roles_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.users(id) ON DELETE CASCADE;


--
-- Name: user_sessions user_sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.user_sessions
    ADD CONSTRAINT user_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES pgz_sport.users(id) ON DELETE CASCADE;


--
-- Name: users users_billing_user_id_fkey; Type: FK CONSTRAINT; Schema: pgz_sport; Owner: rinet
--

ALTER TABLE ONLY pgz_sport.users
    ADD CONSTRAINT users_billing_user_id_fkey FOREIGN KEY (billing_user_id) REFERENCES billing.users(id);


--
-- PostgreSQL database dump complete
--

\unrestrict EyRcpjsnvnw9n7b8so76p7PAg1NWhmLAPEQh1liAhf6RheNHVbJBA0Z7sA2gWiQ

