Last active
September 15, 2017 08:26
-
-
Save iheitlager/39d9a234af4f8acd0d96a5ba04636f34 to your computer and use it in GitHub Desktop.
data-migrator sample 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from data_migrator import models, transform | |
from data_migrator.emitters import MySQLEmitter | |
def parse_b(v): | |
if v == 'B': | |
return 'transformed_B' | |
else: | |
return v.lower() | |
class Result(models.Model): | |
id = models.IntField(pos=0) # keep id | |
uuid = models.UUIDField() # generate new uuid4 field | |
# replace NULLs and trim | |
a = models.StringField(pos=1, default='NO_NULL', max_length=5, nullable='NULL', replacement=lambda x:x.upper()) | |
# parse this field | |
b = models.StringField(pos=2, parse=parse_b, name='my_b') | |
class Meta: | |
table_name = 'new_table_name' | |
# django-esc like creating and saving of records (to a manager) | |
Result(a='my a', b='my b').objects.save() | |
if __name__ == "__main__": | |
transform.Transformer(models=[Result], emitter=MySQLEmitter).process() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment