Exemplo n.º 1
0
 def test_multiple_migration_dry_run(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'second-run')
     self.settings['directory'] = fixtures_path
     self.settings['dry_run'] = True
     mariposa = DBMigrate(**self.settings)
     self.assertEqual(
         mariposa.migrate(),
         ("sql: -- start filename: 20120115075349-create-user-table.sql "
          "sha1: 0187aa5e13e268fc621c894a7ac4345579cf50b7\n"
          "-- intentionally making this imperfect so it can be migrated\n"
          "CREATE TABLE users (\n"
          "  id int PRIMARY KEY,\n"
          "  name varchar(255),\n"
          "  password_sha1 varchar(40)\n"
          ");\n"
          "INSERT INTO dbmigration (filename, sha1, date) VALUES ("
          "'20120115075349-create-user-table.sql', "
          "'0187aa5e13e268fc621c894a7ac4345579cf50b7', "
          "%(date_func)s());\n"
          "sql: -- start filename: 20120603133552-awesome.sql sha1: "
          "6759512e1e29b60a82b4a5587c5ea18e06b7d381\n"
          "ALTER TABLE users ADD COLUMN email varchar(70);\n"
          "INSERT INTO dbmigration (filename, sha1, date) VALUES ("
          "'20120603133552-awesome.sql', "
          "'6759512e1e29b60a82b4a5587c5ea18e06b7d381', %(date_func)s());" %
          {
              'date_func': mariposa.engine.date_func
          }))
Exemplo n.º 2
0
 def test_multiple_migration_dry_run(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'second-run')
     self.settings['directory'] = fixtures_path
     self.settings['dry_run'] = True
     mariposa = DBMigrate(**self.settings)
     self.assertEqual(mariposa.migrate(), (
         "sql: -- start filename: 20120115075349-create-user-table.sql "
         "sha1: 0187aa5e13e268fc621c894a7ac4345579cf50b7\n"
         "-- intentionally making this imperfect so it can be migrated\n"
         "CREATE TABLE users (\n"
         "  id int PRIMARY KEY,\n"
         "  name varchar(255),\n"
         "  password_sha1 varchar(40)\n"
         ");\n"
         "INSERT INTO dbmigration (filename, sha1, date) VALUES ("
         "'20120115075349-create-user-table.sql', "
         "'0187aa5e13e268fc621c894a7ac4345579cf50b7', "
         "%(date_func)s());\n"
         "sql: -- start filename: 20120603133552-awesome.sql sha1: "
         "6759512e1e29b60a82b4a5587c5ea18e06b7d381\n"
         "ALTER TABLE users ADD COLUMN email varchar(70);\n"
         "INSERT INTO dbmigration (filename, sha1, date) VALUES ("
         "'20120603133552-awesome.sql', "
         "'6759512e1e29b60a82b4a5587c5ea18e06b7d381', %(date_func)s());" %
         {'date_func': mariposa.engine.date_func}))
Exemplo n.º 3
0
 def test_create(self):
     self.settings['directory'] = '/tmp'
     mariposa = DBMigrate(**self.settings)
     fake_file = FakeFile()
     mariposa.create('test slug', 'sql', fake_file)
     self.assert_(fake_file.filename.startswith('/tmp'))
     self.assert_(fake_file.filename.endswith('test-slug.sql'))
     self.assertEqual(fake_file.contents, '-- add your migration here')
Exemplo n.º 4
0
 def test_null_migration_after_successful_migration(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'initial')
     self.settings['directory'] = fixtures_path
     self.settings['out_of_order'] = False
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.migrate()
Exemplo n.º 5
0
 def test_null_migration_after_successful_migration(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'initial')
     self.settings['directory'] = fixtures_path
     self.settings['out_of_order'] = False
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.migrate()
Exemplo n.º 6
0
 def test_create(self):
     self.settings['directory'] = '/tmp'
     mariposa = DBMigrate(**self.settings)
     fake_file = FakeFile()
     mariposa.create('test slug', 'sql', fake_file)
     self.assert_(fake_file.filename.startswith('/tmp'))
     self.assert_(fake_file.filename.endswith('test-slug.sql'))
     self.assertEqual(fake_file.contents, '-- add your migration here')
Exemplo n.º 7
0
 def test_current_migrations(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'initial')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     self.assertEqual(mariposa.current_migrations(),
                      [('20120115075349-create-user-table.sql',
                        '0187aa5e13e268fc621c894a7ac4345579cf50b7')])
Exemplo n.º 8
0
 def test_failing_script_migration(self):
     self.settings['directory'] = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'arbitrary-scripts-failing')
     mariposa = DBMigrate(**self.settings)
     try:
         mariposa.migrate()
         self.fail('Expected the script to fail')
     except subprocess.CalledProcessError as e:
         self.assert_('20121019152409-script.sh' in str(e))
Exemplo n.º 9
0
 def test_initial_migration(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'initial')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     # since the database is in memory we need to reach in to get it
     self.assertEqual(mariposa.engine.performed_migrations(),
                      [('20120115075349-create-user-table.sql',
                        '0187aa5e13e268fc621c894a7ac4345579cf50b7')])
