Skip to content

Commit 1528df6

Browse files
committed
[PERF] stock: optimize migration performance by pre-creating columns
1 parent 07e26e3 commit 1528df6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

openupgrade_scripts/scripts/stock/17.0.1.1/pre-migration.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@
1313
}
1414

1515

16+
def _pre_stock_picking_picking_properties(env):
17+
"""Avoid triggering the computed method"""
18+
openupgrade.logged_query(
19+
env.cr,
20+
"""
21+
ALTER TABLE stock_picking
22+
ADD COLUMN IF NOT EXISTS picking_properties jsonb
23+
""",
24+
)
25+
26+
27+
def _pre_stock_picking_picking_properties(env):
28+
"""Avoid triggering the computed method"""
29+
openupgrade.logged_query(
30+
env.cr,
31+
"""
32+
ALTER TABLE stock_move_line
33+
ADD COLUMN IF NOT EXISTS picked boolean
34+
""",
35+
)
36+
openupgrade.logged_query(
37+
env.cr,
38+
"""
39+
UPDATE stock_move_line
40+
SET picked = True
41+
WHERE state = 'done';
42+
""",
43+
)
44+
45+
1646
def fix_move_line_quantity(env):
1747
"""
1848
v17 combines what used to be reserved_qty and qty_done.
@@ -40,4 +70,6 @@ def fix_move_line_quantity(env):
4070
def migrate(env, version):
4171
openupgrade.rename_fields(env, _field_renames)
4272
openupgrade.copy_columns(env.cr, _column_copies)
73+
_pre_stock_picking_picking_properties(env)
74+
_pre_stock_picking_picking_properties(env)
4375
fix_move_line_quantity(env)

openupgrade_scripts/scripts/stock/17.0.1.1/upgrade_analysis_work.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ stock / stock.move.line / quantity (float) : NEW ha
4545
# DONE: pre-migration
4646

4747
stock / stock.move.line / picked (boolean) : NEW hasdefault: compute
48+
# DONE: pre-migration: Pre-create the column for avoiding triggering the compute.
49+
4850
stock / stock.move.line / quant_id (many2one) : NEW relation: stock.quant
4951
stock / stock.move.line / quantity_product_uom (float) : NEW isfunction: function, stored
5052
# NOTHING TO DO
@@ -66,7 +68,11 @@ stock / stock.picking / message_main_attachment_id (many2one):
6668
stock / stock.picking / move_ids_without_package (one2many): is now stored
6769
stock / stock.picking / move_ids_without_package (one2many): not a function anymore
6870
stock / stock.picking / move_line_nosuggest_ids (one2many): DEL relation: stock.move.line
71+
# NOTHING TO DO
72+
6973
stock / stock.picking / picking_properties (properties): NEW hasdefault: compute
74+
# DONE: pre-migration: Pre-create the column for avoiding triggering the compute.
75+
7076
stock / stock.picking / rating_ids (one2many) : NEW relation: rating.rating
7177
stock / stock.picking / show_operations (boolean) : not a function anymore
7278
stock / stock.picking / show_operations (boolean) : now related

0 commit comments

Comments
 (0)