architect icon indicating copy to clipboard operation
architect copied to clipboard

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

Open ramusus opened this issue 10 years ago • 3 comments

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

ramusus avatar Aug 08 '15 13:08 ramusus

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

maxtepkeev avatar Aug 10 '15 08:08 maxtepkeev

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

ramusus avatar Oct 01 '15 12:10 ramusus

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.

maxtepkeev avatar Oct 18 '15 17:10 maxtepkeev