Exemplo n.º 10
0
 def test_failing_script_migration(self):
     self.settings['directory'] = os.path.join(os.path.dirname(__file__),
                                               'fixtures',
                                               'arbitrary-scripts-failing')
     mariposa = DBMigrate(**self.settings)
     try:
         mariposa.migrate()
         self.fail('Expected the script to fail')
     except subprocess.CalledProcessError as e:
         self.assert_('20121019152409-script.sh' in str(e))
Exemplo n.º 11
0
 def test_current_migrations(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'initial')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     self.assertEqual(
         mariposa.current_migrations(), [(
             '20120115075349-create-user-table.sql',
             '0187aa5e13e268fc621c894a7ac4345579cf50b7'
         )])
Exemplo n.º 12
0
 def test_initial_migration(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'initial')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     # since the database is in memory we need to reach in to get it
     self.assertEqual(
         mariposa.engine.performed_migrations(), [(
             '20120115075349-create-user-table.sql',
             '0187aa5e13e268fc621c894a7ac4345579cf50b7'
         )])
Exemplo n.º 13
0
 def test_passing_script_migration(self):
     self.settings['directory'] = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'arbitrary-scripts')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     self.assertEqual(
         mariposa.engine.performed_migrations(),
         [('20121019152404-initial.sql',
           '4205e6d2f0c0f141098ccf8b56e04ed2e9da3f92'),
          ('20121019152409-script.sh',
           '837a6ab019646fae8488048e20ff2651437b2fbd'),
          ('20121019152412-final.sql',
           '4205e6d2f0c0f141098ccf8b56e04ed2e9da3f92')])
Exemplo n.º 14
0
 def test_passing_script_migration(self):
     self.settings['directory'] = os.path.join(os.path.dirname(__file__),
                                               'fixtures',
                                               'arbitrary-scripts')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     self.assertEqual(mariposa.engine.performed_migrations(),
                      [('20121019152404-initial.sql',
                        '4205e6d2f0c0f141098ccf8b56e04ed2e9da3f92'),
                       ('20121019152409-script.sh',
                        '837a6ab019646fae8488048e20ff2651437b2fbd'),
                       ('20121019152412-final.sql',
                        '4205e6d2f0c0f141098ccf8b56e04ed2e9da3f92')])
Exemplo n.º 15
0
 def test_null_dry_run_migration(self):
     self.settings['directory'] = os.path.join(os.path.dirname(__file__),
                                               'fixtures', 'second-run')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     self.settings['dry_run'] = True
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
Exemplo n.º 16
0
 def test_ignore_filenames_sha1_migration(self):
     self.settings['directory'] = os.path.join(os.path.dirname(__file__),
                                               'fixtures', 'sha1-update-1')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(os.path.dirname(__file__),
                                       'fixtures', 'sha1-update-2')
     mariposa.renamed()
     mariposa.migrate()
     self.assertEqual(
         mariposa.engine.performed_migrations(),
         [('20120115075300-add-another-test-table-renamed-reordered.sql',
           '4aebd2514665effff5105ad568a4fbe62f567087'),
          ('20120115075349-create-user-table.sql',
           '0187aa5e13e268fc621c894a7ac4345579cf50b7')])
Exemplo n.º 17
0
 def test_dry_run_migration(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'initial')
     self.settings['directory'] = fixtures_path
     self.settings['dry_run'] = True
     mariposa = DBMigrate(**self.settings)
     self.assertEqual(mariposa.migrate(), (
         "sql: -- start filename: 20120115075349-create-user-table.sql "
         "sha1: 0187aa5e13e268fc621c894a7ac4345579cf50b7\n"
         "-- intentionally making this imperfect so it can be migrated\n"
         "CREATE TABLE users (\n"
         "  id int PRIMARY KEY,\n"
         "  name varchar(255),\n"
         "  password_sha1 varchar(40)\n"
         ");\n"
         "INSERT INTO dbmigration (filename, sha1, date) VALUES ("
         "'20120115075349-create-user-table.sql', "
         "'0187aa5e13e268fc621c894a7ac4345579cf50b7', %s());" %
         mariposa.engine.date_func))
Exemplo n.º 18
0
 def test_dry_run_migration(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'initial')
     self.settings['directory'] = fixtures_path
     self.settings['dry_run'] = True
     mariposa = DBMigrate(**self.settings)
     self.assertEqual(
         mariposa.migrate(),
         ("sql: -- start filename: 20120115075349-create-user-table.sql "
          "sha1: 0187aa5e13e268fc621c894a7ac4345579cf50b7\n"
          "-- intentionally making this imperfect so it can be migrated\n"
          "CREATE TABLE users (\n"
          "  id int PRIMARY KEY,\n"
          "  name varchar(255),\n"
          "  password_sha1 varchar(40)\n"
          ");\n"
          "INSERT INTO dbmigration (filename, sha1, date) VALUES ("
          "'20120115075349-create-user-table.sql', "
          "'0187aa5e13e268fc621c894a7ac4345579cf50b7', %s());" %
          mariposa.engine.date_func))
