def test_create_module(tmpdir, caplog): manager = DatabaseManager(models.database, directory=tmpdir) manager.create(models) migrations = manager.migration_files assert len(migrations) == 7 assert migrations[0].endswith('create_table_basicfields') assert 'created: {}'.format(migrations[0]) in caplog.text assert migrations[1].endswith('create_table_hascheckconstraint') assert 'created: {}'.format(migrations[1]) in caplog.text assert migrations[2].endswith('create_table_organization') assert 'created: {}'.format(migrations[2]) in caplog.text assert migrations[3].endswith('create_table_complexperson') assert 'created: {}'.format(migrations[3]) in caplog.text assert migrations[4].endswith('create_table_person') assert 'created: {}'.format(migrations[4]) in caplog.text assert migrations[5].endswith('create_table_hasuniqueforeignkey') assert 'created: {}'.format(migrations[5]) in caplog.text assert migrations[6].endswith('create_table_relatestoname') assert 'created: {}'.format(migrations[6]) in caplog.text
def test_create_module(tmpdir, caplog): """Test module creations. peewee handles the model creation sequentially in prior versions of 2.10 Refer to: https://github.com/coleifer/peewee/compare/2.9.2...2.10.0 """ manager = DatabaseManager(models.database, directory=tmpdir) manager.create(models) migrations = manager.migration_files assert len(migrations) == 7 assert migrations[0].endswith('create_table_basicfields') assert 'created: {}'.format(migrations[0]) in caplog.text assert migrations[1].endswith('create_table_hascheckconstraint') assert 'created: {}'.format(migrations[1]) in caplog.text assert migrations[2].endswith('create_table_organization') assert 'created: {}'.format(migrations[2]) in caplog.text assert migrations[3].endswith('create_table_complexperson') assert 'created: {}'.format(migrations[3]) in caplog.text assert migrations[4].endswith('create_table_person') assert 'created: {}'.format(migrations[4]) in caplog.text assert migrations[5].endswith('create_table_hasuniqueforeignkey') assert 'created: {}'.format(migrations[5]) in caplog.text assert migrations[6].endswith('create_table_relatestoname') assert 'created: {}'.format(migrations[6]) in caplog.text
def test_create_module(tmpdir, caplog): """Test module creations. peewee changed the migration creation order in: https://github.com/coleifer/peewee/compare/2.9.2...2.10.0 First create models on which current model depends (either through foreign keys or through depends_on), then create current model itself. """ manager = DatabaseManager(models.database, directory=tmpdir) manager.create(models) migrations = manager.migration_files assert len(migrations) == 8 # basicfields has no relationship assert migrations[0].endswith('create_table_basicfields') assert 'created: {}'.format(migrations[0]) in caplog.text # organization has no relationships assert migrations[1].endswith('create_table_organization') assert 'created: {}'.format(migrations[1]) in caplog.text # since complexpersion relates to organization is then now created assert migrations[2].endswith('create_table_complexperson') assert 'created: {}'.format(migrations[2]) in caplog.text # HasCheckConstraint has no relationships assert migrations[3].endswith('create_table_hascheckconstraint') assert 'created: {}'.format(migrations[3]) in caplog.text # Person has no relationship assert migrations[4].endswith('create_table_person') assert 'created: {}'.format(migrations[4]) in caplog.text # HasUniqueForeignKey relates to Person assert migrations[5].endswith('create_table_hasuniqueforeignkey') assert 'created: {}'.format(migrations[5]) in caplog.text # ModelWithTimestamp assert migrations[6].endswith('create_table_modelwithtimestamp') assert 'created: {}'.format(migrations[6]) in caplog.text # RelatesToName relates to Person assert migrations[7].endswith('create_table_relatestoname') assert 'created: {}'.format(migrations[7]) in caplog.text
def test_create_import(tmpdir, caplog): manager = DatabaseManager('sqlite:///:memory:', directory=tmpdir) manager.create('Person') assert 'could not import: Person' in caplog.text
def test_create(tmpdir, caplog): manager = DatabaseManager('sqlite:///:memory:', directory=tmpdir) manager.create(models.Person) assert 'created: 0001_create_table_person' in caplog.text
def test_create_error(tmpdir, caplog): manager = DatabaseManager('sqlite:///:memory:', directory=tmpdir) manager.create(models.NotModel) assert "type object 'NotModel' has no attribute '_meta'" in caplog.text
from peewee_moves import DatabaseManager from models import database manager = DatabaseManager(database) print(manager.revision()) manager.create('models') manager.upgrade()