Skip to content

Raw sql migrations #348

Answered by gi0baro
a0nguyen asked this question in Q&A
Discussion options

You must be logged in to vote

@a0nguyen you can generate an empty migration as described in the docs using the relative command

emmett migrations new -m "Some name here"

then you can use the executesql command to run whatever SQL query you prefer in the migration up and down methods, eg:

def up(self):
    # runs when migration is applied
    self.db.executesql("ALTER TABLE ...")

def down(self):
    # runs when downgraded to previous
    self.db.executesql("ALTER TABLE...")

you can also avoid to write down commands, but ensure to raise some error so it's clear migration cannot be downgraded.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by a0nguyen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants