Import: Move zerver_reaction from 'messages-000001.json' to 'realm.json'.

Also change the existing slack conversion script structure, to
include 'zerver_realm' in 'realm.json'.
This commit is contained in:
Rhea Parekh 2018-05-24 17:26:15 +05:30 committed by Tim Abbott
parent f84c9b919b
commit c79d7f1070
2 changed files with 17 additions and 14 deletions

View File

@ -539,6 +539,19 @@ def do_import_realm(import_dir: Path, subdomain: str) -> Realm:
# Import zerver_message and zerver_usermessage
import_message_data(import_dir)
# As the export of Reactions is not supported, Zulip exported
# data would not contain this field.
# However this is supported in slack importer script
if 'zerver_reaction' in data:
re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message")
re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile")
for reaction in data['zerver_reaction']:
if reaction['reaction_type'] == Reaction.REALM_EMOJI:
re_map_foreign_keys(data, 'zerver_reaction', 'emoji_code',
related_table="realmemoji", id_field=True)
update_model_ids(Reaction, data, 'zerver_reaction', 'reaction')
bulk_import_model(data, Reaction, 'zerver_reaction')
# Do attachments AFTER message data is loaded.
# TODO: de-dup how we read these json files.
fn = os.path.join(import_dir, "attachment.json")
@ -614,20 +627,6 @@ def import_message_data(import_dir: Path) -> None:
fix_bitfield_keys(data, 'zerver_usermessage', 'flags')
update_model_ids(UserMessage, data, 'zerver_usermessage', 'usermessage')
bulk_import_model(data, UserMessage, 'zerver_usermessage')
# As the export of Reactions is not supported, Zulip exported
# data would not contain this field.
# However this is supported in slack importer script
if 'zerver_reaction' in data:
re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message")
re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile")
for reaction in data['zerver_reaction']:
if reaction['reaction_type'] == Reaction.REALM_EMOJI:
re_map_foreign_keys(data, 'zerver_reaction', 'emoji_code',
related_table="realmemoji", id_field=True)
update_model_ids(Reaction, data, 'zerver_reaction', 'reaction')
bulk_import_model(data, Reaction, 'zerver_reaction')
dump_file_id += 1
def import_attachments(data: TableData) -> None:

View File

@ -829,6 +829,10 @@ def do_convert_data(slack_zip_file: str, output_dir: str, token: str, threads: i
slack_data_dir, user_list, realm_id, added_users, added_recipient, added_channels,
realm, realm['zerver_realmemoji'], domain_name)
# Move zerver_reactions to realm.json file
realm['zerver_reaction'] = message_json['zerver_reaction']
del message_json['zerver_reaction']
emoji_folder = os.path.join(output_dir, 'emoji')
os.makedirs(emoji_folder, exist_ok=True)
emoji_records = process_emojis(realm['zerver_realmemoji'], emoji_folder, emoji_url_map, threads)