alter table jin_role drop priv_master_resellers_users;
alter table jin_role drop priv_master_resellers_settings;
alter table jin_role drop priv_master_resellers_resprogs;
alter table jin_role drop priv_member_resell_resprogs;

drop table jin_resprog;
drop table jin_resprog_settings;
drop table jin_user_resprog;

alter table jin_product drop dlv_resprogs;

delete from jin_product where resprog_base_prod_id != 0;
alter table jin_product drop resprog_user_resprog_id;
alter table jin_product drop resprog_base_prod_id;

delete from jin_download where resprog_base_obj_id != 0;
delete from jin_ext_script where resprog_base_obj_id != 0;
delete from jin_brandpdf where resprog_base_obj_id != 0;
delete from jin_membership where resprog_base_obj_id != 0;
alter table jin_download drop resprog_base_obj_id;
alter table jin_ext_script drop resprog_base_obj_id;
alter table jin_brandpdf drop resprog_base_obj_id;
alter table jin_membership drop resprog_base_obj_id;

alter table jin_embedded_email drop comm_royalty_due;
alter table jin_embedded_email drop comm_royalty_overdue;
alter table jin_embedded_email drop comm_royalty_superoverdue;

alter table jin_role change priv_master_resellers_royalties priv_master_affiliates_royalties int(1) not null default 0;
alter table jin_role change priv_member_resell_royalties priv_member_promote_royalties int(1) not null default 0;
alter table jin_role change priv_member_resell_payroyalties priv_member_promote_payroyalties int(1) not null default 0;

# leave owner_id=0, owner_id=1
delete from jin_affinb where owner_id>1;
delete from jin_affinb_cfg where owner_id>1;
delete from jin_affinb_template where owner_id>1;
delete from jin_affprog where owner_id>1;
delete from jin_affprog_series where owner_id>1;
delete from jin_affprog_series_history where owner_id>1;
delete from jin_affprog_series_step where owner_id>1;
delete from jin_alert_cfg where owner_id>1;
delete from jin_alert_msg where owner_id>1;
delete from jin_api_user where owner_id>1;
delete from jin_ban where owner_id>1;
delete from jin_banner where owner_id>1;
delete from jin_banner_item where owner_id>1;
delete from jin_bcastnews where owner_id>1;
delete from jin_bcastnews_feeder where owner_id>1;
delete from jin_bcastnews_message where owner_id>1;
delete from jin_blogpub where owner_id>1;
delete from jin_brandpdf where owner_id>1;
delete from jin_certman where owner_id>1;
delete from jin_cloud where owner_id>1;
delete from jin_cloud_comment where owner_id>1;
delete from jin_cloud_page where owner_id>1;
delete from jin_commission where owner_id>1;
delete from jin_content_series where owner_id>1;
delete from jin_content_series_step where owner_id>1;
delete from jin_coupon where owner_id>1;
delete from jin_customtag where owner_id>1;
delete from jin_dbbackup where owner_id>1;
delete from jin_download where owner_id>1;
delete from jin_embedded_email where owner_id>1;
delete from jin_ext_script where owner_id>1;
delete from jin_followupman_series where owner_id>1;
delete from jin_followupman_series_message where owner_id>1;
delete from jin_followupman_template where owner_id>1;
delete from jin_followupman_user_series where owner_id>1;
delete from jin_form_editor where owner_id>1;
delete from jin_geoforce where owner_id>1;
delete from jin_helpticket where owner_id>1;
delete from jin_helpticket_settings where owner_id>1;
delete from jin_invitation where owner_id>1;
delete from jin_invoicepdf where owner_id>1;
delete from jin_ipn_forward where owner_id>1;
delete from jin_jvevent where owner_id>1;
delete from jin_jvevent_prod where owner_id>1;
delete from jin_jvmsub where owner_id>1;
delete from jin_lesson where owner_id>1;
delete from jin_lesson_series where owner_id>1;
delete from jin_linkdir where owner_id>1;
delete from jin_linkdir_link where owner_id>1;
delete from jin_massmail_settings where owner_id>1;
delete from jin_membership where owner_id>1;
delete from jin_merchant_settings where owner_id>1;
delete from jin_metaaff where owner_id>1;
delete from jin_order where owner_id>1;
delete from jin_oto where owner_id>1;
delete from jin_package where owner_id>1;
delete from jin_page where owner_id>1;
delete from jin_pgtxn where owner_id>1;
delete from jin_priceinc where owner_id>1;
delete from jin_product where owner_id>1;
delete from jin_promogen where owner_id>1;
delete from jin_promogen_template where owner_id>1;
delete from jin_quest where owner_id>1;
delete from jin_quest_item where owner_id>1;
delete from jin_reflink_settings where owner_id>1;
delete from jin_reminder where owner_id>1;
delete from jin_reminder_type where owner_id>1;
delete from jin_reward where owner_id>1;
delete from jin_role where owner_id>1;
delete from jin_sale where owner_id>1;
delete from jin_shipping where owner_id>1;
delete from jin_shipping_due where owner_id>1;
delete from jin_shopcart_category where owner_id>1;
delete from jin_shopcart_review where owner_id>1;
delete from jin_shopcart_settings where owner_id>1;
delete from jin_short_url where owner_id>1;
delete from jin_specprices where owner_id>1;
delete from jin_specusers where owner_id>1;
delete from jin_sponsor where owner_id>1;
delete from jin_sponsor_cfg where owner_id>1;
delete from jin_stats_report where owner_id>1;
delete from jin_style where owner_id>1;
delete from jin_supro where owner_id>1;
delete from jin_tax where owner_id>1;
delete from jin_template where owner_id>1;
delete from jin_terms where owner_id>1;
delete from jin_testimonial where owner_id>1;
delete from jin_testimonial_page where owner_id>1;
delete from jin_user where owner_id>1;
delete from jin_user_affprog where owner_id>1;
delete from jin_user_dlv where owner_id>1;
delete from jin_user_point_history where owner_id>1;
delete from jin_user_quest where owner_id>1;
delete from jin_user_role where owner_id>1;
delete from jin_video where owner_id>1;

