-
-
Notifications
You must be signed in to change notification settings - Fork 8
[16.0][IMP] Add support for migration scan between repository (modules moved to new repos) #91
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
Merged
sebalix
merged 2 commits into
OCA:16.0
from
sebalix:16-support-migration-scan-between-repo
Apr 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
38 changes: 38 additions & 0 deletions
38
odoo_project_migration/migrations/16.0.1.1.0/post-migration.py
This file contains hidden or 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,38 @@ | ||
| # Copyright 2025 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
|
||
| import logging | ||
|
|
||
| from odoo import SUPERUSER_ID, api | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def migrate(cr, version): | ||
| if not version: | ||
| return | ||
| env = api.Environment(cr, SUPERUSER_ID, {}) | ||
| fix_migration_states(env) | ||
|
|
||
|
|
||
| def fix_migration_states(env): | ||
| _logger.info("Update '<odoo.project.module.migration>.state' field...") | ||
| query = """ | ||
| SELECT mig.id | ||
| FROM odoo_module_branch_migration mig | ||
| JOIN odoo_module_branch AS source | ||
| ON mig.module_branch_id=source.id | ||
| JOIN odoo_module_branch AS target | ||
| ON mig.target_module_branch_id=target.id | ||
| WHERE source.repository_branch_id IS NOT NULL | ||
| AND target.repository_branch_id IS NOT NULL | ||
| AND source.repository_id != target.repository_id; | ||
| """ | ||
| env.cr.execute(query) | ||
| mig_ids = [row[0] for row in env.cr.fetchall()] | ||
| # Recompute migration state, especially for modules moved to another repo | ||
| project_migs = env["odoo.project.module.migration"].search( | ||
| [("module_migration_id", "in", mig_ids)] | ||
| ) | ||
| env.add_to_compute(project_migs._fields["state"], project_migs) | ||
| project_migs.modified(["state"]) |
This file contains hidden or 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 hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
odoo_repository_migration/migrations/16.0.1.2.0/post-migration.py
This file contains hidden or 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,56 @@ | ||
| # Copyright 2024 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
|
||
| import logging | ||
|
|
||
| from odoo import SUPERUSER_ID, api | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def migrate(cr, version): | ||
| if not version: | ||
| return | ||
| env = api.Environment(cr, SUPERUSER_ID, {}) | ||
| fix_migration_states(env) | ||
|
|
||
|
|
||
| def fix_migration_states(env): | ||
| _logger.info("Plan a scan to fix '<odoo.module.branch.migration>.state' field...") | ||
| query = """ | ||
| SELECT mig.id | ||
| FROM odoo_module_branch_migration mig | ||
| JOIN odoo_module_branch AS source | ||
| ON mig.module_branch_id=source.id | ||
| JOIN odoo_module_branch AS target | ||
| ON mig.target_module_branch_id=target.id | ||
| WHERE source.repository_branch_id IS NOT NULL | ||
| AND target.repository_branch_id IS NOT NULL | ||
| AND source.repository_id != target.repository_id; | ||
| """ | ||
| env.cr.execute(query) | ||
| mig_ids = [row[0] for row in env.cr.fetchall()] | ||
| # Reset 'last_target_scanned_commit' to recompute 'migration_scan' | ||
| if mig_ids: | ||
| query = """ | ||
| UPDATE odoo_module_branch_migration | ||
| SET last_target_scanned_commit=NULL | ||
| WHERE id IN %s; | ||
| """ | ||
| args = (tuple(mig_ids),) | ||
| env.cr.execute(query, args) | ||
| # Reset collected migration data on modules that shouldn't have any | ||
| mbm_model = env["odoo.module.branch.migration"] | ||
| migs = mbm_model.search( | ||
| [ | ||
| ("results", "!=", False), | ||
| ("repository_id.collect_migration_data", "=", False), | ||
| ] | ||
| ) | ||
| migs.results = False | ||
| # Recompute migration state/flag, especially for modules moved to another repo | ||
| # that won't trigger a migration scan. | ||
| migs = mbm_model.search([("id", "in", mig_ids)]) | ||
| env.add_to_compute(migs._fields["state"], migs) | ||
| env.add_to_compute(migs._fields["migration_scan"], migs) | ||
| migs.modified(["state", "migration_scan"]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved_to_standarddoes it exists ?May be just
movedis enough ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, module
l10n_eu_oss(while it's not really a move, more Odoo that creates its own, and OCA needed to rename its own with suffix_oca), same forknowledgemodule, Odoo creates its own enterprise module starting from 16.0, forcing OCA to rename itdocument_knowledge.So I agree it's not really a "move" functionally speaking, it's the technical module name that has been moved only, but that highlight something we should take care during a migration.