From cc5dd07ffd6e39c84520f7a20b7b0964877490ea Mon Sep 17 00:00:00 2001 From: Toon Willems Date: Thu, 19 Dec 2024 11:14:31 +0100 Subject: [PATCH] update schema --- config/database.yml | 4 +- db/events_structure.sql | 226 +++++++++++++++++++++++++++++++++++++++- db/structure.sql | 226 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 451 insertions(+), 5 deletions(-) diff --git a/config/database.yml b/config/database.yml index a9fee607e20..8dcb3b252fb 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,6 +19,7 @@ development: clickhouse: adapter: clickhouse database: default + schema_format: 'ruby' host: clickhouse port: 8123 username: default @@ -44,9 +45,10 @@ test: username: <%= ENV.fetch('LAGO_CLICKHOUSE_USERNAME', 'default') %> password: <%= ENV.fetch('LAGO_CLICKHOUSE_PASSWORD', 'default') %> migrations_paths: db/clickhouse_migrate + schema_format: 'ruby' debug: true database_tasks: <% if ENV['LAGO_CLICKHOUSE_MIGRATIONS_ENABLED'].present? %> true <% else %> false <% end %> - schema_dump: <% if ENV['LAGO_DISABLE_SCHEMA_DUMP'].present? %> false <% else %> clickhouse_structure.sql <% end %> + schema_dump: <% if ENV['LAGO_DISABLE_SCHEMA_DUMP'].present? %> false <% else %> clickhouse_schema.rb <% end %> staging: primary: diff --git a/db/events_structure.sql b/db/events_structure.sql index c957117d591..09e77ae638c 100644 --- a/db/events_structure.sql +++ b/db/events_structure.sql @@ -19,6 +19,7 @@ ALTER TABLE IF EXISTS ONLY public.fees DROP CONSTRAINT IF EXISTS fk_rails_eaca94 ALTER TABLE IF EXISTS ONLY public.integration_customers DROP CONSTRAINT IF EXISTS fk_rails_ea80151038; ALTER TABLE IF EXISTS ONLY public.recurring_transaction_rules DROP CONSTRAINT IF EXISTS fk_rails_e8bac9c5bb; ALTER TABLE IF EXISTS ONLY public.credit_note_items DROP CONSTRAINT IF EXISTS fk_rails_dea748e529; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS fk_rails_dd7e076158; ALTER TABLE IF EXISTS ONLY public.invites DROP CONSTRAINT IF EXISTS fk_rails_dd342449a6; ALTER TABLE IF EXISTS ONLY public.fees DROP CONSTRAINT IF EXISTS fk_rails_d9ffb8b4a1; ALTER TABLE IF EXISTS ONLY public.coupon_targets DROP CONSTRAINT IF EXISTS fk_rails_d1dc5814e9; @@ -38,6 +39,7 @@ ALTER TABLE IF EXISTS ONLY public.commitments_taxes DROP CONSTRAINT IF EXISTS fk ALTER TABLE IF EXISTS ONLY public.integration_items DROP CONSTRAINT IF EXISTS fk_rails_a9dc2ea536; ALTER TABLE IF EXISTS ONLY public.charges DROP CONSTRAINT IF EXISTS fk_rails_a710519346; ALTER TABLE IF EXISTS ONLY public.group_properties DROP CONSTRAINT IF EXISTS fk_rails_a2d2cb3819; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS fk_rails_9ff1d277f3; ALTER TABLE IF EXISTS ONLY public.credit_note_items DROP CONSTRAINT IF EXISTS fk_rails_9f22076477; ALTER TABLE IF EXISTS ONLY public.wallet_transactions DROP CONSTRAINT IF EXISTS fk_rails_9ea6759859; ALTER TABLE IF EXISTS ONLY public.applied_add_ons DROP CONSTRAINT IF EXISTS fk_rails_9c8e276cc0; @@ -61,6 +63,7 @@ ALTER TABLE IF EXISTS ONLY public.add_ons DROP CONSTRAINT IF EXISTS fk_rails_81e ALTER TABLE IF EXISTS ONLY public.charges DROP CONSTRAINT IF EXISTS fk_rails_7eb0484711; ALTER TABLE IF EXISTS ONLY public.billable_metrics DROP CONSTRAINT IF EXISTS fk_rails_7e8a2f26e5; ALTER TABLE IF EXISTS ONLY public.charge_filter_values DROP CONSTRAINT IF EXISTS fk_rails_7da558cadc; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_sections DROP CONSTRAINT IF EXISTS fk_rails_7c0e340dbd; ALTER TABLE IF EXISTS ONLY public.adjusted_fees DROP CONSTRAINT IF EXISTS fk_rails_7b324610ad; ALTER TABLE IF EXISTS ONLY public.api_keys DROP CONSTRAINT IF EXISTS fk_rails_7aab96f30e; ALTER TABLE IF EXISTS ONLY public.billable_metric_filters DROP CONSTRAINT IF EXISTS fk_rails_7a0704ce72; @@ -73,6 +76,7 @@ ALTER TABLE IF EXISTS ONLY public.data_exports DROP CONSTRAINT IF EXISTS fk_rail ALTER TABLE IF EXISTS ONLY public.invoices_taxes DROP CONSTRAINT IF EXISTS fk_rails_6e148ccbb1; ALTER TABLE IF EXISTS ONLY public.adjusted_fees DROP CONSTRAINT IF EXISTS fk_rails_6d465e6b10; ALTER TABLE IF EXISTS ONLY public.dunning_campaigns DROP CONSTRAINT IF EXISTS fk_rails_6c720a8ccd; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS fk_rails_6b1e3d1159; ALTER TABLE IF EXISTS ONLY public.integration_resources DROP CONSTRAINT IF EXISTS fk_rails_67d4eb3c92; ALTER TABLE IF EXISTS ONLY public.subscriptions DROP CONSTRAINT IF EXISTS fk_rails_66eb6b32c1; ALTER TABLE IF EXISTS ONLY public.taxes DROP CONSTRAINT IF EXISTS fk_rails_65b48ef6bf; @@ -126,6 +130,7 @@ ALTER TABLE IF EXISTS ONLY public.webhooks DROP CONSTRAINT IF EXISTS fk_rails_20 ALTER TABLE IF EXISTS ONLY public.credits DROP CONSTRAINT IF EXISTS fk_rails_1db0057d9b; ALTER TABLE IF EXISTS ONLY public.customer_metadata DROP CONSTRAINT IF EXISTS fk_rails_195153290d; ALTER TABLE IF EXISTS ONLY public.daily_usages DROP CONSTRAINT IF EXISTS fk_rails_12d29bc654; +ALTER TABLE IF EXISTS ONLY public.applied_invoice_custom_sections DROP CONSTRAINT IF EXISTS fk_rails_10428ecad2; ALTER TABLE IF EXISTS ONLY public.integration_customers DROP CONSTRAINT IF EXISTS fk_rails_0e464363cb; ALTER TABLE IF EXISTS ONLY public.invoices DROP CONSTRAINT IF EXISTS fk_rails_0d349e632f; ALTER TABLE IF EXISTS ONLY public.add_ons_taxes DROP CONSTRAINT IF EXISTS fk_rails_08dfe87131; @@ -195,6 +200,7 @@ DROP INDEX IF EXISTS public.index_plans_on_created_at; DROP INDEX IF EXISTS public.index_payments_on_payment_provider_id; DROP INDEX IF EXISTS public.index_payments_on_payment_provider_customer_id; DROP INDEX IF EXISTS public.index_payments_on_payable_type_and_payable_id; +DROP INDEX IF EXISTS public.index_payments_on_payable_id_and_payable_type; DROP INDEX IF EXISTS public.index_payments_on_invoice_id; DROP INDEX IF EXISTS public.index_payment_requests_on_organization_id; DROP INDEX IF EXISTS public.index_payment_requests_on_dunning_campaign_id; @@ -234,6 +240,10 @@ DROP INDEX IF EXISTS public.index_invoice_subscriptions_on_charges_from_and_to_d DROP INDEX IF EXISTS public.index_invoice_subscriptions_boundaries; DROP INDEX IF EXISTS public.index_invoice_metadata_on_invoice_id_and_key; DROP INDEX IF EXISTS public.index_invoice_metadata_on_invoice_id; +DROP INDEX IF EXISTS public.index_invoice_custom_sections_on_organization_id_and_code; +DROP INDEX IF EXISTS public.index_invoice_custom_sections_on_organization_id; +DROP INDEX IF EXISTS public.index_invoice_custom_section_selections_on_organization_id; +DROP INDEX IF EXISTS public.index_invoice_custom_section_selections_on_customer_id; DROP INDEX IF EXISTS public.index_invites_on_token; DROP INDEX IF EXISTS public.index_invites_on_organization_id; DROP INDEX IF EXISTS public.index_invites_on_membership_id; @@ -360,6 +370,7 @@ DROP INDEX IF EXISTS public.index_billable_metric_filters_on_deleted_at; DROP INDEX IF EXISTS public.index_billable_metric_filters_on_billable_metric_id; DROP INDEX IF EXISTS public.index_applied_usage_thresholds_on_usage_threshold_id; DROP INDEX IF EXISTS public.index_applied_usage_thresholds_on_invoice_id; +DROP INDEX IF EXISTS public.index_applied_invoice_custom_sections_on_invoice_id; DROP INDEX IF EXISTS public.index_applied_coupons_on_customer_id; DROP INDEX IF EXISTS public.index_applied_coupons_on_coupon_id; DROP INDEX IF EXISTS public.index_applied_add_ons_on_customer_id; @@ -389,7 +400,9 @@ DROP INDEX IF EXISTS public.index_active_charge_filter_values; DROP INDEX IF EXISTS public.idx_on_usage_threshold_id_invoice_id_cb82cdf163; DROP INDEX IF EXISTS public.idx_on_start_processing_at_external_subscription_id_31b81116ce; DROP INDEX IF EXISTS public.idx_on_organization_id_external_subscription_id_df3a30d96d; +DROP INDEX IF EXISTS public.idx_on_organization_id_deleted_at_225e3f789d; DROP INDEX IF EXISTS public.idx_on_invoice_id_payment_request_id_aa550779a4; +DROP INDEX IF EXISTS public.idx_on_invoice_custom_section_id_7edbcef7b5; DROP INDEX IF EXISTS public.idx_on_external_subscription_id_organization_id_40aa74e2eb; DROP INDEX IF EXISTS public.idx_on_dunning_campaign_id_currency_fbf233b2ae; DROP INDEX IF EXISTS public.idx_on_amount_cents_plan_id_recurring_888044d66b; @@ -423,6 +436,8 @@ ALTER TABLE IF EXISTS ONLY public.invoices_payment_requests DROP CONSTRAINT IF E ALTER TABLE IF EXISTS ONLY public.invoice_subscriptions DROP CONSTRAINT IF EXISTS invoice_subscriptions_pkey; ALTER TABLE IF EXISTS ONLY public.invoice_metadata DROP CONSTRAINT IF EXISTS invoice_metadata_pkey; ALTER TABLE IF EXISTS ONLY public.invoice_errors DROP CONSTRAINT IF EXISTS invoice_errors_pkey; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_sections DROP CONSTRAINT IF EXISTS invoice_custom_sections_pkey; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS invoice_custom_section_selections_pkey; ALTER TABLE IF EXISTS ONLY public.invites DROP CONSTRAINT IF EXISTS invites_pkey; ALTER TABLE IF EXISTS ONLY public.integrations DROP CONSTRAINT IF EXISTS integrations_pkey; ALTER TABLE IF EXISTS ONLY public.integration_resources DROP CONSTRAINT IF EXISTS integration_resources_pkey; @@ -461,6 +476,7 @@ ALTER TABLE IF EXISTS ONLY public.billable_metrics DROP CONSTRAINT IF EXISTS bil ALTER TABLE IF EXISTS ONLY public.billable_metric_filters DROP CONSTRAINT IF EXISTS billable_metric_filters_pkey; ALTER TABLE IF EXISTS ONLY public.ar_internal_metadata DROP CONSTRAINT IF EXISTS ar_internal_metadata_pkey; ALTER TABLE IF EXISTS ONLY public.applied_usage_thresholds DROP CONSTRAINT IF EXISTS applied_usage_thresholds_pkey; +ALTER TABLE IF EXISTS ONLY public.applied_invoice_custom_sections DROP CONSTRAINT IF EXISTS applied_invoice_custom_sections_pkey; ALTER TABLE IF EXISTS ONLY public.applied_coupons DROP CONSTRAINT IF EXISTS applied_coupons_pkey; ALTER TABLE IF EXISTS ONLY public.applied_add_ons DROP CONSTRAINT IF EXISTS applied_add_ons_pkey; ALTER TABLE IF EXISTS ONLY public.api_keys DROP CONSTRAINT IF EXISTS api_keys_pkey; @@ -503,6 +519,8 @@ DROP TABLE IF EXISTS public.invoices; DROP TABLE IF EXISTS public.invoice_subscriptions; DROP TABLE IF EXISTS public.invoice_metadata; DROP TABLE IF EXISTS public.invoice_errors; +DROP TABLE IF EXISTS public.invoice_custom_sections; +DROP TABLE IF EXISTS public.invoice_custom_section_selections; DROP TABLE IF EXISTS public.invites; DROP TABLE IF EXISTS public.integrations; DROP TABLE IF EXISTS public.integration_resources; @@ -542,6 +560,7 @@ DROP TABLE IF EXISTS public.billable_metrics; DROP TABLE IF EXISTS public.billable_metric_filters; DROP TABLE IF EXISTS public.ar_internal_metadata; DROP TABLE IF EXISTS public.applied_usage_thresholds; +DROP TABLE IF EXISTS public.applied_invoice_custom_sections; DROP TABLE IF EXISTS public.applied_coupons; DROP TABLE IF EXISTS public.applied_add_ons; DROP TABLE IF EXISTS public.api_keys; @@ -552,7 +571,9 @@ DROP TABLE IF EXISTS public.active_storage_variant_records; DROP TABLE IF EXISTS public.active_storage_blobs; DROP TABLE IF EXISTS public.active_storage_attachments; DROP PROCEDURE IF EXISTS public.trigger_subscription_update(IN p_organization_id uuid, IN p_external_subscription_id character varying); +DROP TYPE IF EXISTS public.tax_status; DROP TYPE IF EXISTS public.subscription_invoicing_reason; +DROP TYPE IF EXISTS public.payment_payable_payment_status; DROP TYPE IF EXISTS public.customer_type; DROP TYPE IF EXISTS public.billable_metric_weighted_interval; DROP TYPE IF EXISTS public.billable_metric_rounding_function; @@ -624,6 +645,18 @@ CREATE TYPE public.customer_type AS ENUM ( ); +-- +-- Name: payment_payable_payment_status; Type: TYPE; Schema: public; Owner: - +-- + +CREATE TYPE public.payment_payable_payment_status AS ENUM ( + 'pending', + 'processing', + 'succeeded', + 'failed' +); + + -- -- Name: subscription_invoicing_reason; Type: TYPE; Schema: public; Owner: - -- @@ -638,6 +671,17 @@ CREATE TYPE public.subscription_invoicing_reason AS ENUM ( ); +-- +-- Name: tax_status; Type: TYPE; Schema: public; Owner: - +-- + +CREATE TYPE public.tax_status AS ENUM ( + 'pending', + 'succeeded', + 'failed' +); + + -- -- Name: trigger_subscription_update(uuid, character varying); Type: PROCEDURE; Schema: public; Owner: - -- @@ -818,6 +862,22 @@ CREATE TABLE public.applied_coupons ( ); +-- +-- Name: applied_invoice_custom_sections; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.applied_invoice_custom_sections ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + name character varying NOT NULL, + code character varying NOT NULL, + display_name character varying, + details character varying, + invoice_id uuid NOT NULL, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + -- -- Name: applied_usage_thresholds; Type: TABLE; Schema: public; Owner: - -- @@ -1222,6 +1282,7 @@ CREATE TABLE public.customers ( exclude_from_dunning_campaign boolean DEFAULT false NOT NULL, last_dunning_campaign_attempt integer DEFAULT 0 NOT NULL, last_dunning_campaign_attempt_at timestamp without time zone, + skip_invoice_custom_sections boolean DEFAULT false NOT NULL, CONSTRAINT check_customers_on_invoice_grace_period CHECK ((invoice_grace_period >= 0)), CONSTRAINT check_customers_on_net_payment_term CHECK ((net_payment_term >= 0)) ); @@ -1586,6 +1647,38 @@ CREATE TABLE public.invites ( ); +-- +-- Name: invoice_custom_section_selections; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.invoice_custom_section_selections ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + invoice_custom_section_id uuid NOT NULL, + organization_id uuid, + customer_id uuid, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: invoice_custom_sections; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.invoice_custom_sections ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + name character varying NOT NULL, + code character varying NOT NULL, + description character varying, + display_name character varying, + details character varying, + organization_id uuid NOT NULL, + deleted_at timestamp without time zone, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + -- -- Name: invoice_errors; Type: TABLE; Schema: public; Owner: - -- @@ -1676,6 +1769,7 @@ CREATE TABLE public.invoices ( payment_overdue boolean DEFAULT false, negative_amount_cents bigint DEFAULT 0 NOT NULL, progressive_billing_credit_amount_cents bigint DEFAULT 0 NOT NULL, + tax_status public.tax_status, CONSTRAINT check_organizations_on_net_payment_term CHECK ((net_payment_term >= 0)) ); @@ -1907,13 +2001,14 @@ CREATE TABLE public.payments ( payment_provider_customer_id uuid, amount_cents bigint NOT NULL, amount_currency character varying NOT NULL, - provider_payment_id character varying NOT NULL, + provider_payment_id character varying, status character varying NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, payable_type character varying DEFAULT 'Invoice'::character varying NOT NULL, payable_id uuid, - provider_payment_data jsonb DEFAULT '{}'::jsonb + provider_payment_data jsonb DEFAULT '{}'::jsonb, + payable_payment_status public.payment_payable_payment_status ); @@ -2318,6 +2413,14 @@ ALTER TABLE ONLY public.applied_coupons ADD CONSTRAINT applied_coupons_pkey PRIMARY KEY (id); +-- +-- Name: applied_invoice_custom_sections applied_invoice_custom_sections_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.applied_invoice_custom_sections + ADD CONSTRAINT applied_invoice_custom_sections_pkey PRIMARY KEY (id); + + -- -- Name: applied_usage_thresholds applied_usage_thresholds_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2622,6 +2725,22 @@ ALTER TABLE ONLY public.invites ADD CONSTRAINT invites_pkey PRIMARY KEY (id); +-- +-- Name: invoice_custom_section_selections invoice_custom_section_selections_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT invoice_custom_section_selections_pkey PRIMARY KEY (id); + + +-- +-- Name: invoice_custom_sections invoice_custom_sections_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_sections + ADD CONSTRAINT invoice_custom_sections_pkey PRIMARY KEY (id); + + -- -- Name: invoice_errors invoice_errors_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2883,6 +3002,13 @@ CREATE UNIQUE INDEX idx_on_dunning_campaign_id_currency_fbf233b2ae ON public.dun CREATE UNIQUE INDEX idx_on_external_subscription_id_organization_id_40aa74e2eb ON public.subscription_event_triggers USING btree (external_subscription_id, organization_id) WHERE (start_processing_at IS NULL); +-- +-- Name: idx_on_invoice_custom_section_id_7edbcef7b5; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_on_invoice_custom_section_id_7edbcef7b5 ON public.invoice_custom_section_selections USING btree (invoice_custom_section_id); + + -- -- Name: idx_on_invoice_id_payment_request_id_aa550779a4; Type: INDEX; Schema: public; Owner: - -- @@ -2890,6 +3016,13 @@ CREATE UNIQUE INDEX idx_on_external_subscription_id_organization_id_40aa74e2eb O CREATE UNIQUE INDEX idx_on_invoice_id_payment_request_id_aa550779a4 ON public.invoices_payment_requests USING btree (invoice_id, payment_request_id); +-- +-- Name: idx_on_organization_id_deleted_at_225e3f789d; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_on_organization_id_deleted_at_225e3f789d ON public.invoice_custom_sections USING btree (organization_id, deleted_at); + + -- -- Name: idx_on_organization_id_external_subscription_id_df3a30d96d; Type: INDEX; Schema: public; Owner: - -- @@ -3093,6 +3226,13 @@ CREATE INDEX index_applied_coupons_on_coupon_id ON public.applied_coupons USING CREATE INDEX index_applied_coupons_on_customer_id ON public.applied_coupons USING btree (customer_id); +-- +-- Name: index_applied_invoice_custom_sections_on_invoice_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_applied_invoice_custom_sections_on_invoice_id ON public.applied_invoice_custom_sections USING btree (invoice_id); + + -- -- Name: index_applied_usage_thresholds_on_invoice_id; Type: INDEX; Schema: public; Owner: - -- @@ -3975,6 +4115,34 @@ CREATE INDEX index_invites_on_organization_id ON public.invites USING btree (org CREATE UNIQUE INDEX index_invites_on_token ON public.invites USING btree (token); +-- +-- Name: index_invoice_custom_section_selections_on_customer_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_invoice_custom_section_selections_on_customer_id ON public.invoice_custom_section_selections USING btree (customer_id); + + +-- +-- Name: index_invoice_custom_section_selections_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_invoice_custom_section_selections_on_organization_id ON public.invoice_custom_section_selections USING btree (organization_id); + + +-- +-- Name: index_invoice_custom_sections_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_invoice_custom_sections_on_organization_id ON public.invoice_custom_sections USING btree (organization_id); + + +-- +-- Name: index_invoice_custom_sections_on_organization_id_and_code; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_invoice_custom_sections_on_organization_id_and_code ON public.invoice_custom_sections USING btree (organization_id, code); + + -- -- Name: index_invoice_metadata_on_invoice_id; Type: INDEX; Schema: public; Owner: - -- @@ -4248,6 +4416,13 @@ CREATE INDEX index_payment_requests_on_organization_id ON public.payment_request CREATE INDEX index_payments_on_invoice_id ON public.payments USING btree (invoice_id); +-- +-- Name: index_payments_on_payable_id_and_payable_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_payments_on_payable_id_and_payable_type ON public.payments USING btree (payable_id, payable_type) WHERE (payable_payment_status = ANY (ARRAY['pending'::public.payment_payable_payment_status, 'processing'::public.payment_payable_payment_status])); + + -- -- Name: index_payments_on_payable_type_and_payable_id; Type: INDEX; Schema: public; Owner: - -- @@ -4676,6 +4851,14 @@ ALTER TABLE ONLY public.integration_customers ADD CONSTRAINT fk_rails_0e464363cb FOREIGN KEY (customer_id) REFERENCES public.customers(id); +-- +-- Name: applied_invoice_custom_sections fk_rails_10428ecad2; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.applied_invoice_custom_sections + ADD CONSTRAINT fk_rails_10428ecad2 FOREIGN KEY (invoice_id) REFERENCES public.invoices(id); + + -- -- Name: daily_usages fk_rails_12d29bc654; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5100,6 +5283,14 @@ ALTER TABLE ONLY public.integration_resources ADD CONSTRAINT fk_rails_67d4eb3c92 FOREIGN KEY (integration_id) REFERENCES public.integrations(id); +-- +-- Name: invoice_custom_section_selections fk_rails_6b1e3d1159; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT fk_rails_6b1e3d1159 FOREIGN KEY (organization_id) REFERENCES public.organizations(id); + + -- -- Name: dunning_campaigns fk_rails_6c720a8ccd; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5196,6 +5387,14 @@ ALTER TABLE ONLY public.adjusted_fees ADD CONSTRAINT fk_rails_7b324610ad FOREIGN KEY (charge_id) REFERENCES public.charges(id); +-- +-- Name: invoice_custom_sections fk_rails_7c0e340dbd; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_sections + ADD CONSTRAINT fk_rails_7c0e340dbd FOREIGN KEY (organization_id) REFERENCES public.organizations(id); + + -- -- Name: charge_filter_values fk_rails_7da558cadc; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5380,6 +5579,14 @@ ALTER TABLE ONLY public.credit_note_items ADD CONSTRAINT fk_rails_9f22076477 FOREIGN KEY (credit_note_id) REFERENCES public.credit_notes(id); +-- +-- Name: invoice_custom_section_selections fk_rails_9ff1d277f3; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT fk_rails_9ff1d277f3 FOREIGN KEY (invoice_custom_section_id) REFERENCES public.invoice_custom_sections(id); + + -- -- Name: group_properties fk_rails_a2d2cb3819; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5532,6 +5739,14 @@ ALTER TABLE ONLY public.invites ADD CONSTRAINT fk_rails_dd342449a6 FOREIGN KEY (organization_id) REFERENCES public.organizations(id); +-- +-- Name: invoice_custom_section_selections fk_rails_dd7e076158; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT fk_rails_dd7e076158 FOREIGN KEY (customer_id) REFERENCES public.customers(id); + + -- -- Name: credit_note_items fk_rails_dea748e529; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5619,6 +5834,9 @@ ALTER TABLE ONLY public.adjusted_fees SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES +('20241216140931'), +('20241216110525'), +('20241213142739'), ('20241203141040'), ('20241203140905'), ('20241203135310'), @@ -5628,6 +5846,10 @@ INSERT INTO "schema_migrations" (version) VALUES ('20241126103448'), ('20241126102447'), ('20241125194753'), +('20241122141158'), +('20241122140603'), +('20241122134430'), +('20241122111534'), ('20241122105327'), ('20241122105133'), ('20241122104537'), diff --git a/db/structure.sql b/db/structure.sql index c957117d591..09e77ae638c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -19,6 +19,7 @@ ALTER TABLE IF EXISTS ONLY public.fees DROP CONSTRAINT IF EXISTS fk_rails_eaca94 ALTER TABLE IF EXISTS ONLY public.integration_customers DROP CONSTRAINT IF EXISTS fk_rails_ea80151038; ALTER TABLE IF EXISTS ONLY public.recurring_transaction_rules DROP CONSTRAINT IF EXISTS fk_rails_e8bac9c5bb; ALTER TABLE IF EXISTS ONLY public.credit_note_items DROP CONSTRAINT IF EXISTS fk_rails_dea748e529; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS fk_rails_dd7e076158; ALTER TABLE IF EXISTS ONLY public.invites DROP CONSTRAINT IF EXISTS fk_rails_dd342449a6; ALTER TABLE IF EXISTS ONLY public.fees DROP CONSTRAINT IF EXISTS fk_rails_d9ffb8b4a1; ALTER TABLE IF EXISTS ONLY public.coupon_targets DROP CONSTRAINT IF EXISTS fk_rails_d1dc5814e9; @@ -38,6 +39,7 @@ ALTER TABLE IF EXISTS ONLY public.commitments_taxes DROP CONSTRAINT IF EXISTS fk ALTER TABLE IF EXISTS ONLY public.integration_items DROP CONSTRAINT IF EXISTS fk_rails_a9dc2ea536; ALTER TABLE IF EXISTS ONLY public.charges DROP CONSTRAINT IF EXISTS fk_rails_a710519346; ALTER TABLE IF EXISTS ONLY public.group_properties DROP CONSTRAINT IF EXISTS fk_rails_a2d2cb3819; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS fk_rails_9ff1d277f3; ALTER TABLE IF EXISTS ONLY public.credit_note_items DROP CONSTRAINT IF EXISTS fk_rails_9f22076477; ALTER TABLE IF EXISTS ONLY public.wallet_transactions DROP CONSTRAINT IF EXISTS fk_rails_9ea6759859; ALTER TABLE IF EXISTS ONLY public.applied_add_ons DROP CONSTRAINT IF EXISTS fk_rails_9c8e276cc0; @@ -61,6 +63,7 @@ ALTER TABLE IF EXISTS ONLY public.add_ons DROP CONSTRAINT IF EXISTS fk_rails_81e ALTER TABLE IF EXISTS ONLY public.charges DROP CONSTRAINT IF EXISTS fk_rails_7eb0484711; ALTER TABLE IF EXISTS ONLY public.billable_metrics DROP CONSTRAINT IF EXISTS fk_rails_7e8a2f26e5; ALTER TABLE IF EXISTS ONLY public.charge_filter_values DROP CONSTRAINT IF EXISTS fk_rails_7da558cadc; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_sections DROP CONSTRAINT IF EXISTS fk_rails_7c0e340dbd; ALTER TABLE IF EXISTS ONLY public.adjusted_fees DROP CONSTRAINT IF EXISTS fk_rails_7b324610ad; ALTER TABLE IF EXISTS ONLY public.api_keys DROP CONSTRAINT IF EXISTS fk_rails_7aab96f30e; ALTER TABLE IF EXISTS ONLY public.billable_metric_filters DROP CONSTRAINT IF EXISTS fk_rails_7a0704ce72; @@ -73,6 +76,7 @@ ALTER TABLE IF EXISTS ONLY public.data_exports DROP CONSTRAINT IF EXISTS fk_rail ALTER TABLE IF EXISTS ONLY public.invoices_taxes DROP CONSTRAINT IF EXISTS fk_rails_6e148ccbb1; ALTER TABLE IF EXISTS ONLY public.adjusted_fees DROP CONSTRAINT IF EXISTS fk_rails_6d465e6b10; ALTER TABLE IF EXISTS ONLY public.dunning_campaigns DROP CONSTRAINT IF EXISTS fk_rails_6c720a8ccd; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS fk_rails_6b1e3d1159; ALTER TABLE IF EXISTS ONLY public.integration_resources DROP CONSTRAINT IF EXISTS fk_rails_67d4eb3c92; ALTER TABLE IF EXISTS ONLY public.subscriptions DROP CONSTRAINT IF EXISTS fk_rails_66eb6b32c1; ALTER TABLE IF EXISTS ONLY public.taxes DROP CONSTRAINT IF EXISTS fk_rails_65b48ef6bf; @@ -126,6 +130,7 @@ ALTER TABLE IF EXISTS ONLY public.webhooks DROP CONSTRAINT IF EXISTS fk_rails_20 ALTER TABLE IF EXISTS ONLY public.credits DROP CONSTRAINT IF EXISTS fk_rails_1db0057d9b; ALTER TABLE IF EXISTS ONLY public.customer_metadata DROP CONSTRAINT IF EXISTS fk_rails_195153290d; ALTER TABLE IF EXISTS ONLY public.daily_usages DROP CONSTRAINT IF EXISTS fk_rails_12d29bc654; +ALTER TABLE IF EXISTS ONLY public.applied_invoice_custom_sections DROP CONSTRAINT IF EXISTS fk_rails_10428ecad2; ALTER TABLE IF EXISTS ONLY public.integration_customers DROP CONSTRAINT IF EXISTS fk_rails_0e464363cb; ALTER TABLE IF EXISTS ONLY public.invoices DROP CONSTRAINT IF EXISTS fk_rails_0d349e632f; ALTER TABLE IF EXISTS ONLY public.add_ons_taxes DROP CONSTRAINT IF EXISTS fk_rails_08dfe87131; @@ -195,6 +200,7 @@ DROP INDEX IF EXISTS public.index_plans_on_created_at; DROP INDEX IF EXISTS public.index_payments_on_payment_provider_id; DROP INDEX IF EXISTS public.index_payments_on_payment_provider_customer_id; DROP INDEX IF EXISTS public.index_payments_on_payable_type_and_payable_id; +DROP INDEX IF EXISTS public.index_payments_on_payable_id_and_payable_type; DROP INDEX IF EXISTS public.index_payments_on_invoice_id; DROP INDEX IF EXISTS public.index_payment_requests_on_organization_id; DROP INDEX IF EXISTS public.index_payment_requests_on_dunning_campaign_id; @@ -234,6 +240,10 @@ DROP INDEX IF EXISTS public.index_invoice_subscriptions_on_charges_from_and_to_d DROP INDEX IF EXISTS public.index_invoice_subscriptions_boundaries; DROP INDEX IF EXISTS public.index_invoice_metadata_on_invoice_id_and_key; DROP INDEX IF EXISTS public.index_invoice_metadata_on_invoice_id; +DROP INDEX IF EXISTS public.index_invoice_custom_sections_on_organization_id_and_code; +DROP INDEX IF EXISTS public.index_invoice_custom_sections_on_organization_id; +DROP INDEX IF EXISTS public.index_invoice_custom_section_selections_on_organization_id; +DROP INDEX IF EXISTS public.index_invoice_custom_section_selections_on_customer_id; DROP INDEX IF EXISTS public.index_invites_on_token; DROP INDEX IF EXISTS public.index_invites_on_organization_id; DROP INDEX IF EXISTS public.index_invites_on_membership_id; @@ -360,6 +370,7 @@ DROP INDEX IF EXISTS public.index_billable_metric_filters_on_deleted_at; DROP INDEX IF EXISTS public.index_billable_metric_filters_on_billable_metric_id; DROP INDEX IF EXISTS public.index_applied_usage_thresholds_on_usage_threshold_id; DROP INDEX IF EXISTS public.index_applied_usage_thresholds_on_invoice_id; +DROP INDEX IF EXISTS public.index_applied_invoice_custom_sections_on_invoice_id; DROP INDEX IF EXISTS public.index_applied_coupons_on_customer_id; DROP INDEX IF EXISTS public.index_applied_coupons_on_coupon_id; DROP INDEX IF EXISTS public.index_applied_add_ons_on_customer_id; @@ -389,7 +400,9 @@ DROP INDEX IF EXISTS public.index_active_charge_filter_values; DROP INDEX IF EXISTS public.idx_on_usage_threshold_id_invoice_id_cb82cdf163; DROP INDEX IF EXISTS public.idx_on_start_processing_at_external_subscription_id_31b81116ce; DROP INDEX IF EXISTS public.idx_on_organization_id_external_subscription_id_df3a30d96d; +DROP INDEX IF EXISTS public.idx_on_organization_id_deleted_at_225e3f789d; DROP INDEX IF EXISTS public.idx_on_invoice_id_payment_request_id_aa550779a4; +DROP INDEX IF EXISTS public.idx_on_invoice_custom_section_id_7edbcef7b5; DROP INDEX IF EXISTS public.idx_on_external_subscription_id_organization_id_40aa74e2eb; DROP INDEX IF EXISTS public.idx_on_dunning_campaign_id_currency_fbf233b2ae; DROP INDEX IF EXISTS public.idx_on_amount_cents_plan_id_recurring_888044d66b; @@ -423,6 +436,8 @@ ALTER TABLE IF EXISTS ONLY public.invoices_payment_requests DROP CONSTRAINT IF E ALTER TABLE IF EXISTS ONLY public.invoice_subscriptions DROP CONSTRAINT IF EXISTS invoice_subscriptions_pkey; ALTER TABLE IF EXISTS ONLY public.invoice_metadata DROP CONSTRAINT IF EXISTS invoice_metadata_pkey; ALTER TABLE IF EXISTS ONLY public.invoice_errors DROP CONSTRAINT IF EXISTS invoice_errors_pkey; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_sections DROP CONSTRAINT IF EXISTS invoice_custom_sections_pkey; +ALTER TABLE IF EXISTS ONLY public.invoice_custom_section_selections DROP CONSTRAINT IF EXISTS invoice_custom_section_selections_pkey; ALTER TABLE IF EXISTS ONLY public.invites DROP CONSTRAINT IF EXISTS invites_pkey; ALTER TABLE IF EXISTS ONLY public.integrations DROP CONSTRAINT IF EXISTS integrations_pkey; ALTER TABLE IF EXISTS ONLY public.integration_resources DROP CONSTRAINT IF EXISTS integration_resources_pkey; @@ -461,6 +476,7 @@ ALTER TABLE IF EXISTS ONLY public.billable_metrics DROP CONSTRAINT IF EXISTS bil ALTER TABLE IF EXISTS ONLY public.billable_metric_filters DROP CONSTRAINT IF EXISTS billable_metric_filters_pkey; ALTER TABLE IF EXISTS ONLY public.ar_internal_metadata DROP CONSTRAINT IF EXISTS ar_internal_metadata_pkey; ALTER TABLE IF EXISTS ONLY public.applied_usage_thresholds DROP CONSTRAINT IF EXISTS applied_usage_thresholds_pkey; +ALTER TABLE IF EXISTS ONLY public.applied_invoice_custom_sections DROP CONSTRAINT IF EXISTS applied_invoice_custom_sections_pkey; ALTER TABLE IF EXISTS ONLY public.applied_coupons DROP CONSTRAINT IF EXISTS applied_coupons_pkey; ALTER TABLE IF EXISTS ONLY public.applied_add_ons DROP CONSTRAINT IF EXISTS applied_add_ons_pkey; ALTER TABLE IF EXISTS ONLY public.api_keys DROP CONSTRAINT IF EXISTS api_keys_pkey; @@ -503,6 +519,8 @@ DROP TABLE IF EXISTS public.invoices; DROP TABLE IF EXISTS public.invoice_subscriptions; DROP TABLE IF EXISTS public.invoice_metadata; DROP TABLE IF EXISTS public.invoice_errors; +DROP TABLE IF EXISTS public.invoice_custom_sections; +DROP TABLE IF EXISTS public.invoice_custom_section_selections; DROP TABLE IF EXISTS public.invites; DROP TABLE IF EXISTS public.integrations; DROP TABLE IF EXISTS public.integration_resources; @@ -542,6 +560,7 @@ DROP TABLE IF EXISTS public.billable_metrics; DROP TABLE IF EXISTS public.billable_metric_filters; DROP TABLE IF EXISTS public.ar_internal_metadata; DROP TABLE IF EXISTS public.applied_usage_thresholds; +DROP TABLE IF EXISTS public.applied_invoice_custom_sections; DROP TABLE IF EXISTS public.applied_coupons; DROP TABLE IF EXISTS public.applied_add_ons; DROP TABLE IF EXISTS public.api_keys; @@ -552,7 +571,9 @@ DROP TABLE IF EXISTS public.active_storage_variant_records; DROP TABLE IF EXISTS public.active_storage_blobs; DROP TABLE IF EXISTS public.active_storage_attachments; DROP PROCEDURE IF EXISTS public.trigger_subscription_update(IN p_organization_id uuid, IN p_external_subscription_id character varying); +DROP TYPE IF EXISTS public.tax_status; DROP TYPE IF EXISTS public.subscription_invoicing_reason; +DROP TYPE IF EXISTS public.payment_payable_payment_status; DROP TYPE IF EXISTS public.customer_type; DROP TYPE IF EXISTS public.billable_metric_weighted_interval; DROP TYPE IF EXISTS public.billable_metric_rounding_function; @@ -624,6 +645,18 @@ CREATE TYPE public.customer_type AS ENUM ( ); +-- +-- Name: payment_payable_payment_status; Type: TYPE; Schema: public; Owner: - +-- + +CREATE TYPE public.payment_payable_payment_status AS ENUM ( + 'pending', + 'processing', + 'succeeded', + 'failed' +); + + -- -- Name: subscription_invoicing_reason; Type: TYPE; Schema: public; Owner: - -- @@ -638,6 +671,17 @@ CREATE TYPE public.subscription_invoicing_reason AS ENUM ( ); +-- +-- Name: tax_status; Type: TYPE; Schema: public; Owner: - +-- + +CREATE TYPE public.tax_status AS ENUM ( + 'pending', + 'succeeded', + 'failed' +); + + -- -- Name: trigger_subscription_update(uuid, character varying); Type: PROCEDURE; Schema: public; Owner: - -- @@ -818,6 +862,22 @@ CREATE TABLE public.applied_coupons ( ); +-- +-- Name: applied_invoice_custom_sections; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.applied_invoice_custom_sections ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + name character varying NOT NULL, + code character varying NOT NULL, + display_name character varying, + details character varying, + invoice_id uuid NOT NULL, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + -- -- Name: applied_usage_thresholds; Type: TABLE; Schema: public; Owner: - -- @@ -1222,6 +1282,7 @@ CREATE TABLE public.customers ( exclude_from_dunning_campaign boolean DEFAULT false NOT NULL, last_dunning_campaign_attempt integer DEFAULT 0 NOT NULL, last_dunning_campaign_attempt_at timestamp without time zone, + skip_invoice_custom_sections boolean DEFAULT false NOT NULL, CONSTRAINT check_customers_on_invoice_grace_period CHECK ((invoice_grace_period >= 0)), CONSTRAINT check_customers_on_net_payment_term CHECK ((net_payment_term >= 0)) ); @@ -1586,6 +1647,38 @@ CREATE TABLE public.invites ( ); +-- +-- Name: invoice_custom_section_selections; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.invoice_custom_section_selections ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + invoice_custom_section_id uuid NOT NULL, + organization_id uuid, + customer_id uuid, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: invoice_custom_sections; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.invoice_custom_sections ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + name character varying NOT NULL, + code character varying NOT NULL, + description character varying, + display_name character varying, + details character varying, + organization_id uuid NOT NULL, + deleted_at timestamp without time zone, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + -- -- Name: invoice_errors; Type: TABLE; Schema: public; Owner: - -- @@ -1676,6 +1769,7 @@ CREATE TABLE public.invoices ( payment_overdue boolean DEFAULT false, negative_amount_cents bigint DEFAULT 0 NOT NULL, progressive_billing_credit_amount_cents bigint DEFAULT 0 NOT NULL, + tax_status public.tax_status, CONSTRAINT check_organizations_on_net_payment_term CHECK ((net_payment_term >= 0)) ); @@ -1907,13 +2001,14 @@ CREATE TABLE public.payments ( payment_provider_customer_id uuid, amount_cents bigint NOT NULL, amount_currency character varying NOT NULL, - provider_payment_id character varying NOT NULL, + provider_payment_id character varying, status character varying NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, payable_type character varying DEFAULT 'Invoice'::character varying NOT NULL, payable_id uuid, - provider_payment_data jsonb DEFAULT '{}'::jsonb + provider_payment_data jsonb DEFAULT '{}'::jsonb, + payable_payment_status public.payment_payable_payment_status ); @@ -2318,6 +2413,14 @@ ALTER TABLE ONLY public.applied_coupons ADD CONSTRAINT applied_coupons_pkey PRIMARY KEY (id); +-- +-- Name: applied_invoice_custom_sections applied_invoice_custom_sections_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.applied_invoice_custom_sections + ADD CONSTRAINT applied_invoice_custom_sections_pkey PRIMARY KEY (id); + + -- -- Name: applied_usage_thresholds applied_usage_thresholds_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2622,6 +2725,22 @@ ALTER TABLE ONLY public.invites ADD CONSTRAINT invites_pkey PRIMARY KEY (id); +-- +-- Name: invoice_custom_section_selections invoice_custom_section_selections_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT invoice_custom_section_selections_pkey PRIMARY KEY (id); + + +-- +-- Name: invoice_custom_sections invoice_custom_sections_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_sections + ADD CONSTRAINT invoice_custom_sections_pkey PRIMARY KEY (id); + + -- -- Name: invoice_errors invoice_errors_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2883,6 +3002,13 @@ CREATE UNIQUE INDEX idx_on_dunning_campaign_id_currency_fbf233b2ae ON public.dun CREATE UNIQUE INDEX idx_on_external_subscription_id_organization_id_40aa74e2eb ON public.subscription_event_triggers USING btree (external_subscription_id, organization_id) WHERE (start_processing_at IS NULL); +-- +-- Name: idx_on_invoice_custom_section_id_7edbcef7b5; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_on_invoice_custom_section_id_7edbcef7b5 ON public.invoice_custom_section_selections USING btree (invoice_custom_section_id); + + -- -- Name: idx_on_invoice_id_payment_request_id_aa550779a4; Type: INDEX; Schema: public; Owner: - -- @@ -2890,6 +3016,13 @@ CREATE UNIQUE INDEX idx_on_external_subscription_id_organization_id_40aa74e2eb O CREATE UNIQUE INDEX idx_on_invoice_id_payment_request_id_aa550779a4 ON public.invoices_payment_requests USING btree (invoice_id, payment_request_id); +-- +-- Name: idx_on_organization_id_deleted_at_225e3f789d; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_on_organization_id_deleted_at_225e3f789d ON public.invoice_custom_sections USING btree (organization_id, deleted_at); + + -- -- Name: idx_on_organization_id_external_subscription_id_df3a30d96d; Type: INDEX; Schema: public; Owner: - -- @@ -3093,6 +3226,13 @@ CREATE INDEX index_applied_coupons_on_coupon_id ON public.applied_coupons USING CREATE INDEX index_applied_coupons_on_customer_id ON public.applied_coupons USING btree (customer_id); +-- +-- Name: index_applied_invoice_custom_sections_on_invoice_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_applied_invoice_custom_sections_on_invoice_id ON public.applied_invoice_custom_sections USING btree (invoice_id); + + -- -- Name: index_applied_usage_thresholds_on_invoice_id; Type: INDEX; Schema: public; Owner: - -- @@ -3975,6 +4115,34 @@ CREATE INDEX index_invites_on_organization_id ON public.invites USING btree (org CREATE UNIQUE INDEX index_invites_on_token ON public.invites USING btree (token); +-- +-- Name: index_invoice_custom_section_selections_on_customer_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_invoice_custom_section_selections_on_customer_id ON public.invoice_custom_section_selections USING btree (customer_id); + + +-- +-- Name: index_invoice_custom_section_selections_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_invoice_custom_section_selections_on_organization_id ON public.invoice_custom_section_selections USING btree (organization_id); + + +-- +-- Name: index_invoice_custom_sections_on_organization_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_invoice_custom_sections_on_organization_id ON public.invoice_custom_sections USING btree (organization_id); + + +-- +-- Name: index_invoice_custom_sections_on_organization_id_and_code; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_invoice_custom_sections_on_organization_id_and_code ON public.invoice_custom_sections USING btree (organization_id, code); + + -- -- Name: index_invoice_metadata_on_invoice_id; Type: INDEX; Schema: public; Owner: - -- @@ -4248,6 +4416,13 @@ CREATE INDEX index_payment_requests_on_organization_id ON public.payment_request CREATE INDEX index_payments_on_invoice_id ON public.payments USING btree (invoice_id); +-- +-- Name: index_payments_on_payable_id_and_payable_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_payments_on_payable_id_and_payable_type ON public.payments USING btree (payable_id, payable_type) WHERE (payable_payment_status = ANY (ARRAY['pending'::public.payment_payable_payment_status, 'processing'::public.payment_payable_payment_status])); + + -- -- Name: index_payments_on_payable_type_and_payable_id; Type: INDEX; Schema: public; Owner: - -- @@ -4676,6 +4851,14 @@ ALTER TABLE ONLY public.integration_customers ADD CONSTRAINT fk_rails_0e464363cb FOREIGN KEY (customer_id) REFERENCES public.customers(id); +-- +-- Name: applied_invoice_custom_sections fk_rails_10428ecad2; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.applied_invoice_custom_sections + ADD CONSTRAINT fk_rails_10428ecad2 FOREIGN KEY (invoice_id) REFERENCES public.invoices(id); + + -- -- Name: daily_usages fk_rails_12d29bc654; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5100,6 +5283,14 @@ ALTER TABLE ONLY public.integration_resources ADD CONSTRAINT fk_rails_67d4eb3c92 FOREIGN KEY (integration_id) REFERENCES public.integrations(id); +-- +-- Name: invoice_custom_section_selections fk_rails_6b1e3d1159; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT fk_rails_6b1e3d1159 FOREIGN KEY (organization_id) REFERENCES public.organizations(id); + + -- -- Name: dunning_campaigns fk_rails_6c720a8ccd; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5196,6 +5387,14 @@ ALTER TABLE ONLY public.adjusted_fees ADD CONSTRAINT fk_rails_7b324610ad FOREIGN KEY (charge_id) REFERENCES public.charges(id); +-- +-- Name: invoice_custom_sections fk_rails_7c0e340dbd; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_sections + ADD CONSTRAINT fk_rails_7c0e340dbd FOREIGN KEY (organization_id) REFERENCES public.organizations(id); + + -- -- Name: charge_filter_values fk_rails_7da558cadc; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5380,6 +5579,14 @@ ALTER TABLE ONLY public.credit_note_items ADD CONSTRAINT fk_rails_9f22076477 FOREIGN KEY (credit_note_id) REFERENCES public.credit_notes(id); +-- +-- Name: invoice_custom_section_selections fk_rails_9ff1d277f3; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT fk_rails_9ff1d277f3 FOREIGN KEY (invoice_custom_section_id) REFERENCES public.invoice_custom_sections(id); + + -- -- Name: group_properties fk_rails_a2d2cb3819; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5532,6 +5739,14 @@ ALTER TABLE ONLY public.invites ADD CONSTRAINT fk_rails_dd342449a6 FOREIGN KEY (organization_id) REFERENCES public.organizations(id); +-- +-- Name: invoice_custom_section_selections fk_rails_dd7e076158; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invoice_custom_section_selections + ADD CONSTRAINT fk_rails_dd7e076158 FOREIGN KEY (customer_id) REFERENCES public.customers(id); + + -- -- Name: credit_note_items fk_rails_dea748e529; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5619,6 +5834,9 @@ ALTER TABLE ONLY public.adjusted_fees SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES +('20241216140931'), +('20241216110525'), +('20241213142739'), ('20241203141040'), ('20241203140905'), ('20241203135310'), @@ -5628,6 +5846,10 @@ INSERT INTO "schema_migrations" (version) VALUES ('20241126103448'), ('20241126102447'), ('20241125194753'), +('20241122141158'), +('20241122140603'), +('20241122134430'), +('20241122111534'), ('20241122105327'), ('20241122105133'), ('20241122104537'),