-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] maintenance_equipment_sequence: Migration to 15.0
- Loading branch information
1 parent
53d29db
commit 9e37e98
Showing
6 changed files
with
66 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
maintenance_equipment_sequence/migrations/15.0.1.0.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2021 ForgeFlow S.L. (https://forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
def migrate(cr, version): | ||
""" | ||
Column `code` of table `maintenance_equipment` has been modified to not have duplicates | ||
and then has been copied to `serial_no` column because they have the same function and | ||
`serial_no` is the one in the core. | ||
Afterwards, column 'code' has been deleted. | ||
""" | ||
|
||
if not version: | ||
return | ||
|
||
cr.execute( | ||
""" | ||
UPDATE maintenance_equipment | ||
SET code = serial_no | ||
WHERE code IS NULL;""" | ||
) | ||
|
||
cr.execute( | ||
""" | ||
WITH cte AS | ||
( | ||
SELECT ROW_NUMBER() OVER(PARTITION BY code ORDER BY code ) AS rno, code | ||
FROM maintenance_equipment | ||
) | ||
UPDATE maintenance_equipment me | ||
SET code = me.code || '_' || me.id | ||
FROM cte | ||
WHERE cte.rno>1 AND cte.code = me.code""" | ||
) | ||
|
||
cr.execute( | ||
""" | ||
UPDATE maintenance_equipment | ||
SET serial_no = code | ||
WHERE code IS NOT NULL;""" | ||
) | ||
|
||
cr.execute( | ||
""" | ||
ALTER TABLE maintenance_equipment | ||
DROP COLUMN code;""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* Adria Gil Sorribes <adria.gil@forgeflow.com> | ||
* Núria Martín Xifré <nuria.martin@forgeflow.com> | ||
* Bernat Puig Font <bernat.puig@forgeflow.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters