sdispater / orator

The Orator ORM provides a simple yet beautiful ActiveRecord implementation.

Home Page:https://orator-orm.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use raw SQL in migrations

dapicester opened this issue · comments

I spent some time trying to figure this out, and turned out to be very simple. Unfortunately I couldn't find any documentation for this. I hope writing some doc here will help anyone else searching for this.

Using raw SQL in migrations is as simple as using Migration.get_connection().statement().

For example, to use some Postgres-specific features like text search one can do something like this:

class AddTextSearchIndex(Migration):
    def up(self):
        self.get_connection().statement('''
            CREATE INDEX ts_idx ON mytable USING GIN (to_tsvector('english', column));
        ''')

    def down(self):
        self.get_connection().statement('''
            DROP INDEX ts_idx;
        ''')