\q
--
-- PostgreSQL database dump
--

-- Dumped from database version 15.13
-- Dumped by pg_dump version 15.13

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;

--
-- Name: legacy; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA legacy;


ALTER SCHEMA legacy OWNER TO postgres;

--
-- Name: check_user_pass(text, text); Type: FUNCTION; Schema: legacy; Owner: postgres
--

CREATE FUNCTION legacy.check_user_pass(username text, password text) RETURNS name
    LANGUAGE sql
    AS $_$
  SELECT rolname AS username
  FROM pg_authid
  -- regexp-split scram hash:
  CROSS JOIN LATERAL regexp_match(rolpassword, '^SCRAM-SHA-256\$(.*):(.*)\$(.*):(.*)$') AS rm
  -- identify regexp groups with sane names:
  CROSS JOIN LATERAL (SELECT rm[1]::integer AS iteration_count, decode(rm[2], 'base64') as salt, decode(rm[3], 'base64') AS stored_key, decode(rm[4], 'base64') AS server_key, 32 AS digest_length) AS stored_password_part
  -- calculate pbkdf2-digest:
  CROSS JOIN LATERAL (SELECT basic_auth.pbkdf2(salt, check_user_pass.password, iteration_count, digest_length, 'sha256')) AS digest_key(digest_key)
  -- based on that, calculate hashed passwort part:
  CROSS JOIN LATERAL (SELECT 
	digest(hmac('Client Key', digest_key, 'sha256'), 'sha256') AS stored_key,
	hmac('Server Key', digest_key, 'sha256') AS server_key) AS check_password_part
  WHERE rolpassword IS NOT NULL
    AND pg_authid.rolname = check_user_pass.username
    -- verify password:
    AND check_password_part.stored_key = stored_password_part.stored_key
    AND check_password_part.server_key = stored_password_part.server_key;
$_$;


ALTER FUNCTION legacy.check_user_pass(username text, password text) OWNER TO postgres;

--
-- Name: ensure_subuser_exists(common.dataimpulsepool, text); Type: FUNCTION; Schema: legacy; Owner: postgres
--

CREATE FUNCTION legacy.ensure_subuser_exists(pool common.dataimpulsepool DEFAULT 'residential'::common.dataimpulsepool, user_id text DEFAULT common.current_user_id()) RETURNS text
    LANGUAGE plpgsql
    AS $_$
DECLARE
  sub_id TEXT;
BEGIN
  SELECT all_user.user_id 
  FROM legacy.all_user
  WHERE all_user.user_id = ensure_subuser_exists.user_id 
  INTO user_id;

  IF user_id IS NULL THEN
    RAISE sqlstate 'PT422' USING
      message = format($message$user '%s' does not exists$message$, user_id);
  END IF;

  SELECT "user".sub_id 
  FROM legacy."user"
  WHERE 
    "user".user_id = ensure_subuser_exists.user_id 
     AND "user".pool::DATAIMPULSEPOOL = ensure_subuser_exists.pool
  INTO sub_id;
  
  IF sub_id IS NULL THEN
    sub_id := dataimpulse.create_subuser(user_id::TEXT, NULL, NULL, NULL, pool, NULL)->>'id';
    INSERT INTO legacy."user" (user_id, buy_num, sub_id, pool, used_promo_list) 
    VALUES (user_id, 0, sub_id::BIGINT, pool, '');
  END IF;

  RETURN sub_id;
END $_$;


ALTER FUNCTION legacy.ensure_subuser_exists(pool common.dataimpulsepool, user_id text) OWNER TO postgres;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: available_pay; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.available_pay (
    name text,
    is_available text,
    description text,
    "order" bigint
)
INHERITS (common.created_at, common.updated_at, common.ordered);


ALTER TABLE legacy.available_pay OWNER TO postgres;

