Notice This is a beta feature offered by Google. Also this is automatic translation, which means the results are often inacurate and/or hilarious. Enjoy.

ARCHIVES /  RSS
Blog

Migrating freecomments data to Django 1.0 comments in 4 easy steps

h3  ~  28 Aug 2008, 09:00  –  post a comment

It's not quite hard but even with the good official documentation, I've ran into some pitfalls.

First thing I made was to modify my models and templates so it works with the new Django 1.0 comments system. This documentation made it quite easy.

I suggest you to checkout a copy of your site, create a development database to work with by using python manage.py syncdb. When your new comment system is working properly and freecomments are gone, you can start the migration.

1. Get the database

h3@prod: sudo mysqldump -uroot -p dbName > dbName-dd-mm-yyyy.sql

2. Load database on dev

h3@dev: scp prod-server.com:./dbName-dd-mm-yyyy.sql ~/
h3@dev: mysql -uroot -p
mysql> DROP DATABASE dbName;
mysql> CREATE DATABASE dbName;
h3@dev: mysql -uroot -p dbName < dbName-dd-mm-yyy.sql

3. Recreate new comments tables

h3@dev: python manage syncdb
Creating table django_comments
Creating table django_comment_flags
Installing index for comments.Comment model
Installing index for comments.CommentFlag model

Now that we have django_comments table and freecomment's data, we can run this SQL script provided in Django's documentation

BEGIN;

INSERT INTO django_comments
    (content_type_id, object_pk, site_id, user_name, user_email, user_url,
    comment, submit_date, ip_address, is_public, is_removed)
SELECT
    content_type_id, object_id, site_id, person_name, '', '', comment,
    submit_date, ip_address, is_public, approved
FROM comments_freecomment;

INSERT INTO django_comments
    (content_type_id, object_pk, site_id, user_id, user_name, user_email,
    user_url, comment, submit_date, ip_address, is_public, is_removed)
SELECT
    content_type_id, object_id, site_id, user_id, '', '', '', comment,
    submit_date, ip_address, is_public, is_removed
FROM comments_comment;

COMMIT;

;UPDATE django_comments SET user_name = (
;    SELECT username FROM auth_user
;    WHERE django_comments.user_id = auth_user.id
;);
;UPDATE django_comments SET user_email = (
;    SELECT email FROM auth_user
;    WHERE django_comments.user_id = auth_user.id
;);
;COMMIT;

I commented the last to update statements because I used only anonymous freecomments, running these drops the user_name fields of non-registered users.. all that is.

Also, every comments will be marked as removed so you have to update them. Notice that "is_public" as been replaced by "is_removed", don't forget to update your templates accordingly or you'll end up asking yourself why you don't see any comments.

mysql> UPDATE django_comments set is_removed=0;

After ensuring that everything works, you might want to drop deprecated tables

h3@dev: mysql -uroot -p
mysql> DROP TABLES comments_comment, comments_freecomment, \
comments_karmascore, comments_moderatordeletion, comments_userflag;

4. Deploy

Deploy your code on the production server, dump the dev database and load it into the production server et voila.

h3@dev: sudo mysqldump -uroot -p dbName > dbName-prod.sql
h3@dev: scp dbName-prod.sql prod-server.com:.
h3@prod: mysql -uroot -p
mysql> DROP DATABASE dbName;
mysql> CREATE DATABASE dbName;
h3@prod: mysql -uroot -p dbName < dbName-prod.sql

post a comment Comments

no comments :|

Copyrighted stuff .. u know.