Skip to content

Commit

Permalink
Merge pull request #359 from Tecnativa/15.0-fix-event_session-migrati…
Browse files Browse the repository at this point in the history
…on-scripts

[15.0][OU] event_session: Migration script
  • Loading branch information
pedrobaeza authored Jan 30, 2024
2 parents 8f6ae05 + 17180b2 commit 6e19277
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions event_session/migrations/15.0.1.0.0/pre-migration.py
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)

0 comments on commit 6e19277

Please sign in to comment.