maxtepkeev / architect

A set of tools which enhances ORMs written in Python with more features
Other
391 stars 57 forks source link

How to deal with already filled tables and move data from the master to children #17

Open ramusus opened 8 years ago

ramusus commented 8 years ago

I have a table with big amount of data inside. Just applied

@architect.install('partition', type='range', subtype='date', constraint='month', column='date_from')

and created triggers. But my data is still in master table. How I can move it to the children tables in the most efficient way?

I use Django framework

maxtepkeev commented 8 years ago

Yes, currently architect doesn't provide a way to transfer existing data to partitions automatically, so you have to do this by hand. Let's assume that you have a table called logs which already have some data inside and you want this table to be partitioned. These are the steps to do that:

1) Rename logs to logs_old 2) Create new empty logs table, apply architect decorator and run the partition command to create triggers 3) Move all your data from logs_old to logs and it will automatically assign data to needed partitions because triggers are already there

ramusus commented 8 years ago

I think it's a popular use case, may be it's worth to make a script for this? For example Django management command or option architect move_data

maxtepkeev commented 8 years ago

I agree, an architect command for that is a great idea, unfortunately I currently don't have time to do that, so a pull request is more than welcome.