(core) Migrate Attachments columns from marshalled blobs to JSON

Summary: Adds a migration in preparation for future work on tracking and deleting attachments. This includes a `_grist_Attachments.timeDeleted` column which isn't used yet, and changing the storage format of user columns of type `Attachments`. DocStorage now treats Attachments like RefList in general (since they use JSON), which also prompted a tiny bit of refactoring.

Test Plan: Added a migration test case showing the change in format.

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3352
This commit is contained in:
Alex Hall
2022-04-01 23:55:59 +02:00
parent 22807fce8e
commit 251d79704b
8 changed files with 42 additions and 16 deletions

View File

@@ -906,3 +906,21 @@ def migration27(tdset):
add_column('_grist_Tables_column', 'rules', 'RefList:_grist_Tables_column'),
add_column('_grist_Views_section_field', 'rules', 'RefList:_grist_Tables_column'),
])
@migration(schema_version=28)
def migration28(tdset):
doc_actions = [add_column('_grist_Attachments', 'timeDeleted', 'DateTime')]
tables = list(actions.transpose_bulk_action(tdset.all_tables["_grist_Tables"]))
columns = list(actions.transpose_bulk_action(tdset.all_tables["_grist_Tables_column"]))
for table in tables:
for col in columns:
if table.id == col.parentId and col.type == "Attachments":
# This looks like it doesn't change anything,
# but it makes DocStorage realise that the sqlType has changed
# so it converts marshalled blobs to JSON
doc_actions.append(actions.ModifyColumn(table.tableId, col.colId, {"type": "Attachments"}))
return tdset.apply_doc_actions(doc_actions)

View File

@@ -15,7 +15,7 @@ import six
import actions
SCHEMA_VERSION = 27
SCHEMA_VERSION = 28
def make_column(col_id, col_type, formula='', isFormula=False):
return {
@@ -235,6 +235,7 @@ def schema_create_actions():
make_column("fileSize", "Int"), # The size in bytes
make_column("imageHeight", "Int"), # height in pixels
make_column("imageWidth", "Int"), # width in pixels
make_column("timeDeleted", "DateTime"),
make_column("timeUploaded", "DateTime")
]),