From 5038c7e7a5ed4384a9b0299f2cbb019abb5caa7b Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Tue, 11 Jun 2019 09:33:45 +0200 Subject: [PATCH] fix promo code constraint, cleanup admin_reservation_request --- .../PGSQL/V201_2.0.0.3__ADD_ROW_SECURITY.sql | 11 +++++++++++ ..._2.0.0.12__FIX_PROMO_CODE_UNIQUE_INDEX.sql | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/main/resources/alfio/db/PGSQL/V202_2.0.0.12__FIX_PROMO_CODE_UNIQUE_INDEX.sql diff --git a/src/main/resources/alfio/db/PGSQL/V201_2.0.0.3__ADD_ROW_SECURITY.sql b/src/main/resources/alfio/db/PGSQL/V201_2.0.0.3__ADD_ROW_SECURITY.sql index a8b8e5a0e8..40a726ec7f 100644 --- a/src/main/resources/alfio/db/PGSQL/V201_2.0.0.3__ADD_ROW_SECURITY.sql +++ b/src/main/resources/alfio/db/PGSQL/V201_2.0.0.3__ADD_ROW_SECURITY.sql @@ -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; @@ -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); diff --git a/src/main/resources/alfio/db/PGSQL/V202_2.0.0.12__FIX_PROMO_CODE_UNIQUE_INDEX.sql b/src/main/resources/alfio/db/PGSQL/V202_2.0.0.12__FIX_PROMO_CODE_UNIQUE_INDEX.sql new file mode 100644 index 0000000000..08f0e2ad0e --- /dev/null +++ b/src/main/resources/alfio/db/PGSQL/V202_2.0.0.12__FIX_PROMO_CODE_UNIQUE_INDEX.sql @@ -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 . +-- + +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;