Exemplo n.º 19
0
 def test_null_dry_run_migration(self):
     self.settings['directory'] = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'second-run')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     self.settings['dry_run'] = True
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
Exemplo n.º 20
0
 def test_ignore_filenames_sha1_migration(self):
     self.settings['directory'] = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'sha1-update-1')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'sha1-update-2')
     mariposa.renamed()
     mariposa.migrate()
     self.assertEqual(
         mariposa.engine.performed_migrations(),
         [('20120115075300-add-another-test-table-renamed-reordered.sql',
           '4aebd2514665effff5105ad568a4fbe62f567087'),
          ('20120115075349-create-user-table.sql',
           '0187aa5e13e268fc621c894a7ac4345579cf50b7')])
Exemplo n.º 21
0
 def test_multiple_migrations(self):
     self.settings['directory'] = os.path.join(os.path.dirname(__file__),
                                               'fixtures', 'initial')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(os.path.dirname(__file__),
                                       'fixtures', 'second-run')
     mariposa.migrate()
     self.assertEqual(mariposa.engine.performed_migrations(),
                      [('20120115075349-create-user-table.sql',
                        '0187aa5e13e268fc621c894a7ac4345579cf50b7'),
                       ('20120603133552-awesome.sql',
                        '6759512e1e29b60a82b4a5587c5ea18e06b7d381')])
Exemplo n.º 22
0
 def test_out_of_order_migration(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'out-of-order-1')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(os.path.dirname(__file__),
                                       'fixtures', 'out-of-order-2')
     try:
         mariposa.migrate()
         self.fail('Expected an OutOfOrder exception')
     except OutOfOrderException as e:
         self.assertEqual(str(e),
                          ('[20120114221757-before-initial.sql] '
                           'older than the latest performed migration'))
Exemplo n.º 23
0
 def test_allowed_out_of_order_migration(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'out-of-order-1')
     self.settings['directory'] = fixtures_path
     self.settings['out_of_order'] = True
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(os.path.dirname(__file__),
                                       'fixtures', 'out-of-order-2')
     mariposa.migrate()
     self.assertEqual(mariposa.engine.performed_migrations(),
                      [('20120114221757-before-initial.sql',
                        'c7fc17564f24f7b960e9ef3f6f9130203cc87dc9'),
                       ('20120115221757-initial.sql',
                        '841ea60d649264965a3e8c8a955fd7aad54dad3e')])
Exemplo n.º 24
0
 def test_deleted_migrations_detected(self):
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures',
                                  'deleted-1')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(os.path.dirname(__file__),
                                       'fixtures', 'deleted-2')
     try:
         mariposa.migrate()
         self.fail('Expected a ModifiedMigrationException')
     except ModifiedMigrationException as e:
         self.assertEqual(str(e),
                          ('[20120115221757-initial.sql] migrations were '
                           'deleted since they were run on this database.'))
Exemplo n.º 25
0
 def test_multiple_migrations(self):
     self.settings['directory'] = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'initial')
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'second-run')
     mariposa.migrate()
     self.assertEqual(
         mariposa.engine.performed_migrations(),
         [('20120115075349-create-user-table.sql',
           '0187aa5e13e268fc621c894a7ac4345579cf50b7'),
          ('20120603133552-awesome.sql',
           '6759512e1e29b60a82b4a5587c5ea18e06b7d381')])
Exemplo n.º 26
0
 def test_out_of_order_migration(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'out-of-order-1')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'out-of-order-2')
     try:
         mariposa.migrate()
         self.fail('Expected an OutOfOrder exception')
     except OutOfOrderException as e:
         self.assertEqual(
             str(e),
             ('[20120114221757-before-initial.sql] '
              'older than the latest performed migration'))
Exemplo n.º 27
0
 def test_allowed_out_of_order_migration(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'out-of-order-1')
     self.settings['directory'] = fixtures_path
     self.settings['out_of_order'] = True
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'out-of-order-2')
     mariposa.migrate()
     self.assertEqual(
         mariposa.engine.performed_migrations(),
         [('20120114221757-before-initial.sql',
           'c7fc17564f24f7b960e9ef3f6f9130203cc87dc9'),
          ('20120115221757-initial.sql',
           '841ea60d649264965a3e8c8a955fd7aad54dad3e')])
Exemplo n.º 28
0
 def test_deleted_migrations_detected(self):
     fixtures_path = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'deleted-1')
     self.settings['directory'] = fixtures_path
     mariposa = DBMigrate(**self.settings)
     mariposa.migrate()
     mariposa.directory = os.path.join(
         os.path.dirname(__file__), 'fixtures', 'deleted-2')
     try:
         mariposa.migrate()
         self.fail('Expected a ModifiedMigrationException')
     except ModifiedMigrationException as e:
         self.assertEqual(
             str(e),
             ('[20120115221757-initial.sql] migrations were '
              'deleted since they were run on this database.'))