-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #359 from Tecnativa/15.0-fix-event_session-migrati…
…on-scripts [15.0][OU] event_session: Migration script
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2012 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def _set_use_sessions_flag(env): | ||
"""Preset the new use_sessions flag according to existing data""" | ||
openupgrade.logged_query( | ||
env.cr, "ALTER TABLE event_type ADD COLUMN IF NOT EXISTS use_sessions BOOLEAN" | ||
) | ||
openupgrade.logged_query( | ||
env.cr, "ALTER TABLE event_event ADD COLUMN IF NOT EXISTS use_sessions BOOLEAN" | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE event_event SET use_sessions = true | ||
WHERE id in ( | ||
SELECT DISTINCT event_id FROM event_session | ||
) | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE event_type SET use_sessions = true | ||
WHERE id in ( | ||
SELECT DISTINCT event_type_id FROM event_event WHERE use_sessions | ||
) | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_set_use_sessions_flag(env) |