alter table jin_affinb drop owner_id;
alter table jin_affinb_cfg drop owner_id;
alter table jin_affinb_template drop owner_id;
alter table jin_affprog drop owner_id;
alter table jin_affprog_series drop owner_id;
alter table jin_affprog_series_history drop owner_id;
alter table jin_affprog_series_step drop owner_id;
alter table jin_alert_cfg drop owner_id;
alter table jin_alert_msg drop owner_id;
alter table jin_api_user drop owner_id;
alter table jin_ban drop owner_id;
alter table jin_banner drop owner_id;
alter table jin_banner_item drop owner_id;
alter table jin_bcastnews drop owner_id;
alter table jin_bcastnews_feeder drop owner_id;
alter table jin_bcastnews_message drop owner_id;
alter table jin_blogpub drop owner_id;
alter table jin_brandpdf drop owner_id;
alter table jin_certman drop owner_id;
alter table jin_cloud drop owner_id;
alter table jin_cloud_comment drop owner_id;
alter table jin_cloud_page drop owner_id;
alter table jin_commission drop owner_id;
alter table jin_content_series drop owner_id;
alter table jin_content_series_step drop owner_id;
alter table jin_coupon drop owner_id;
alter table jin_customtag drop owner_id;
alter table jin_dbbackup drop owner_id;
alter table jin_download drop owner_id;
alter table jin_embedded_email drop owner_id;
alter table jin_ext_script drop owner_id;
alter table jin_followupman_series drop owner_id;
alter table jin_followupman_series_message drop owner_id;
alter table jin_followupman_template drop owner_id;
alter table jin_followupman_user_series drop owner_id;
alter table jin_form_editor drop owner_id;
alter table jin_geoforce drop owner_id;
alter table jin_helpticket drop owner_id;
alter table jin_helpticket_settings drop owner_id;
alter table jin_invitation drop owner_id;
alter table jin_invoicepdf drop owner_id;
alter table jin_ipn_forward drop owner_id;
alter table jin_jvevent drop owner_id;
alter table jin_jvevent_prod drop owner_id;
alter table jin_jvmsub drop owner_id;
alter table jin_lesson drop owner_id;
alter table jin_lesson_series drop owner_id;
alter table jin_linkdir drop owner_id;
alter table jin_linkdir_link drop owner_id;
alter table jin_massmail_settings drop owner_id;
alter table jin_membership drop owner_id;
alter table jin_merchant_settings drop owner_id;
alter table jin_metaaff drop owner_id;
alter table jin_order drop owner_id;
alter table jin_oto drop owner_id;
alter table jin_package drop owner_id;
alter table jin_page drop owner_id;
alter table jin_pgtxn drop owner_id;
alter table jin_priceinc drop owner_id;
alter table jin_product drop owner_id;
alter table jin_promogen drop owner_id;
alter table jin_promogen_template drop owner_id;
alter table jin_quest drop owner_id;
alter table jin_quest_item drop owner_id;
alter table jin_reflink_settings drop owner_id;
alter table jin_reminder drop owner_id;
alter table jin_reminder_type drop owner_id;
alter table jin_reward drop owner_id;
alter table jin_role drop owner_id;
alter table jin_sale drop owner_id;
alter table jin_shipping drop owner_id;
alter table jin_shipping_due drop owner_id;
alter table jin_shopcart_category drop owner_id;
alter table jin_shopcart_review drop owner_id;
alter table jin_shopcart_settings drop owner_id;
alter table jin_short_url drop owner_id;
alter table jin_specprices drop owner_id;
alter table jin_specusers drop owner_id;
alter table jin_sponsor drop owner_id;
alter table jin_sponsor_cfg drop owner_id;
alter table jin_stats_report drop owner_id;
alter table jin_style drop owner_id;
alter table jin_supro drop owner_id;
alter table jin_tax drop owner_id;
alter table jin_template drop owner_id;
alter table jin_terms drop owner_id;
alter table jin_testimonial drop owner_id;
alter table jin_testimonial_page drop owner_id;
alter table jin_user drop owner_id;
alter table jin_user_affprog drop owner_id;
alter table jin_user_dlv drop owner_id;
alter table jin_user_point_history drop owner_id;
alter table jin_user_quest drop owner_id;
alter table jin_user_role drop owner_id;
alter table jin_video drop owner_id;

