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

Moving to bw_projects needs a migration #147

Open
cmutel opened this issue Aug 23, 2023 · 2 comments
Open

Moving to bw_projects needs a migration #147

cmutel opened this issue Aug 23, 2023 · 2 comments
Assignees

Comments

@cmutel
Copy link
Member

cmutel commented Aug 23, 2023

We need to read the old database file (probably using the builtin library and not peewee as we aren't sure about the schema) and insert the old projects into the new database.

@cmutel cmutel self-assigned this Aug 23, 2023
@cmutel
Copy link
Member Author

cmutel commented Aug 23, 2023

bw_projects uses the same database file, projects.bd, but different tables. The older version is called projectdataset, the bw_projects one is project:

Screenshot 2023-08-23 at 09 15 19

@cmutel
Copy link
Member Author

cmutel commented Aug 23, 2023

Code to get old values from SQLite database:

import pickle
import sqlite3


def process_value(data, column):
    if column == 'data':
        return pickle.loads(data)
    else:
        return data


def load_old_project_data():
    projects_db_fp = bd.projects.file_helper.dir_base_data / "projects.db"
    projects_db = sqlite3.connect(projects_db_fp)
    cursor = projects_db.cursor()

    columns = [line[0] for line in cursor.execute("SELECT name FROM pragma_table_info('projectdataset') ORDER BY cid ASC")]
    qs = list(cursor.execute("SELECT * FROM projectdataset"))

    return [
        {column: process_value(value, column) for column, value in zip(columns, line)}
        for line in qs
    ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant