Ejemplo n.º 1
0
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')"
    ]
Ejemplo n.º 2
0
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')"]
Ejemplo n.º 3
0
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')"
Ejemplo n.º 4
0
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)"
    ]
Ejemplo n.º 5
0
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)')",
    ]