alter table jin_commission add payer_user_id int(11) not null default 0 after sale_id;

delete from jin_user where ownership_id != id;
alter table jin_user drop ownership_id;

alter table jin_campaign change owner_id aff_id int(11) not null;
alter table jin_quickresell change owner_id aff_id int(11) not null;
alter table jin_pgate change owner_id user_id int(11) not null;
alter table jin_reflink change owner_id user_id int(11) not null;
alter table jin_autoresponder change owner_id user_id int(11) not null;

update jin_role set priv_member_promote_royalties=1,priv_member_promote_payroyalties=1 where id=3;

alter table jin_role add priv_auth_profile_login int(1) not null default 0 after priv_supervisor;
alter table jin_role add priv_auth_profile_merchant int(1) not null default 0 after priv_auth_profile_login;
alter table jin_role add priv_auth_profile_member int(1) not null default 0 after priv_auth_profile_merchant;
alter table jin_role add priv_auth_profile_pgates int(1) not null default 0 after priv_auth_profile_member;
alter table jin_role add priv_auth_profile_affpgates int(1) not null default 0 after priv_auth_profile_pgates;

update jin_role set priv_auth_profile_login=1,priv_auth_profile_member=1,priv_auth_profile_affpgates=1 where id=3;


create table jin_affiliate_settings
(
  id                        int(11) not null primary key,

  autoresp_me2cust_ids      varchar(255) not null default '',
  autoresp_me2refered_ids   varchar(255) not null default '',

  email_me2refered          text not null default ''
);

replace into jin_affiliate_settings select id,autoresp_me2cust_ids,autoresp_me2refered_ids,email_me2refered from jin_merchant_settings;

alter table jin_merchant_settings drop autoresp_me2cust_ids;
alter table jin_merchant_settings drop autoresp_me2refered_ids;
alter table jin_merchant_settings drop email_me2refered;

delete from zen_labelling where owner_id>1;
update zen_labelling set owner_id=0;

alter table jin_role drop limit_products;
alter table jin_role drop limit_packages;
alter table jin_role drop limit_minisites;
alter table jin_role drop limit_shopcarts;
alter table jin_role drop limit_members;
alter table jin_role drop limit_roles;
alter table jin_role drop limit_dlvuploadone;
alter table jin_role drop limit_dlvuploadall;

alter table jin_role add limit_labels varchar(255) not null default '';

alter table jin_package_product add checked int(1) not null default 0 after upsell;

alter table jin_merchant_settings add no_regbutton int(1) not null default 0;

alter table jin_sale add txn_pgate_id int(11) not null default 0 after txn_pgate_type;

alter table jin_paylog add order_id int(11) not null default 0 after type;
alter table jin_paylog add sale_id int(11) not null default 0 after order_id;
alter table jin_paylog change type type varchar(50) not null default '';

#===

alter table jin_sale add subscr_refsale int(1) not null default 0 after subscr_descr_more;
alter table jin_product drop pg_subscr_cancel_nodelay;
create index paid on jin_sale(paid,subscr_refsale);
create index subscr_id on jin_jvmsub(subscr_id);
