Some of the model work done for CGP

This commit is contained in:
Eric Schultz 2021-02-08 16:33:19 -06:00 committed by Eric Schultz
parent 34627681a2
commit d27b0b66f4
6 changed files with 151 additions and 4 deletions

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
class CampaignGiftPurchase < ApplicationRecord
belongs_to :campaign
has_many :campaign_gifts, class_name: 'ModernCampaignGift'
validates :amount, presence: true
validates :campaign, presence: true
validates :campaign_gifts, length: { minimum: 1 }
end

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
class ModernCampaignGift < ApplicationRecord
include Model::Houidable
include Model::Jbuilder
include Model::Eventable
setup_houid :cgift
belongs_to :campaign_gift_purchase
belongs_to :legacy_campaign_gift, class_name: 'CampaignGift', foreign_key: :campaign_gift_id, inverse_of: :modern_campaign_gift
validates :amount, presence: true
validates :legacy_campaign_gift, presence: true
validates :campaign_gift_purchase, presence: true
end

View file

@ -0,0 +1,11 @@
class CreateCampaignGiftPurchases < ActiveRecord::Migration[6.1]
def change
create_table :campaign_gift_purchases, id: :string do |t|
t.boolean :deleted, null: false, default: false
t.integer :amount, null: false
t.references :campaign, foreign_key: true
t.timestamps
end
end
end

View file

@ -0,0 +1,12 @@
class CreateModernCampaignGifts < ActiveRecord::Migration[6.1]
def change
create_table :modern_campaign_gifts, id: :string do |t|
t.boolean :deleted, null: false, default: false
t.references :campaign_gift, null: false, foreign_key: true
t.integer :amount, null: false, default: 0
t.references :campaign_gift_purchase, type: :string, null: false, foreign_key: true
t.timestamps
end
end
end

View file

