core: register badges migration (#7429)

This commit is contained in:
spaced4ndy
2026-08-28 10:20:13 +00:00
committed by GitHub
parent e80a174f13
commit 6075ea5797
8 changed files with 700 additions and 18 deletions
@@ -168,6 +168,159 @@ CREATE TABLE test_chat_schema.app_settings (
CREATE TABLE test_chat_schema.badge_code_redemptions (
badge_code_redemption_id bigint NOT NULL,
user_id bigint NOT NULL,
code text NOT NULL,
purchase_key bytea NOT NULL,
purchase_priv_key bytea NOT NULL,
master_key bytea NOT NULL,
created_at timestamp with time zone NOT NULL
);
ALTER TABLE test_chat_schema.badge_code_redemptions ALTER COLUMN badge_code_redemption_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME test_chat_schema.badge_code_redemptions_badge_code_redemption_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
CREATE TABLE test_chat_schema.badge_invoices (
invoice_id text NOT NULL,
badge_purchase_id bigint NOT NULL,
price_id text NOT NULL,
offer_id text,
months smallint NOT NULL,
created_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.badge_issuances (
issuance_id text NOT NULL,
badge_purchase_id bigint NOT NULL,
entry_id bigint,
badge_type text NOT NULL,
period_start timestamp with time zone NOT NULL,
period_end timestamp with time zone NOT NULL,
expiry timestamp with time zone NOT NULL,
credential bytea NOT NULL,
created_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.badge_ledger (
entry_id bigint NOT NULL,
entry_uuid text NOT NULL,
badge_purchase_id bigint NOT NULL,
change_months smallint NOT NULL,
balance_months smallint NOT NULL,
balance_start_ts timestamp with time zone NOT NULL,
balance_badge_type text NOT NULL,
was_paused_since timestamp with time zone,
service_created_at timestamp with time zone NOT NULL,
created_at timestamp with time zone NOT NULL,
entry_type text NOT NULL,
entry_credit_type text,
entry_debit_type text,
payment_id text,
charge_id text,
from_purchase_id bigint,
to_purchase_id bigint,
entry_type_unknown smallint DEFAULT 0 NOT NULL,
entry_type_value text
);
ALTER TABLE test_chat_schema.badge_ledger ALTER COLUMN entry_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME test_chat_schema.badge_ledger_entry_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
CREATE TABLE test_chat_schema.badge_offers (
offer_id text NOT NULL,
price_id text,
months smallint NOT NULL,
free_months smallint,
discount smallint,
status text NOT NULL,
created_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.badge_prices (
price_id text NOT NULL,
badge_type text NOT NULL,
month_price bigint NOT NULL,
currency text NOT NULL,
status text NOT NULL,
created_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.badge_purchases (
badge_purchase_id bigint NOT NULL,
purchase_key bytea NOT NULL,
master_key bytea NOT NULL,
initial_badge_type text NOT NULL,
current_badge_type text NOT NULL,
payment_id text,
status text NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
user_id bigint,
purchase_priv_key bytea,
alert_acked_kind text,
alert_acked_episode text,
alert_snooze_until timestamp with time zone,
badge_code_redemption_id bigint
);
ALTER TABLE test_chat_schema.badge_purchases ALTER COLUMN badge_purchase_id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME test_chat_schema.badge_purchases_badge_purchase_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
CREATE TABLE test_chat_schema.badge_subscription_changes (
change_id text NOT NULL,
badge_purchase_id bigint NOT NULL,
from_badge_type text NOT NULL,
to_badge_type text NOT NULL,
from_provider_ref text,
to_provider_ref text,
effective text NOT NULL,
status text NOT NULL,
effective_at timestamp with time zone,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.calls (
call_id bigint NOT NULL,
contact_id bigint NOT NULL,
@@ -999,7 +1152,7 @@ CREATE TABLE test_chat_schema.groups (
public_member_count bigint,
relay_request_retries bigint DEFAULT 0 NOT NULL,
relay_request_delay bigint DEFAULT 0 NOT NULL,
relay_request_execute_at timestamp with time zone DEFAULT '1970-01-01 01:00:00+01'::timestamp with time zone NOT NULL,
relay_request_execute_at timestamp with time zone DEFAULT '1970-01-01 04:00:00+04'::timestamp with time zone NOT NULL,
relay_inactive_at timestamp with time zone,
relay_sent_web_domain text,
roster_version bigint,
@@ -1027,6 +1180,26 @@ ALTER TABLE test_chat_schema.groups ALTER COLUMN group_id ADD GENERATED ALWAYS A
CREATE TABLE test_chat_schema.invoices (
invoice_id text NOT NULL,
provider text NOT NULL,
price bigint NOT NULL,
discount_amount bigint,
credit_amount bigint,
amount bigint NOT NULL,
currency text NOT NULL,
payment_url text,
payment_address text,
payment_crypto_currency text,
payment_crypto_amount text,
expires_at timestamp with time zone NOT NULL,
status text NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.known_servers (
server_id bigint NOT NULL,
host text NOT NULL,
@@ -1160,6 +1333,26 @@ ALTER TABLE test_chat_schema.operator_usage_conditions ALTER COLUMN operator_usa
CREATE TABLE test_chat_schema.payments (
payment_id text NOT NULL,
invoice_id text,
provider text NOT NULL,
provider_ref text,
amount bigint,
currency text,
status text NOT NULL,
exception text,
subscription_renews_at timestamp with time zone,
grace_until timestamp with time zone,
cancelled smallint DEFAULT 0 NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
evidence bytea,
receipt_code text
);
CREATE TABLE test_chat_schema.pending_group_messages (
pending_group_message_id bigint NOT NULL,
group_member_id bigint NOT NULL,
@@ -1454,6 +1647,19 @@ CREATE TABLE test_chat_schema.snd_files (
CREATE TABLE test_chat_schema.subscription_charges (
charge_id text NOT NULL,
payment_id text NOT NULL,
provider_charge_ref text NOT NULL,
period_start timestamp with time zone NOT NULL,
period_end timestamp with time zone NOT NULL,
amount bigint NOT NULL,
currency text NOT NULL,
charged_at timestamp with time zone NOT NULL
);
CREATE TABLE test_chat_schema.usage_conditions (
usage_conditions_id bigint NOT NULL,
conditions_commit text NOT NULL,
@@ -1516,7 +1722,8 @@ CREATE TABLE test_chat_schema.users (
auto_accept_member_contacts smallint DEFAULT 0 NOT NULL,
is_user_chat_relay smallint DEFAULT 0 NOT NULL,
client_service smallint DEFAULT 0 NOT NULL,
auto_accept_group_invitations smallint DEFAULT 0 NOT NULL
auto_accept_group_invitations smallint DEFAULT 0 NOT NULL,
shown_badge_id bigint
);
@@ -1555,6 +1762,61 @@ ALTER TABLE test_chat_schema.xftp_file_descriptions ALTER COLUMN file_descr_id A
ALTER TABLE ONLY test_chat_schema.badge_code_redemptions
ADD CONSTRAINT badge_code_redemptions_code_key UNIQUE (code);
ALTER TABLE ONLY test_chat_schema.badge_code_redemptions
ADD CONSTRAINT badge_code_redemptions_pkey PRIMARY KEY (badge_code_redemption_id);
ALTER TABLE ONLY test_chat_schema.badge_invoices
ADD CONSTRAINT badge_invoices_pkey PRIMARY KEY (invoice_id);
ALTER TABLE ONLY test_chat_schema.badge_issuances
ADD CONSTRAINT badge_issuances_pkey PRIMARY KEY (issuance_id);
ALTER TABLE ONLY test_chat_schema.badge_ledger
ADD CONSTRAINT badge_ledger_pkey PRIMARY KEY (entry_id);
ALTER TABLE ONLY test_chat_schema.badge_offers
ADD CONSTRAINT badge_offers_pkey PRIMARY KEY (offer_id);
ALTER TABLE ONLY test_chat_schema.badge_prices
ADD CONSTRAINT badge_prices_pkey PRIMARY KEY (price_id);
ALTER TABLE ONLY test_chat_schema.badge_purchases
ADD CONSTRAINT badge_purchases_payment_id_key UNIQUE (payment_id);
ALTER TABLE ONLY test_chat_schema.badge_purchases
ADD CONSTRAINT badge_purchases_pkey PRIMARY KEY (badge_purchase_id);
ALTER TABLE ONLY test_chat_schema.badge_purchases
ADD CONSTRAINT badge_purchases_purchase_key_key UNIQUE (purchase_key);
ALTER TABLE ONLY test_chat_schema.badge_subscription_changes
ADD CONSTRAINT badge_subscription_changes_pkey PRIMARY KEY (change_id);
ALTER TABLE ONLY test_chat_schema.calls
ADD CONSTRAINT calls_pkey PRIMARY KEY (call_id);
@@ -1745,6 +2007,11 @@ ALTER TABLE ONLY test_chat_schema.groups
ALTER TABLE ONLY test_chat_schema.invoices
ADD CONSTRAINT invoices_pkey PRIMARY KEY (invoice_id);
ALTER TABLE ONLY test_chat_schema.known_servers
ADD CONSTRAINT known_servers_pkey PRIMARY KEY (server_id);
@@ -1780,6 +2047,11 @@ ALTER TABLE ONLY test_chat_schema.operator_usage_conditions
ALTER TABLE ONLY test_chat_schema.payments
ADD CONSTRAINT payments_pkey PRIMARY KEY (payment_id);
ALTER TABLE ONLY test_chat_schema.pending_group_messages
ADD CONSTRAINT pending_group_messages_pkey PRIMARY KEY (pending_group_message_id);
@@ -1855,6 +2127,16 @@ ALTER TABLE ONLY test_chat_schema.snd_files
ALTER TABLE ONLY test_chat_schema.subscription_charges
ADD CONSTRAINT subscription_charges_payment_id_provider_charge_ref_key UNIQUE (payment_id, provider_charge_ref);
ALTER TABLE ONLY test_chat_schema.subscription_charges
ADD CONSTRAINT subscription_charges_pkey PRIMARY KEY (charge_id);
ALTER TABLE ONLY test_chat_schema.usage_conditions
ADD CONSTRAINT usage_conditions_conditions_commit_key UNIQUE (conditions_commit);
@@ -1907,6 +2189,70 @@ CREATE INDEX files_note_folder_id ON test_chat_schema.files USING btree (note_fo
CREATE INDEX idx_badge_code_redemptions_user ON test_chat_schema.badge_code_redemptions USING btree (user_id);
CREATE INDEX idx_badge_invoices_offer ON test_chat_schema.badge_invoices USING btree (offer_id);
CREATE INDEX idx_badge_invoices_price ON test_chat_schema.badge_invoices USING btree (price_id);
CREATE INDEX idx_badge_invoices_purchase ON test_chat_schema.badge_invoices USING btree (badge_purchase_id);
CREATE INDEX idx_badge_issuances_entry ON test_chat_schema.badge_issuances USING btree (entry_id);
CREATE INDEX idx_badge_issuances_purchase ON test_chat_schema.badge_issuances USING btree (badge_purchase_id, issuance_id);
CREATE INDEX idx_badge_ledger_charge ON test_chat_schema.badge_ledger USING btree (charge_id);
CREATE INDEX idx_badge_ledger_from_purchase ON test_chat_schema.badge_ledger USING btree (from_purchase_id);
CREATE INDEX idx_badge_ledger_payment ON test_chat_schema.badge_ledger USING btree (payment_id);
CREATE INDEX idx_badge_ledger_purchase ON test_chat_schema.badge_ledger USING btree (badge_purchase_id, entry_id);
CREATE INDEX idx_badge_ledger_to_purchase ON test_chat_schema.badge_ledger USING btree (to_purchase_id);
CREATE UNIQUE INDEX idx_badge_ledger_uuid ON test_chat_schema.badge_ledger USING btree (entry_uuid);
CREATE INDEX idx_badge_offers_price ON test_chat_schema.badge_offers USING btree (price_id);
CREATE UNIQUE INDEX idx_badge_purchases_code_redemption ON test_chat_schema.badge_purchases USING btree (badge_code_redemption_id);
CREATE INDEX idx_badge_purchases_user ON test_chat_schema.badge_purchases USING btree (user_id);
CREATE INDEX idx_badge_subscription_changes_purchase ON test_chat_schema.badge_subscription_changes USING btree (badge_purchase_id);
CREATE INDEX idx_calls_chat_item_id ON test_chat_schema.calls USING btree (chat_item_id);
@@ -2511,6 +2857,14 @@ CREATE INDEX idx_operator_usage_conditions_server_operator_id ON test_chat_schem
CREATE INDEX idx_payments_invoice ON test_chat_schema.payments USING btree (invoice_id);
CREATE INDEX idx_payments_provider_ref ON test_chat_schema.payments USING btree (provider, provider_ref);
CREATE INDEX idx_pending_group_messages_group_member_id ON test_chat_schema.pending_group_messages USING btree (group_member_id);
@@ -2639,6 +2993,10 @@ CREATE UNIQUE INDEX idx_user_contact_links_group_id ON test_chat_schema.user_con
CREATE INDEX idx_users_shown_badge ON test_chat_schema.users USING btree (shown_badge_id);
CREATE INDEX idx_xftp_file_descriptions_user_id ON test_chat_schema.xftp_file_descriptions USING btree (user_id);
@@ -2659,6 +3017,91 @@ CREATE TRIGGER tr_group_members_update_update_summary AFTER UPDATE ON test_chat_
ALTER TABLE ONLY test_chat_schema.badge_code_redemptions
ADD CONSTRAINT badge_code_redemptions_user_id_fkey FOREIGN KEY (user_id) REFERENCES test_chat_schema.users(user_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.badge_invoices
ADD CONSTRAINT badge_invoices_badge_purchase_id_fkey FOREIGN KEY (badge_purchase_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.badge_invoices
ADD CONSTRAINT badge_invoices_invoice_id_fkey FOREIGN KEY (invoice_id) REFERENCES test_chat_schema.invoices(invoice_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.badge_invoices
ADD CONSTRAINT badge_invoices_offer_id_fkey FOREIGN KEY (offer_id) REFERENCES test_chat_schema.badge_offers(offer_id);
ALTER TABLE ONLY test_chat_schema.badge_invoices
ADD CONSTRAINT badge_invoices_price_id_fkey FOREIGN KEY (price_id) REFERENCES test_chat_schema.badge_prices(price_id);
ALTER TABLE ONLY test_chat_schema.badge_issuances
ADD CONSTRAINT badge_issuances_badge_purchase_id_fkey FOREIGN KEY (badge_purchase_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.badge_issuances
ADD CONSTRAINT badge_issuances_entry_id_fkey FOREIGN KEY (entry_id) REFERENCES test_chat_schema.badge_ledger(entry_id);
ALTER TABLE ONLY test_chat_schema.badge_ledger
ADD CONSTRAINT badge_ledger_badge_purchase_id_fkey FOREIGN KEY (badge_purchase_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.badge_ledger
ADD CONSTRAINT badge_ledger_charge_id_fkey FOREIGN KEY (charge_id) REFERENCES test_chat_schema.subscription_charges(charge_id);
ALTER TABLE ONLY test_chat_schema.badge_ledger
ADD CONSTRAINT badge_ledger_from_purchase_id_fkey FOREIGN KEY (from_purchase_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id);
ALTER TABLE ONLY test_chat_schema.badge_ledger
ADD CONSTRAINT badge_ledger_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES test_chat_schema.payments(payment_id);
ALTER TABLE ONLY test_chat_schema.badge_ledger
ADD CONSTRAINT badge_ledger_to_purchase_id_fkey FOREIGN KEY (to_purchase_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id);
ALTER TABLE ONLY test_chat_schema.badge_offers
ADD CONSTRAINT badge_offers_price_id_fkey FOREIGN KEY (price_id) REFERENCES test_chat_schema.badge_prices(price_id);
ALTER TABLE ONLY test_chat_schema.badge_purchases
ADD CONSTRAINT badge_purchases_badge_code_redemption_id_fkey FOREIGN KEY (badge_code_redemption_id) REFERENCES test_chat_schema.badge_code_redemptions(badge_code_redemption_id);
ALTER TABLE ONLY test_chat_schema.badge_purchases
ADD CONSTRAINT badge_purchases_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES test_chat_schema.payments(payment_id);
ALTER TABLE ONLY test_chat_schema.badge_purchases
ADD CONSTRAINT badge_purchases_user_id_fkey FOREIGN KEY (user_id) REFERENCES test_chat_schema.users(user_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.badge_subscription_changes
ADD CONSTRAINT badge_subscription_changes_badge_purchase_id_fkey FOREIGN KEY (badge_purchase_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.calls
ADD CONSTRAINT calls_chat_item_id_fkey FOREIGN KEY (chat_item_id) REFERENCES test_chat_schema.chat_items(chat_item_id) ON DELETE CASCADE;
@@ -3199,6 +3642,11 @@ ALTER TABLE ONLY test_chat_schema.operator_usage_conditions
ALTER TABLE ONLY test_chat_schema.payments
ADD CONSTRAINT payments_invoice_id_fkey FOREIGN KEY (invoice_id) REFERENCES test_chat_schema.invoices(invoice_id);
ALTER TABLE ONLY test_chat_schema.pending_group_messages
ADD CONSTRAINT pending_group_messages_group_member_id_fkey FOREIGN KEY (group_member_id) REFERENCES test_chat_schema.group_members(group_member_id) ON DELETE CASCADE;
@@ -3304,6 +3752,11 @@ ALTER TABLE ONLY test_chat_schema.snd_files
ALTER TABLE ONLY test_chat_schema.subscription_charges
ADD CONSTRAINT subscription_charges_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES test_chat_schema.payments(payment_id) ON DELETE CASCADE;
ALTER TABLE ONLY test_chat_schema.user_contact_links
ADD CONSTRAINT user_contact_links_group_id_fkey FOREIGN KEY (group_id) REFERENCES test_chat_schema.groups(group_id) ON DELETE CASCADE;
@@ -3314,6 +3767,11 @@ ALTER TABLE ONLY test_chat_schema.user_contact_links
ALTER TABLE ONLY test_chat_schema.users
ADD CONSTRAINT users_shown_badge_id_fkey FOREIGN KEY (shown_badge_id) REFERENCES test_chat_schema.badge_purchases(badge_purchase_id) ON DELETE SET NULL;
ALTER TABLE ONLY test_chat_schema.xftp_file_descriptions
ADD CONSTRAINT xftp_file_descriptions_user_id_fkey FOREIGN KEY (user_id) REFERENCES test_chat_schema.users(user_id) ON DELETE CASCADE;