-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the migration file has `should_run` defined, it is considered a repeat migration. `should_run` is called every time `migrate` is run, and if it returns true, `up` is run.
- Loading branch information
Showing
8 changed files
with
230 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
# Uncomment should_run if this is a repeat migration | ||
# def should_run(cursor): | ||
# # TODO return True if migration should run | ||
|
||
|
||
def up(cursor): | ||
cursor.execute('CREATE TABLE a_table (name TEXT)') | ||
|
||
|
||
def down(cursor): | ||
cursor.execute('DROP TABLE a_table') |
19 changes: 19 additions & 0 deletions
19
dbmigrator/tests/data/md/20170810093943_repeat_insert_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
|
||
|
||
def should_run(cursor): | ||
return os.path.exists('insert_data.txt') | ||
|
||
|
||
def up(cursor): | ||
with open('insert_data.txt') as f: | ||
data = f.read() | ||
cursor.execute('INSERT INTO a_table VALUES (%s)', (data,)) | ||
|
||
|
||
def down(cursor): | ||
with open('insert_data.txt') as f: | ||
data = f.read() | ||
cursor.execute('DELETE FROM a_table WHERE name = %s', (data,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
# Uncomment should_run if this is a repeat migration | ||
# def should_run(cursor): | ||
# # TODO return True if migration should run | ||
|
||
|
||
def up(cursor): | ||
# TODO migration code | ||
pass | ||
|
||
|
||
def down(cursor): | ||
# TODO rollback code | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters