aboutsummaryrefslogtreecommitdiff
path: root/migrations/2015_10_14_17211444836060_create_passages_table.py
diff options
context:
space:
mode:
authorCamil Staps2015-10-14 19:40:29 +0200
committerCamil Staps2015-10-14 19:40:29 +0200
commitadddd3ff8630bb8c5fc7355bcd0d09f226353f67 (patch)
treeae26c76eb0a9d7bdc496885bba2105ae00f19e5a /migrations/2015_10_14_17211444836060_create_passages_table.py
parentOnly insert from dump when non-empty (diff)
Using Orator migrations
Diffstat (limited to 'migrations/2015_10_14_17211444836060_create_passages_table.py')
-rw-r--r--migrations/2015_10_14_17211444836060_create_passages_table.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/migrations/2015_10_14_17211444836060_create_passages_table.py b/migrations/2015_10_14_17211444836060_create_passages_table.py
new file mode 100644
index 0000000..a044dbb
--- /dev/null
+++ b/migrations/2015_10_14_17211444836060_create_passages_table.py
@@ -0,0 +1,31 @@
+from orator.migrations import Migration
+
+
+class CreatePassagesTable(Migration):
+
+ def up(self):
+ """
+ Run the migrations.
+ """
+ with self.schema.create('passages') as table:
+ table.increments('id')
+ table.string('fst_book')
+ table.small_integer('fst_chapter')
+ table.small_integer('fst_nr')
+ table.string('snd_book')
+ table.small_integer('snd_chapter')
+ table.small_integer('snd_nr')
+ table.foreign(['fst_book', 'fst_chapter', 'fst_nr'])\
+ .references(['book', 'chapter', 'nr']).on('verses')\
+ .on_delete('restrict').on_update('cascade')
+ table.foreign(['snd_book', 'snd_chapter', 'snd_nr'])\
+ .references(['book', 'chapter', 'nr']).on('verses')\
+ .on_delete('restrict').on_update('cascade')
+ table.unique(['fst_book', 'fst_chapter', 'fst_nr',
+ 'snd_book', 'snd_chapter', 'snd_nr'])
+
+ def down(self):
+ """
+ Revert the migrations.
+ """
+ self.schema.drop('passages')