Bug 15084: DB Changes - add currency.archived and FK on aqorders.currency

See the comment for details.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2015-10-29 14:55:23 +00:00 committed by Brendan A Gallagher
parent a4013eee67
commit eceece8de2
1 changed files with 8 additions and 0 deletions

View File

@ -0,0 +1,8 @@
-- Add the new currency.archived column
alter table currency add column archived tinyint(1) default 0;
-- Set currency=NULL if empty (just in case)
update aqorders set currency=NULL where currency="";
-- Insert the missing currency and mark them as archived before adding the FK
insert into currency(currency, archived) select distinct currency, 1 from aqorders where currency not in (select currency from currency);
-- And finally add the FK
alter table aqorders add foreign key (currency) references currency(currency) on delete set null on update set null;