@ -398,6 +398,20 @@ CREATE SEQUENCE public.campaign_gift_options_id_seq
ALTER SEQUENCE public.campaign_gift_options_id_seq OWNED BY public.campaign_gift_options.id;
--
-- Name: campaign_gift_purchases; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.campaign_gift_purchases (
id character varying NOT NULL,
deleted boolean DEFAULT false NOT NULL,
amount integer NOT NULL,
campaign_id bigint,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
--
-- Name: campaign_gifts; Type: TABLE; Schema: public; Owner: -
--
@ -1436,6 +1450,21 @@ CREATE SEQUENCE public.miscellaneous_np_infos_id_seq
ALTER SEQUENCE public.miscellaneous_np_infos_id_seq OWNED BY public.miscellaneous_np_infos.id;
--
-- Name: modern_campaign_gifts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.modern_campaign_gifts (
id character varying NOT NULL,
deleted boolean DEFAULT false NOT NULL,
campaign_gift_id bigint NOT NULL,
amount integer DEFAULT 0 NOT NULL,
campaign_gift_purchase_id character varying NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
--
-- Name: modern_donations; Type: TABLE; Schema: public; Owner: -
--
@ -2859,6 +2888,14 @@ ALTER TABLE ONLY public.campaign_gift_options
ADD CONSTRAINT campaign_gift_options_pkey PRIMARY KEY (id);
--
-- Name: campaign_gift_purchases campaign_gift_purchases_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.campaign_gift_purchases
ADD CONSTRAINT campaign_gift_purchases_pkey PRIMARY KEY (id);
--
-- Name: campaign_gifts campaign_gifts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -3075,6 +3112,14 @@ ALTER TABLE ONLY public.miscellaneous_np_infos
ADD CONSTRAINT miscellaneous_np_infos_pkey PRIMARY KEY (id);
--
-- Name: modern_campaign_gifts modern_campaign_gifts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.modern_campaign_gifts
ADD CONSTRAINT modern_campaign_gifts_pkey PRIMARY KEY (id);
--
-- Name: modern_donations modern_donations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -3381,6 +3426,13 @@ CREATE INDEX index_activities_on_nonprofit_id ON public.activities USING btree (
CREATE INDEX index_activities_on_supporter_id ON public.activities USING btree (supporter_id);
--
-- Name: index_campaign_gift_purchases_on_campaign_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_campaign_gift_purchases_on_campaign_id ON public.campaign_gift_purchases USING btree (campaign_id);
--
-- Name: index_campaign_gifts_on_campaign_gift_option_id; Type: INDEX; Schema: public; Owner: -
--
@ -3444,6 +3496,20 @@ CREATE INDEX index_exports_on_user_id ON public.exports USING btree (user_id);
CREATE INDEX index_import_requests_on_nonprofit_id ON public.import_requests USING btree (nonprofit_id);
--
-- Name: index_modern_campaign_gifts_on_campaign_gift_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_modern_campaign_gifts_on_campaign_gift_id ON public.modern_campaign_gifts USING btree (campaign_gift_id);
--
-- Name: index_modern_campaign_gifts_on_campaign_gift_purchase_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_modern_campaign_gifts_on_campaign_gift_purchase_id ON public.modern_campaign_gifts USING btree (campaign_gift_purchase_id);
--
-- Name: index_modern_donations_on_donation_id; Type: INDEX; Schema: public; Owner: -
--
@ -3767,6 +3833,14 @@ ALTER TABLE ONLY public.ticket_to_legacy_tickets
ADD CONSTRAINT fk_rails_062cef70e7 FOREIGN KEY (ticket_id) REFERENCES public.tickets(id);
--
-- Name: modern_campaign_gifts fk_rails_0757cd7020; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.modern_campaign_gifts
ADD CONSTRAINT fk_rails_0757cd7020 FOREIGN KEY (campaign_gift_id) REFERENCES public.campaign_gifts(id);
--
-- Name: ticket_purchases fk_rails_28d2157787; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -3815,6 +3889,14 @@ ALTER TABLE ONLY public.active_storage_attachments
ADD CONSTRAINT fk_rails_c3b3935057 FOREIGN KEY (blob_id) REFERENCES public.active_storage_blobs(id);
--
-- Name: modern_campaign_gifts fk_rails_df25dd1768; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.modern_campaign_gifts
ADD CONSTRAINT fk_rails_df25dd1768 FOREIGN KEY (campaign_gift_purchase_id) REFERENCES public.campaign_gift_purchases(id);
--
-- Name: ticket_purchases fk_rails_e2eb419f70; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -3823,6 +3905,14 @@ ALTER TABLE ONLY public.ticket_purchases
ADD CONSTRAINT fk_rails_e2eb419f70 FOREIGN KEY (event_discount_id) REFERENCES public.event_discounts(id);
--
-- Name: campaign_gift_purchases fk_rails_e393cdf757; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.campaign_gift_purchases
ADD CONSTRAINT fk_rails_e393cdf757 FOREIGN KEY (campaign_id) REFERENCES public.campaigns(id);
--
-- PostgreSQL database dump complete
--
@ -4317,6 +4407,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210204172319'),
('20210204174909'),
('20210204210627'),
('20210204223643');
('20210204223643'),
('20210208211655'),
('20210208212655');

View file

@ -18,6 +18,6 @@ export interface CampaignGiftPurchase extends HoudiniObject<HouID> {
}
export type TicketPurchaseCreated = HoudiniEvent<'ticket_purchase.created', TicketPurchase>;
export type TicketPurchaseUpdated = HoudiniEvent<'ticket_purchase.updated', TicketPurchase>;
export type TicketPurchaseDeleted = HoudiniEvent<'ticket_purchase.deleted', TicketPurchase>;
export type CampaignGiftPurchaseCreated = HoudiniEvent<'campaign_gift_purchase.created', CampaignGiftPurchase>;
export type CampaignGiftPurchaseUpdated = HoudiniEvent<'campaign_gift_purchase.updated', CampaignGiftPurchase>;
export type CampaignGiftPurchaseDeleted = HoudiniEvent<'campaign_gift_purchase.deleted', CampaignGiftPurchase>;