Massage the Tables

by John Samuel Anderson last modified Feb 22, 2009 07:55 AM
Adjust the database tables that ContentMirror created so that they are usable by Django.

Massage the ContentMirror tables

Short-cut: Just use this file: Massage ContentMirror Tables for Django

For each of the ContentMirror tables, there must be an ID field that has unique values, in order for Django to use the data.

Tables affected in this attempt:

  • atbtreefolder
  • atdocument
  • atevent
  • atfavorite
  • atfile
  • atfolder
  • atimage
  • atlink
  • atnewsitem
  • files
  • relations

So, repeat these steps for almost all of the tables (excluding Content, which has ID built-in), replacing sometable with the actual table name.

  1. Create a sequence to be used by the new ID field.
    CREATE SEQUENCE sometable_id_seq;
  2. Add the ID field to the table.
    ALTER TABLE sometable ADD id INT UNIQUE;
  3. Make the ID field auto-increment.
    ALTER TABLE sometable ALTER COLUMN id SET DEFAULT NEXTVAL('sometable_id_seq');
  4. Update the data values in the ID field.
    UPDATE sometable SET id = NEXTVAL('sometable_id_seq');

Steps taken from this blog post:
http://pointbeing.net/weblog/2008/03/mysql-versus-postgresql-adding-an-auto-increment-column-to-a-table.html