Skip to content

Commit

Permalink
fix promo code constraint, cleanup admin_reservation_request
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jun 11, 2019
1 parent 2397345 commit 5038c7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ create policy a_group_access_policy on a_group to public
with check (alfio_check_row_access(organization_id_fk));
--

alter table promo_code drop constraint "unique_promo_code_for_org";
alter table promo_code drop constraint "unique_promo_code_for_event";


create unique index "unique_promo_code_for_org" on promo_code(promo_code, organization_id_fk) where event_id_fk is null;
create unique index "unique_promo_code_for_event" on promo_code(promo_code, event_id_fk) where event_id_fk is not null;
--

update promo_code set organization_id_fk = (select org_id from event where event.id = event_id_fk) where organization_id_fk is null;
alter table promo_code alter column organization_id_fk set not null;

Expand Down Expand Up @@ -197,6 +205,9 @@ create policy email_message_access_policy on email_message to public
--

-- admin_reservation_request

delete from admin_reservation_request where (select count(*) from event where event.id = event_id) = 0;

alter table admin_reservation_request add column organization_id_fk integer;
alter table admin_reservation_request add foreign key(organization_id_fk) references organization(id);
update admin_reservation_request set organization_id_fk = (select org_id from event where event.id = event_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--
-- This file is part of alf.io.
--
-- alf.io is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- alf.io is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with alf.io. If not, see <http://www.gnu.org/licenses/>.
--

create unique index if not exists "unique_promo_code_for_org" on promo_code(promo_code, organization_id_fk) where event_id_fk is null;
create unique index if not exists "unique_promo_code_for_event" on promo_code(promo_code, event_id_fk) where event_id_fk is not null;

0 comments on commit 5038c7e

Please sign in to comment.