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')