--
-- Name: admin_ref; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.admin_ref (
    value text NOT NULL,
    name text NOT NULL,
    number bigint DEFAULT 0 NOT NULL,
    "user" text DEFAULT ''::text NOT NULL,
    user_web text DEFAULT ''::text NOT NULL,
    number_web bigint DEFAULT 0 NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.admin_ref OWNER TO postgres;

--
-- Name: COLUMN admin_ref.value; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.admin_ref.value IS 'Unique referral code';


--
-- Name: COLUMN admin_ref.name; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.admin_ref.name IS 'Display name for the referral link';


--
-- Name: COLUMN admin_ref.number; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.admin_ref.number IS 'Count of telegram bot registrations';


--
-- Name: COLUMN admin_ref."user"; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.admin_ref."user" IS 'Legacy: comma-separated telegram user identifiers';


--
-- Name: COLUMN admin_ref.user_web; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.admin_ref.user_web IS 'Legacy: comma-separated web user identifiers';


--
-- Name: COLUMN admin_ref.number_web; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.admin_ref.number_web IS 'Count of web registrations';


--
-- Name: admin_ref_users; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.admin_ref_users (
    id integer NOT NULL,
    admin_ref_value text NOT NULL,
    user_id text,
    source text NOT NULL,
    CONSTRAINT admin_ref_users_source_check CHECK ((source = ANY (ARRAY['bot'::text, 'web'::text])))
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.admin_ref_users OWNER TO postgres;

--
-- Name: all_user; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.all_user (
    user_id text,
    lang text,
    invited_by text,
    pers_percent text,
    reg_date text,
    username text,
    email text,
    password text,
    role_id bigint,
    confirmed bigint,
    tgcode text,
    tgcode_expires text,
    ref_balance_usd double precision DEFAULT 0 NOT NULL,
    telegram_id text,
    telegram_username text,
    telegram_first_name text,
    telegram_last_name text,
    telegram_language_code text,
    role common.role_type DEFAULT 'vgate_user'::common.role_type NOT NULL,
    notified_low_traffic boolean DEFAULT false NOT NULL,
    telegram_blocked boolean DEFAULT false NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.all_user OWNER TO postgres;

--
-- Name: COLUMN all_user.pers_percent; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.all_user.pers_percent IS 'personal referral persent';


--
-- Name: COLUMN all_user.role_id; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.all_user.role_id IS 'this is not realy related with current app roles, so maybe we need remove that';


--
-- Name: COLUMN all_user.telegram_blocked; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.all_user.telegram_blocked IS 'True if user has blocked the Telegram bot, preventing message delivery';


--
-- Name: promocode; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.promocode (
    promo_name text,
    traffic_amount bigint,
    remaining_activation bigint,
    term text,
    pool text DEFAULT 'residential'::text,
    created_by text
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.promocode OWNER TO postgres;

--
-- Name: request; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.request (
    comment text DEFAULT ''::text NOT NULL,
    amount numeric NOT NULL,
    user_id text NOT NULL,
    id bigint NOT NULL,
    status common.withdraw_request_status DEFAULT 'pending'::common.withdraw_request_status NOT NULL,
    deducted_at timestamp with time zone
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.request OWNER TO postgres;

--
-- Name: admin_ref_users_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.admin_ref_users_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.admin_ref_users_id_seq OWNER TO postgres;

--
-- Name: admin_ref_users_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.admin_ref_users_id_seq OWNED BY legacy.admin_ref_users.id;


--
-- Name: available_pay_order_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

ALTER TABLE legacy.available_pay ALTER COLUMN "order" ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME legacy.available_pay_order_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: banner; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.banner (
    name text,
    photo_id text,
    link text,
    blob bytea,
    id integer NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.banner OWNER TO postgres;

--
-- Name: banner_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.banner_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.banner_id_seq OWNER TO postgres;

--
-- Name: banner_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.banner_id_seq OWNED BY legacy.banner.id;


--
-- Name: blog_article; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.blog_article (
    title text,
    hidden boolean DEFAULT true,
    content text,
    user_id text,
    "order" integer NOT NULL,
    language vgate.language NOT NULL,
    id integer NOT NULL,
    image_blob bytea
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.blog_article OWNER TO postgres;

--
-- Name: COLUMN blog_article.image_blob; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.blog_article.image_blob IS 'Binary image data for blog article header/featured image';


--
-- Name: blog_article_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.blog_article_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.blog_article_id_seq OWNER TO postgres;

--
-- Name: blog_article_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.blog_article_id_seq OWNED BY legacy.blog_article.id;


--
-- Name: blog_article_order_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.blog_article_order_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.blog_article_order_seq OWNER TO postgres;

--
-- Name: blog_article_order_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.blog_article_order_seq OWNED BY legacy.blog_article."order";


--
-- Name: payment; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.payment (
    user_id text NOT NULL,
    subuser_id bigint,
    paid numeric(6,2),
    order_id text,
    amount_gb bigint,
    balance_before text,
    discount text,
    service text,
    date text,
    source text DEFAULT 'bot'::text
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.payment OWNER TO postgres;

--
-- Name: system; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.system (
    key text,
    value text,
    admin_access boolean DEFAULT false NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.system OWNER TO postgres;

--
-- Name: check_missing_referral_payments; Type: VIEW; Schema: legacy; Owner: postgres
--

CREATE VIEW legacy.check_missing_referral_payments AS
 WITH payment_info AS (
         SELECT p.user_id AS buyer_id,
            p.paid AS payment_amount,
            p.order_id,
            p.created_at AS payment_date,
            p.service AS payment_method,
            au.invited_by AS referrer_id,
            COALESCE((au.pers_percent)::double precision, ( SELECT (system.value)::double precision AS value
                   FROM legacy.system
                  WHERE (system.key = 'ref_percent'::text))) AS referral_percent
           FROM (legacy.payment p
             JOIN legacy.all_user au ON ((au.user_id = p.user_id)))
          WHERE ((au.invited_by IS NOT NULL) AND (p.created_at >= '2025-04-25 00:00:00+00'::timestamp with time zone))
        ), referrer_info AS (
         SELECT pi.buyer_id,
            pi.payment_amount,
            pi.order_id,
            pi.payment_date,
            pi.payment_method,
            pi.referrer_id,
            pi.referral_percent,
            au.ref_balance_usd AS current_referral_balance,
            au.username AS referrer_username,
            buyer.username AS buyer_username,
            ((pi.payment_amount)::double precision * pi.referral_percent) AS expected_reward
           FROM ((payment_info pi
             LEFT JOIN legacy.all_user au ON ((au.user_id = pi.referrer_id)))
             LEFT JOIN legacy.all_user buyer ON ((buyer.user_id = pi.buyer_id)))
        )
 SELECT ri.payment_date,
    ri.order_id,
    ri.buyer_username AS buyer,
    ri.buyer_id,
    ri.referrer_username AS referrer,
    ri.referrer_id,
    ri.payment_amount,
    (ri.referral_percent * (100)::double precision) AS referral_percent,
    ri.expected_reward AS should_receive,
    ri.payment_method,
    ri.current_referral_balance
   FROM referrer_info ri
  WHERE ((ri.referrer_id ~ '^\d+$'::text) OR (ri.referrer_id ~~ 'vgate\_%'::text))
  ORDER BY ri.payment_date DESC;


ALTER TABLE legacy.check_missing_referral_payments OWNER TO postgres;

--
-- Name: cross_promo_activations; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.cross_promo_activations (
    promo_name text,
    user_id text,
    gb_amount integer
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.cross_promo_activations OWNER TO postgres;

--
-- Name: disc_promocode; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.disc_promocode (
    name text,
    discount real,
    activations bigint,
    first_use text,
    term text,
    user_for text,
    is_global bigint DEFAULT '0'::bigint
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.disc_promocode OWNER TO postgres;

--
-- Name: discount_tier; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.discount_tier (
    min_amount integer NOT NULL,
    discount double precision
)
INHERITS (common.created_at);


ALTER TABLE legacy.discount_tier OWNER TO postgres;

--
-- Name: invoice; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.invoice (
    id text NOT NULL,
    payment_system text,
    amount integer,
    price numeric,
    user_id text NOT NULL,
    pool common.dataimpulsepool,
    source text DEFAULT 'notknown'::text NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.invoice OWNER TO postgres;

--
-- Name: notification_pool; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.notification_pool (
    target_users text[] NOT NULL,
    message common.format_promise,
    inline_buttons text[] DEFAULT ARRAY[]::text[] NOT NULL,
    message_language vgate.language NOT NULL,
    sended_at timestamp with time zone,
    type text NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.notification_pool OWNER TO postgres;

--
-- Name: price; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.price (
    gb_cost bigint,
    pool text DEFAULT 'residential'::text,
    gb_cost_usd double precision DEFAULT '0'::double precision
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.price OWNER TO postgres;

--
-- Name: promo_activations; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.promo_activations (
    user_id text NOT NULL,
    promo_name text NOT NULL,
    usage_count bigint DEFAULT '0'::bigint,
    promo_type text,
    promo_data jsonb
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.promo_activations OWNER TO postgres;

--
-- Name: recovery_inner; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.recovery_inner (
    code text,
    user_id text,
    exp timestamp without time zone,
    used boolean
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.recovery_inner OWNER TO postgres;

--
-- Name: referral_payment_checks; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.referral_payment_checks (
    id integer NOT NULL,
    payment_date timestamp with time zone,
    order_id text,
    buyer text,
    buyer_id text,
    referrer text,
    referrer_id text,
    payment_amount numeric(12,2),
    referral_percent numeric(5,2),
    should_receive numeric(12,2),
    payment_method text,
    current_referral_balance numeric(12,2),
    returned boolean DEFAULT false
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.referral_payment_checks OWNER TO postgres;

--
-- Name: COLUMN referral_payment_checks.returned; Type: COMMENT; Schema: legacy; Owner: postgres
--

COMMENT ON COLUMN legacy.referral_payment_checks.returned IS 'are referrer received the ref balance';


--
-- Name: referral_payment_checks_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.referral_payment_checks_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.referral_payment_checks_id_seq OWNER TO postgres;

--
-- Name: referral_payment_checks_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.referral_payment_checks_id_seq OWNED BY legacy.referral_payment_checks.id;


--
-- Name: request_in_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.request_in_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.request_in_id_seq OWNER TO postgres;

--
-- Name: request_in_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.request_in_id_seq OWNED BY legacy.request.id;


--
-- Name: role; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.role (
    id bigint NOT NULL,
    name text
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.role OWNER TO postgres;

--
-- Name: role_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.role_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.role_id_seq OWNER TO postgres;

--
-- Name: role_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.role_id_seq OWNED BY legacy.role.id;


--
-- Name: subuser; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.subuser (
    sub_id bigint,
    owner_sub_id bigint,
    label text
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.subuser OWNER TO postgres;

--
-- Name: telegram_message_results; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy.telegram_message_results (
    id bigint NOT NULL,
    batch_id uuid NOT NULL,
    user_id text NOT NULL,
    success boolean NOT NULL,
    http_status integer,
    error_message text,
    bot_token_used text,
    response_content text,
    message_hash common.sha256
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy.telegram_message_results OWNER TO postgres;

--
-- Name: telegram_message_results_id_seq; Type: SEQUENCE; Schema: legacy; Owner: postgres
--

CREATE SEQUENCE legacy.telegram_message_results_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE legacy.telegram_message_results_id_seq OWNER TO postgres;

--
-- Name: telegram_message_results_id_seq; Type: SEQUENCE OWNED BY; Schema: legacy; Owner: postgres
--

ALTER SEQUENCE legacy.telegram_message_results_id_seq OWNED BY legacy.telegram_message_results.id;


--
-- Name: user; Type: TABLE; Schema: legacy; Owner: postgres
--

CREATE TABLE legacy."user" (
    user_id text NOT NULL,
    buy_num bigint DEFAULT 0,
    sub_id bigint,
    used_promo_list text,
    pool common.dataimpulsepool NOT NULL
)
INHERITS (common.created_at, common.updated_at);


ALTER TABLE legacy."user" OWNER TO postgres;

--
-- Name: admin_ref created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: admin_ref updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: admin_ref_users created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: admin_ref_users updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: admin_ref_users id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users ALTER COLUMN id SET DEFAULT nextval('legacy.admin_ref_users_id_seq'::regclass);


--
-- Name: all_user created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.all_user ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: all_user updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.all_user ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: available_pay created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.available_pay ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: available_pay updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.available_pay ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: banner created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.banner ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: banner updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.banner ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: banner id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.banner ALTER COLUMN id SET DEFAULT nextval('legacy.banner_id_seq'::regclass);


--
-- Name: blog_article created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.blog_article ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: blog_article updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.blog_article ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: blog_article order; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.blog_article ALTER COLUMN "order" SET DEFAULT nextval('legacy.blog_article_order_seq'::regclass);


--
-- Name: blog_article id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.blog_article ALTER COLUMN id SET DEFAULT nextval('legacy.blog_article_id_seq'::regclass);


--
-- Name: cross_promo_activations created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.cross_promo_activations ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: cross_promo_activations updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.cross_promo_activations ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: disc_promocode created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.disc_promocode ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: disc_promocode updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.disc_promocode ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: discount_tier created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.discount_tier ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: invoice created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.invoice ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: invoice updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.invoice ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: notification_pool created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.notification_pool ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: notification_pool updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.notification_pool ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: payment created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.payment ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: payment updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.payment ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: price created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.price ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: price updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.price ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: promo_activations created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.promo_activations ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: promo_activations updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.promo_activations ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: promocode created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.promocode ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: promocode updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.promocode ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: recovery_inner created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.recovery_inner ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: recovery_inner updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.recovery_inner ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: referral_payment_checks created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.referral_payment_checks ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: referral_payment_checks updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.referral_payment_checks ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: referral_payment_checks id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.referral_payment_checks ALTER COLUMN id SET DEFAULT nextval('legacy.referral_payment_checks_id_seq'::regclass);


--
-- Name: request created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.request ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: request updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.request ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: request id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.request ALTER COLUMN id SET DEFAULT nextval('legacy.request_in_id_seq'::regclass);


--
-- Name: role created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.role ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: role updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.role ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: role id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.role ALTER COLUMN id SET DEFAULT nextval('legacy.role_id_seq'::regclass);


--
-- Name: subuser created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.subuser ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: subuser updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.subuser ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: system created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.system ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: system updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.system ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: telegram_message_results created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.telegram_message_results ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: telegram_message_results updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.telegram_message_results ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: telegram_message_results id; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.telegram_message_results ALTER COLUMN id SET DEFAULT nextval('legacy.telegram_message_results_id_seq'::regclass);


--
-- Name: user created_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy."user" ALTER COLUMN created_at SET DEFAULT now();


--
-- Name: user updated_at; Type: DEFAULT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy."user" ALTER COLUMN updated_at SET DEFAULT now();


--
-- Name: admin_ref admin_ref_name_unique; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref
    ADD CONSTRAINT admin_ref_name_unique UNIQUE (name);


--
-- Name: admin_ref_users admin_ref_users_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users
    ADD CONSTRAINT admin_ref_users_pkey PRIMARY KEY (id);


--
-- Name: admin_ref admin_ref_value_unique; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref
    ADD CONSTRAINT admin_ref_value_unique UNIQUE (value);


--
-- Name: discount_tier discount_tier_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.discount_tier
    ADD CONSTRAINT discount_tier_pkey PRIMARY KEY (min_amount);


--
-- Name: request idx_16427_request_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.request
    ADD CONSTRAINT idx_16427_request_pkey PRIMARY KEY (id);


--
-- Name: role idx_16469_role_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.role
    ADD CONSTRAINT idx_16469_role_pkey PRIMARY KEY (id);


--
-- Name: promo_activations idx_16475_sqlite_autoindex_promo_activations_1; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.promo_activations
    ADD CONSTRAINT idx_16475_sqlite_autoindex_promo_activations_1 PRIMARY KEY (user_id, promo_name);


--
-- Name: invoice invoice_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.invoice
    ADD CONSTRAINT invoice_pkey PRIMARY KEY (id);


--
-- Name: user legacy_user_pk; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy."user"
    ADD CONSTRAINT legacy_user_pk PRIMARY KEY (user_id, pool);


--
-- Name: referral_payment_checks referral_payment_checks_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.referral_payment_checks
    ADD CONSTRAINT referral_payment_checks_pkey PRIMARY KEY (id);


--
-- Name: system system_key_unique; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.system
    ADD CONSTRAINT system_key_unique UNIQUE (key);


--
-- Name: telegram_message_results telegram_message_results_pkey; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.telegram_message_results
    ADD CONSTRAINT telegram_message_results_pkey PRIMARY KEY (id);


--
-- Name: all_user unique_legacy_user_id; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.all_user
    ADD CONSTRAINT unique_legacy_user_id UNIQUE (user_id);


--
-- Name: admin_ref_users unique_user_ref_source; Type: CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users
    ADD CONSTRAINT unique_user_ref_source UNIQUE (admin_ref_value, user_id, source);


--
-- Name: idx_16407_idx_email; Type: INDEX; Schema: legacy; Owner: postgres
--

CREATE UNIQUE INDEX idx_16407_idx_email ON legacy.all_user USING btree (email);


--
-- Name: idx_16407_idx_username; Type: INDEX; Schema: legacy; Owner: postgres
--

CREATE UNIQUE INDEX idx_16407_idx_username ON legacy.all_user USING btree (username);


--
-- Name: idx_16420_sqlite_autoindex_disc_promocode_1; Type: INDEX; Schema: legacy; Owner: postgres
--

CREATE UNIQUE INDEX idx_16420_sqlite_autoindex_disc_promocode_1 ON legacy.disc_promocode USING btree (name);


--
-- Name: idx_all_user_telegram_blocked; Type: INDEX; Schema: legacy; Owner: postgres
--

CREATE INDEX idx_all_user_telegram_blocked ON legacy.all_user USING btree (telegram_blocked) WHERE (telegram_blocked = true);


--
-- Name: request constraint_name; Type: FK CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.request
    ADD CONSTRAINT constraint_name FOREIGN KEY (user_id) REFERENCES legacy.all_user(user_id);


--
-- Name: admin_ref_users fk_admin_ref_value; Type: FK CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users
    ADD CONSTRAINT fk_admin_ref_value FOREIGN KEY (admin_ref_value) REFERENCES legacy.admin_ref(value) ON DELETE CASCADE;


--
-- Name: invoice fk_legacy_invoice_legacy_all_user; Type: FK CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.invoice
    ADD CONSTRAINT fk_legacy_invoice_legacy_all_user FOREIGN KEY (user_id) REFERENCES legacy.all_user(user_id);


--
-- Name: payment fk_legacy_payment_legacy_all_user; Type: FK CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.payment
    ADD CONSTRAINT fk_legacy_payment_legacy_all_user FOREIGN KEY (user_id) REFERENCES legacy.all_user(user_id);


--
-- Name: promocode fk_legacy_promocode_created_by_user_id; Type: FK CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.promocode
    ADD CONSTRAINT fk_legacy_promocode_created_by_user_id FOREIGN KEY (created_by) REFERENCES legacy.all_user(user_id);


--
-- Name: admin_ref_users fk_user_id; Type: FK CONSTRAINT; Schema: legacy; Owner: postgres
--

ALTER TABLE ONLY legacy.admin_ref_users
    ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES legacy.all_user(user_id) ON DELETE SET NULL;


--
-- Name: SCHEMA legacy; Type: ACL; Schema: -; Owner: postgres
--

GRANT USAGE ON SCHEMA legacy TO vgate_provider;


--
-- Name: TABLE available_pay; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.available_pay TO vgate_provider;


--
-- Name: TABLE admin_ref; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.admin_ref TO vgate_provider;


--
-- Name: TABLE all_user; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.all_user TO vgate_provider;


--
-- Name: TABLE promocode; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.promocode TO vgate_provider;


--
-- Name: TABLE request; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.request TO vgate_provider;


--
-- Name: TABLE banner; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.banner TO vgate_provider;


--
-- Name: TABLE payment; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.payment TO vgate_provider;


--
-- Name: TABLE system; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.system TO vgate_provider;


--
-- Name: TABLE cross_promo_activations; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT ALL ON TABLE legacy.cross_promo_activations TO vgate_tg_bot;


--
-- Name: TABLE disc_promocode; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.disc_promocode TO vgate_provider;


--
-- Name: TABLE invoice; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT ALL ON TABLE legacy.invoice TO vgate_provider;


--
-- Name: TABLE price; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.price TO vgate_provider;


--
-- Name: TABLE promo_activations; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.promo_activations TO vgate_provider;


--
-- Name: TABLE role; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.role TO vgate_provider;


--
-- Name: TABLE subuser; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT SELECT,INSERT ON TABLE legacy.subuser TO vgate_provider;


--
-- Name: TABLE "user"; Type: ACL; Schema: legacy; Owner: postgres
--

GRANT ALL ON TABLE legacy."user" TO vgate_provider;


--
-- PostgreSQL database dump complete
--

