Skip to content
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

[15.0][MIG] google_calendar: migration script #3489

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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