Friday, February 29, 2008

MysqlUtils plugin

Here's a little plugin I wrote to help with MySQL migrations. Things like foreign keys, reference tables, join tables are easy to do. This isn't really documented, but the code is pretty self explanatory. Here are a list of the methods:
  
def add_foreign_key(from_table, to_table, is_required = false)

def remove_foreign_key(from_table, to_table)

def remove_foreign_key_column(from_table, col_name)

def define_foreign_key_column(from_table, from_column, to_table, to_column = "id")

# join_table = addresses_users
# must pass in the correct order, it won't order it for you
def create_join_table(table_one, table_two, fk = true)

def drop_join_table(table_one, table_two)

# reference table is a simple table with just an id and name column
# for each table passed in it will create add a foreign key
# relationship
def create_reference_table(tname, *referenced_by)

def drop_reference_table(tname, *referenced_by)

Install by:
./script/plugin install http://stonean.googlecode.com/svn/mysql_utils/trunk

Nothing spectacular, but may be useful to someone.

0 comments: