heavy refactoring

53 views
Skip to first unread message

Mike Dewhirst

unread,
Jun 9, 2015, 4:09:56 AM6/9/15
to django...@googlegroups.com
With Django 1.7 and Postgres I want to change the name of an app.

From my initial investigation it looks like I need to create a new app
with the desired name and then blow the old one away after pumping the
data across.

Then comes the refactoring.

At the moment I just use a vanilla text editor (Textpad) on Windows.
However, based on my observation of the occasional IDE wars on this list
I have lately been toying with the idea of teaching myself to use PyCharm.

Does anyone have any experience with app-renames and maybe some
refactoring advice for me?

Maybe I don't even need to replace and destroy ...

Thanks

Mike

Erik Cederstrand

unread,
Jun 9, 2015, 4:44:33 AM6/9/15
to Django Users

> Den 09/06/2015 kl. 10.09 skrev Mike Dewhirst <mi...@dewhirst.com.au>:
>
> Does anyone have any experience with app-renames and maybe some refactoring advice for me?
>
> Maybe I don't even need to replace and destroy ...

If you wanted, you could set Meta.db_table for all models to the current table name. Then you shouldn't need to migrate any data. In your Python code, simply rename the directory and everything referencing the app, and you should be good to go, unless your code contains too much clever magic.

I can't remember if Django migrations detect table renames. If not, and you want to rename the tables too, just issue raw "ALTER TABLE name RENAME TO new_name" SQL in an empty migration.

Erik

Mike Dewhirst

unread,
Jun 9, 2015, 4:52:25 AM6/9/15
to django...@googlegroups.com
On 9/06/2015 6:43 PM, Erik Cederstrand wrote:
>
>> Den 09/06/2015 kl. 10.09 skrev Mike Dewhirst
>> <mi...@dewhirst.com.au>:
>>
>> Does anyone have any experience with app-renames and maybe some
>> refactoring advice for me?
>>
>> Maybe I don't even need to replace and destroy ...
>
> If you wanted, you could set Meta.db_table for all models to the
> current table name. Then you shouldn't need to migrate any data. In
> your Python code, simply rename the directory and everything
> referencing the app, and you should be good to go, unless your code
> contains too much clever magic.

Not clever enough.

>
> I can't remember if Django migrations detect table renames. If not,
> and you want to rename the tables too, just issue raw "ALTER TABLE
> name RENAME TO new_name" SQL in an empty migration.

Many thanks Erik

Mike

>
> Erik
>

Andre Avorio

unread,
Jun 11, 2015, 7:34:23 AM6/11/15
to django...@googlegroups.com
Hi Mike,

I had the exact same problem and after investigating I ended up creating a new app from scratch and porting the code and data across. I don't remember finding any specific documentation on this on Django's website. Did I miss something, or should we consider adding a couple of notes on that?

a.

Mike Dewhirst

unread,
Jun 11, 2015, 8:57:29 AM6/11/15
to django...@googlegroups.com
On 11/06/2015 6:02 PM, Andre Avorio wrote:
> Hi Mike,
>
> I had the exact same problem and after investigating I ended up creating
> a new app from scratch and porting the code and data across. I don't
> remember finding any specific documentation on this on Django's website.
> Did I miss something, or should we consider adding a couple of notes on
> that?

Andre

I looked into Erik's suggestion but eventually decided to do exactly
what you did. Just finished and it all seems to be working except for a
m2m relationship which is currently eluding me. It will sort itself out
though.

I'm a big believer in refactoring so the apps, table names and column
names closely match the real world. It might be a good idea to document
replacing the app as a realistic approach to such refactoring.

It will be a week or two before I can think about that. I have a severe
deadline approaching.

What are your thoughts?

Mike


>
> a.
>
>
>
> On Tuesday, 9 June 2015 09:09:56 UTC+1, Mike Dewhirst wrote:
>
> With Django 1.7 and Postgres I want to change the name of an app.
>
> From my initial investigation it looks like I need to create a new
> app
> with the desired name and then blow the old one away after pumping the
> data across.
>
> Then comes the refactoring.
>
> At the moment I just use a vanilla text editor (Textpad) on Windows.
> However, based on my observation of the occasional IDE wars on this
> list
> I have lately been toying with the idea of teaching myself to use
> PyCharm.
>
> Does anyone have any experience with app-renames and maybe some
> refactoring advice for me?
>
> Maybe I don't even need to replace and destroy ...
>
> Thanks
>
> Mike
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e2d5c903-cdcc-418e-b18e-3f43244439ec%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e2d5c903-cdcc-418e-b18e-3f43244439ec%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages