Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] update script by adding missing 'IF NOT EXISTS' condition to av… #4727

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/account/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def compute_balance_for_draft_invoice_lines(env):
def migration_voucher_moves(env):
openupgrade.logged_query(
env.cr,
"ALTER TABLE account_voucher ADD COLUMN "
"ALTER TABLE account_voucher ADD COLUMN IF NOT EXISTS "
"IF NOT EXISTS message_main_attachment_id int4"
)
openupgrade.logged_query(
Expand Down
22 changes: 11 additions & 11 deletions addons/account/migrations/13.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def create_account_invoice_amount_tax_company_signed(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_invoice
ADD COLUMN amount_tax_company_signed numeric"""
ADD COLUMN IF NOT EXISTS amount_tax_company_signed numeric"""
)
openupgrade.logged_query(
env.cr, """
Expand Down Expand Up @@ -150,7 +150,7 @@ def create_account_move_new_columns(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE {table}
ADD COLUMN {column} {column_type}""".format(
ADD COLUMN IF NOT EXISTS {column} {column_type}""".format(
table=table, column=column, column_type=column_type
),
)
Expand All @@ -161,8 +161,8 @@ def fill_account_move_line(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_move_line
ADD COLUMN parent_state varchar,
ADD COLUMN account_internal_type varchar""",
ADD COLUMN IF NOT EXISTS parent_state varchar,
ADD COLUMN IF NOT EXISTS account_internal_type varchar""",
)
openupgrade.logged_query(
env.cr, """
Expand All @@ -183,7 +183,7 @@ def create_res_partner_ranks(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE res_partner
ADD COLUMN customer_rank integer
ADD COLUMN IF NOT EXISTS customer_rank integer
DEFAULT 0""",
)
openupgrade.logged_query(
Expand All @@ -193,7 +193,7 @@ def create_res_partner_ranks(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE res_partner
ADD COLUMN supplier_rank integer
ADD COLUMN IF NOT EXISTS supplier_rank integer
DEFAULT 0""",
)
openupgrade.logged_query(
Expand Down Expand Up @@ -248,7 +248,7 @@ def add_helper_invoice_move_rel(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_move
ADD COLUMN old_invoice_id integer""",
ADD COLUMN IF NOT EXISTS old_invoice_id integer""",
)
openupgrade.logged_query(
env.cr, """
Expand Down Expand Up @@ -277,12 +277,12 @@ def add_helper_invoice_move_rel(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_move_line
ADD COLUMN old_invoice_line_id integer""",
ADD COLUMN IF NOT EXISTS old_invoice_line_id integer""",
)
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_move_line
ADD COLUMN old_invoice_tax_id integer""",
ADD COLUMN IF NOT EXISTS old_invoice_tax_id integer""",
)
# Create index for these columns, as they are going to be accessed frequently
for table, field in [
Expand All @@ -298,7 +298,7 @@ def add_helper_voucher_move_rel(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_move
ADD COLUMN old_voucher_id integer""",
ADD COLUMN IF NOT EXISTS old_voucher_id integer""",
)
openupgrade.logged_query(
env.cr, """
Expand All @@ -311,7 +311,7 @@ def add_helper_voucher_move_rel(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE account_move_line
ADD COLUMN old_voucher_line_id integer""",
ADD COLUMN IF NOT EXISTS old_voucher_line_id integer""",
)


Expand Down
2 changes: 1 addition & 1 deletion addons/crm/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _auto_init(self):
@api.model
def _read_group_stage_ids(self, stages, domain, order):
# retrieve team_id from the context and write the domain
# - ('id', 'in', stages.ids): add columns that should be present
# - ('id', 'in', stages.ids): ADD COLUMN IF NOT EXISTSs that should be present
# - OR ('fold', '=', False): add default columns that are not folded
# - OR ('team_ids', '=', team_id), ('fold', '=', False) if team_id: add team columns that are not folded
team_id = self._context.get('default_team_id')
Expand Down
2 changes: 1 addition & 1 deletion addons/crm_iap_lead/migrations/13.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def fix_crm_reveal_rule_contact_filter_type(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE crm_reveal_rule
ADD COLUMN contact_filter_type varchar""",
ADD COLUMN IF NOT EXISTS contact_filter_type varchar""",
)
openupgrade.logged_query(
env.cr, """
Expand Down
2 changes: 1 addition & 1 deletion addons/im_livechat/migrations/13.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fill_mail_channel_livechat_operator_id(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE mail_channel
ADD COLUMN livechat_operator_id integer""",
ADD COLUMN IF NOT EXISTS livechat_operator_id integer""",
)
openupgrade.logged_query(
env.cr, """
Expand Down
6 changes: 3 additions & 3 deletions addons/mrp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def _pre_init_mrp(cr):
- Also set the default value for unit_factor in the same UPDATE query to save some SQL constraint checks"""
# Openupgrade: the following lines will generate an errors, when running
# openupgrade_records.
# cr.execute("""ALTER TABLE "stock_move" ADD COLUMN "unit_factor" float;""")
# cr.execute("""ALTER TABLE "stock_move" ADD COLUMN "is_done" bool;""")
# cr.execute("""ALTER TABLE "stock_move_line" ADD COLUMN "done_move" bool;""")
# cr.execute("""ALTER TABLE "stock_move" ADD COLUMN IF NOT EXISTS "unit_factor" float;""")
# cr.execute("""ALTER TABLE "stock_move" ADD COLUMN IF NOT EXISTS "is_done" bool;""")
# cr.execute("""ALTER TABLE "stock_move_line" ADD COLUMN IF NOT EXISTS "done_move" bool;""")
# cr.execute("""UPDATE stock_move
# SET is_done=COALESCE(state in ('done', 'cancel'), FALSE),
# unit_factor=1.0;""")
Expand Down
6 changes: 3 additions & 3 deletions addons/mrp/migrations/13.0.2.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def fast_precreation_and_fill_mrp_bom_byproduct(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE mrp_bom_byproduct
ADD COLUMN company_id integer""",
ADD COLUMN IF NOT EXISTS company_id integer""",
)
openupgrade.logged_query(
env.cr, """
ALTER TABLE mrp_bom_byproduct
ADD COLUMN routing_id integer""",
ADD COLUMN IF NOT EXISTS routing_id integer""",
)
openupgrade.logged_query(
env.cr, """
Expand All @@ -63,7 +63,7 @@ def fast_precreation_and_fill_mrp_bom_line(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE mrp_bom_line
ADD COLUMN company_id integer""",
ADD COLUMN IF NOT EXISTS company_id integer""",
)
openupgrade.logged_query(
env.cr, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_pos_payment_methods(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE pos_payment_method
ADD COLUMN old_journal_id int"""
ADD COLUMN IF NOT EXISTS old_journal_id int"""
)
env.cr.execute("""
SELECT DISTINCT journal_id
Expand Down
6 changes: 3 additions & 3 deletions addons/product/migrations/13.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def calculate_product_product_combination_indices(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE product_product
ADD COLUMN combination_indices varchar""",
ADD COLUMN IF NOT EXISTS combination_indices varchar""",
)
openupgrade.logged_query(
env.cr, """
Expand Down Expand Up @@ -222,7 +222,7 @@ def fill_product_template_attribute_value_attribute_line_id(env):
openupgrade.logged_query(
env.cr,
"ALTER TABLE product_template_attribute_value "
"ADD COLUMN attribute_line_id INT4",
"ADD COLUMN IF NOT EXISTS attribute_line_id INT4",
)
openupgrade.logged_query(
env.cr, """
Expand All @@ -244,7 +244,7 @@ def fill_product_template_attribute_value__attribute_id_related(env):
openupgrade.logged_query(
env.cr,
"ALTER TABLE product_template_attribute_value "
"ADD COLUMN attribute_id INT4",
"ADD COLUMN IF NOT EXISTS attribute_id INT4",
)
openupgrade.logged_query(
env.cr, """
Expand Down
2 changes: 1 addition & 1 deletion addons/purchase/migrations/13.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def migrate(env, version):
openupgrade.logged_query(
env.cr, """
ALTER TABLE purchase_order_line
ADD COLUMN qty_received_method varchar""",
ADD COLUMN IF NOT EXISTS qty_received_method varchar""",
)
# Add temporary table for avoiding the automatic launch of the compute method
openupgrade.logged_query(
Expand Down
2 changes: 1 addition & 1 deletion addons/stock_account/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def generate_stock_valuation_layer(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE stock_valuation_layer
ADD COLUMN old_product_price_history_id integer""",
ADD COLUMN IF NOT EXISTS old_product_price_history_id integer""",
)
company_obj = env["res.company"]
product_obj = env["product.product"]
Expand Down
4 changes: 2 additions & 2 deletions addons/survey/migrations/13.0.3.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def add_helper_survey_question_page_rel(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE survey_question
ADD COLUMN old_page_id integer""",
ADD COLUMN IF NOT EXISTS old_page_id integer""",
)


Expand All @@ -70,7 +70,7 @@ def fill_survey_user_input_line_question_sequence(env):
openupgrade.logged_query(
env.cr, """
ALTER TABLE survey_user_input_line
ADD COLUMN question_sequence integer""",
ADD COLUMN IF NOT EXISTS question_sequence integer""",
)
openupgrade.logged_query(
env.cr, """
Expand Down
2 changes: 1 addition & 1 deletion addons/website/migrations/13.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def fill_website_rewrite_name(cr):
openupgrade.logged_query(
cr, """
ALTER TABLE website_rewrite
ADD COLUMN name varchar""",
ADD COLUMN IF NOT EXISTS name varchar""",
)
openupgrade.logged_query(
cr, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def fill_slide_sequence(env):

def convert_slide_categories(env):
openupgrade.logged_query(
env.cr, "ALTER TABLE slide_slide ADD COLUMN old_category_id int4"
env.cr, "ALTER TABLE slide_slide ADD COLUMN IF NOT EXISTS old_category_id int4"
)
openupgrade.logged_query(
env.cr, sql.SQL("""
Expand Down
2 changes: 1 addition & 1 deletion addons/website_slides/migrations/13.0.2.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def migrate(env, version):
openupgrade.rename_columns(env.cr, _column_renames)
openupgrade.copy_columns(env.cr, _column_copies)
openupgrade.rename_fields(env, _field_renames)
openupgrade.logged_query(env.cr, "ALTER TABLE slide_slide ADD COLUMN category_id int4")
openupgrade.logged_query(env.cr, "ALTER TABLE slide_slide ADD COLUMN IF NOT EXISTS category_id int4")
openupgrade.rename_tables(env.cr, [("rel_channel_groups", "res_groups_slide_channel_rel")])
openupgrade.set_xml_ids_noupdate_value(
env,
Expand Down
4 changes: 2 additions & 2 deletions odoo/tools/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def column_exists(cr, tablename, columnname):
def create_column(cr, tablename, columnname, columntype, comment=None):
""" Create a column with the given type. """
coldefault = (columntype.upper()=='BOOLEAN') and 'DEFAULT false' or ''
cr.execute('ALTER TABLE "{}" ADD COLUMN "{}" {} {}'.format(tablename, columnname, columntype, coldefault))
cr.execute('ALTER TABLE "{}" ADD COLUMN IF NOT EXISTS "{}" {} {}'.format(tablename, columnname, columntype, coldefault))
if comment:
cr.execute('COMMENT ON COLUMN "{}"."{}" IS %s'.format(tablename, columnname), (comment,))
_schema.debug("Table %r: added column %r of type %s", tablename, columnname, columntype)
Expand All @@ -97,7 +97,7 @@ def convert_column(cr, tablename, columnname, columntype):
# can't do inplace change -> use a casted temp column
query = '''
ALTER TABLE "{0}" RENAME COLUMN "{1}" TO __temp_type_cast;
ALTER TABLE "{0}" ADD COLUMN "{1}" {2};
ALTER TABLE "{0}" ADD COLUMN IF NOT EXISTS "{1}" {2};
UPDATE "{0}" SET "{1}"= __temp_type_cast::{2};
ALTER TABLE "{0}" DROP COLUMN __temp_type_cast CASCADE;
'''
Expand Down
Loading