Skip to content

Commit

Permalink
Merge pull request #3489 from ForgeFlow/v15_mig_google_calendar
Browse files Browse the repository at this point in the history
[15.0][MIG] google_calendar: migration script
  • Loading branch information
MiquelRForgeFlow authored Jul 28, 2022
2 parents 52cc794 + 6e78487 commit cc4ab2a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsource/modules140-150.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Module coverage 14.0 -> 15.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| google_account |Nothing to do |No DB layout changes. |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| google_calendar | | |
| google_calendar | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| google_drive | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from openupgradelib import openupgrade


def _move_credentials_from_res_users_to_google_calendar_credentials(env):
openupgrade.logged_query(
env.cr,
"""
WITH google_calendar_credentials_tmp AS (
INSERT INTO google_calendar_credentials AS cc (
calendar_rtoken, calendar_token, calendar_token_validity,
calendar_sync_token, calendar_cal_id, synchronization_stopped,
create_uid, create_date, write_uid, write_date)
SELECT u.google_calendar_rtoken, u.google_calendar_token,
u.google_calendar_token_validity, u.google_calendar_sync_token,
u.google_calendar_cal_id, FALSE, max(u.write_uid), max(u.write_date),
max(u.write_uid), max(u.write_date)
FROM res_users u
WHERE u.google_calendar_token IS NOT NULL
GROUP BY u.google_calendar_rtoken, u.google_calendar_token,
u.google_calendar_token_validity, u.google_calendar_sync_token,
u.google_calendar_cal_id
RETURNING cc.id, cc.calendar_token
)
UPDATE res_users u
SET google_cal_account_id = tmp.id
FROM google_calendar_credentials_tmp as tmp
WHERE tmp.calendar_token = u.google_calendar_token
""",
)


@openupgrade.migrate()
def migrate(env, version):
_move_credentials_from_res_users_to_google_calendar_credentials(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---Models in module 'google_calendar'---
new model google.calendar.credentials
---Fields in module 'google_calendar'---
google_calendar / google.calendar.credentials / calendar_cal_id (char) : NEW
google_calendar / google.calendar.credentials / calendar_rtoken (char) : NEW
google_calendar / google.calendar.credentials / calendar_sync_token (char) : NEW
google_calendar / google.calendar.credentials / calendar_token (char) : NEW
google_calendar / google.calendar.credentials / calendar_token_validity (datetime): NEW
google_calendar / google.calendar.credentials / synchronization_stopped (boolean): NEW
google_calendar / google.calendar.credentials / user_ids (one2many) : NEW relation: res.users, required
google_calendar / res.users / google_cal_account_id (many2one): NEW relation: google.calendar.credentials
# NOTHING TO DO: new feature

google_calendar / res.users / google_calendar_cal_id (char) : not stored anymore
google_calendar / res.users / google_calendar_cal_id (char) : now related
google_calendar / res.users / google_calendar_rtoken (char) : not stored anymore
google_calendar / res.users / google_calendar_rtoken (char) : now related
google_calendar / res.users / google_calendar_sync_token (char): not stored anymore
google_calendar / res.users / google_calendar_sync_token (char): now related
google_calendar / res.users / google_calendar_token (char) : not stored anymore
google_calendar / res.users / google_calendar_token (char) : now related
google_calendar / res.users / google_calendar_token_validity (datetime): not stored anymore
google_calendar / res.users / google_calendar_token_validity (datetime): now related
# DONE: move credentials from res_user table to google_calendar_credentials table

---XML records in module 'google_calendar'---
NEW ir.model.access: google_calendar.access_google_calendar_credentials
NEW ir.model.access: google_calendar.google_calendar_manager
DEL ir.ui.view: google_calendar.assets_backend
DEL ir.ui.view: google_calendar.qunit_mobile_suite
DEL ir.ui.view: google_calendar.qunit_suite
# NOTHING TO DO: noupdate="0" records

0 comments on commit cc4ab2a

Please sign in to comment.