begin;
update menu_ref set me_menu='Catégorie fiche' where me_code='CCARD';
alter table attr_def add column ad_default_order int;
comment on column attr_def.ad_default_order is 'Default order of the attribute';








delete from attr_min where ad_id=30 and frd_id=2;
insert into attr_min (frd_id,ad_id) values (2,5);
insert into attr_min (frd_id,ad_id) values (3,5);


insert into attr_min (frd_id,ad_id) values (3,5) on conflict (frd_id ,ad_id ) do nothing;

insert into attr_min (frd_id,ad_id) values (14,9) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,12) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,14) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,16) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,17) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,18) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,24) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,26) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (14,5) on conflict (frd_id ,ad_id ) do nothing;

insert into attr_min (frd_id,ad_id) values (25,14) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (25,32) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (25,27) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (25,18) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (25,27) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (25,32) on conflict (frd_id ,ad_id ) do nothing;

insert into attr_min (frd_id,ad_id) values (13,5) on conflict (frd_id ,ad_id ) do nothing;

insert into attr_min (frd_id,ad_id) values (8,5) on conflict (frd_id ,ad_id ) do nothing;


insert into attr_min (frd_id,ad_id) values (7,5) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (7,11) on conflict (frd_id ,ad_id ) do nothing;


insert into attr_min (frd_id,ad_id) values (6,5) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (6,9) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (6,25) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (6,33) on conflict (frd_id ,ad_id ) do nothing;

delete from attr_min where frd_id =10 and ad_id =12;

insert into attr_min (frd_id,ad_id) values (10,5) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (10,9) on conflict (frd_id ,ad_id ) do nothing;

delete from attr_min where frd_id =12 and ad_id =12;

insert into attr_min (frd_id,ad_id) values (12,5) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (12,9) on conflict (frd_id ,ad_id ) do nothing;

delete from attr_min where frd_id =4 and ad_id =4;
insert into attr_min (frd_id,ad_id) values (4,5) on conflict (frd_id ,ad_id ) do nothing;
insert into attr_min (frd_id,ad_id) values (4,26) on conflict (frd_id ,ad_id ) do nothing;;

delete from attr_min where frd_id =1 and ad_id =15;
insert into attr_min (frd_id,ad_id) values (1,5) on conflict (frd_id ,ad_id ) do nothing;

insert into attr_def values (34,'Site Web','text',22,null,1,157);
insert into attr_min values(8,34), (9,34),(14,34),(4,34);

-- select 'update attr_def set ad_default_order = '||ad_default_order::text||' where ad_id='||ad_id::text||';' from attr_def ad order by ad_default_order;
update attr_def set ad_default_order = 10 where ad_id=1;
update attr_def set ad_default_order = 20 where ad_id=32;
update attr_def set ad_default_order = 30 where ad_id=9;
update attr_def set ad_default_order = 40 where ad_id=34;
update attr_def set ad_default_order = 50 where ad_id=30;
update attr_def set ad_default_order = 60 where ad_id=12;
update attr_def set ad_default_order = 70 where ad_id=25;
update attr_def set ad_default_order = 80 where ad_id=13;
update attr_def set ad_default_order = 90 where ad_id=18;
update attr_def set ad_default_order = 100 where ad_id=27;
update attr_def set ad_default_order = 110 where ad_id=17;
update attr_def set ad_default_order = 120 where ad_id=26;
update attr_def set ad_default_order = 130 where ad_id=14;
update attr_def set ad_default_order = 140 where ad_id=15;
update attr_def set ad_default_order = 150 where ad_id=16;
update attr_def set ad_default_order = 160 where ad_id=24;
update attr_def set ad_default_order = 170 where ad_id=4;
update attr_def set ad_default_order = 180 where ad_id=3;
update attr_def set ad_default_order = 190 where ad_id=5;
update attr_def set ad_default_order = 200 where ad_id=6;
update attr_def set ad_default_order = 210 where ad_id=7;
update attr_def set ad_default_order = 220 where ad_id=2;
update attr_def set ad_default_order = 230 where ad_id=8;
update attr_def set ad_default_order = 240 where ad_id=11;
update attr_def set ad_default_order = 250 where ad_id=10;
update attr_def set ad_default_order = 260 where ad_id=33;
update attr_def set ad_default_order = 270 where ad_id=19;
update attr_def set ad_default_order = 280 where ad_id=20;
update attr_def set ad_default_order = 290 where ad_id=53;
update attr_def set ad_default_order = 300 where ad_id=21;
update attr_def set ad_default_order = 310 where ad_id=51;
update attr_def set ad_default_order = 320 where ad_id=22;
update attr_def set ad_default_order = 330 where ad_id=50;
update attr_def set ad_default_order = 340 where ad_id=52;
update attr_def set ad_default_order = 350 where ad_id=31;
update attr_def set ad_default_order = 9999 where ad_id=23;



insert into version (val,v_description) values (179,'Improve Card Attribut - default order');
commit;