def test_timestamp_model(): output = build_upgrade_from_model(models.ModelWithTimestamp) output = list(output) assert output == [ "with migrator.create_table('modelwithtimestamp') as table:", " table.primary_key('id')", " table.int('tstamp')" ]
def test_non_id_foreign_key_output(): output = build_upgrade_from_model(models.RelatesToName) output = list(output) assert output == [ "with migrator.create_table('relatestoname') as table:", " table.primary_key('id')", " table.foreign_key('string', 'person_name', on_delete='SET NULL', on_update='CASCADE', references='person.name')"]
def test_nullable_foreign_key(): output = build_upgrade_from_model(models.ForeignKeyNullModel) output = list(output) assert output[ 0] == "with migrator.create_table('foreignkeynullmodel') as table:" assert output[1] == " table.primary_key('id')" assert output[ 2] == " table.foreign_key('AUTO', 'purchase_request_id', null=True, on_delete=None, on_update=None, references='modelwithtimestamp.id')"
def test_index_field_names(): output = build_upgrade_from_model(models.HasUniqueForeignKey) output = list(output) assert output == [ "with migrator.create_table('hasuniqueforeignkey') as table:", " table.primary_key('id')", " table.int('age')", " table.foreign_key('VARCHAR', 'person_name', on_delete=None, on_update=None, references='person.name')", " table.add_index(('age', 'person_name'), unique=True)" ]
def test_build_upgrade_from_model(): output = build_upgrade_from_model(models.ComplexPerson) output = list(output) assert output == [ "with migrator.create_table('complexperson') as table:", " table.primary_key('id')", " table.char('name', max_length=5, unique=True)", " table.foreign_key('AUTO', 'organization_id', on_delete=None, on_update=None, references='organization.id')", " table.add_constraint('const1 fake')", " table.add_constraint('CHECK (const2 fake)')", ]