Example #1
0
def test_basic_schemainspect():
    a = ColumnInfo("a", "text", str)
    a2 = ColumnInfo("a", "text", str)
    b = ColumnInfo("b", "varchar", str, dbtypestr="varchar(10)")
    b2 = ColumnInfo("b",
                    "text",
                    str,
                    dbtypestr="text",
                    default="'d'::text",
                    not_null=True)
    assert a == a2
    assert a == a
    assert a != b
    assert b != b2
    alter = b2.alter_table_statements(b, "t")
    assert alter == [
        "alter table t alter column \"b\" set default 'd'::text;",
        'alter table t alter column "b" set not null;',
        'alter table t alter column "b" set data type text using "b"::text;',
    ]
    alter = b.alter_table_statements(b2, "t")
    assert alter == [
        'alter table t alter column "b" drop default;',
        'alter table t alter column "b" drop not null;',
        'alter table t alter column "b" set data type varchar(10) using "b"::varchar(10);',
    ]
    b.add_column_clause == 'add column "b"'
    b.drop_column_clause == 'drop column "b"'
    with temporary_database("sqlite") as dburl:
        with raises(NotImplementedError):
            with S(dburl) as s:
                get_inspector(s)
Example #2
0
def test_basic_schemainspect():
    a = ColumnInfo('a', 'text', str)
    a2 = ColumnInfo('a', 'text', str)
    b = ColumnInfo('b', 'varchar', str, dbtypestr='varchar(10)')
    b2 = ColumnInfo('b',
                    'text',
                    str,
                    dbtypestr='text',
                    default="'d'::text",
                    not_null=True)
    assert a == a2
    assert a == a
    assert a != b
    assert b != b2
    alter = b2.alter_table_statements(b, 't')
    assert alter == [
        'alter table t alter column "b" set default \'d\'::text;',
        'alter table t alter column "b" set not null;',
        'alter table t alter column "b" set data type text;',
    ]
    alter = b.alter_table_statements(b2, 't')
    assert alter == [
        'alter table t alter column "b" drop default;',
        'alter table t alter column "b" drop not null;',
        'alter table t alter column "b" set data type varchar(10);',
    ]
    b.add_column_clause == 'add column "b"'
    b.drop_column_clause == 'drop column "b"'
    with temporary_database('sqlite') as dburl:
        with raises(NotImplementedError):
            with S(dburl) as s:
                get_inspector(s)
Example #3
0
def test_basic_schemainspect():
    a = ColumnInfo("a", "text", str)
    a2 = ColumnInfo("a", "text", str)
    b = ColumnInfo("b", "varchar", str, dbtypestr="varchar(10)")
    b2 = ColumnInfo(
        "b", "text", str, dbtypestr="text", default="'d'::text", not_null=True
    )
    assert a == a2
    assert a == a
    assert a != b
    assert b != b2
    alter = b2.alter_table_statements(b, "t")
    assert alter == [
        "alter table t alter column \"b\" set default 'd'::text;",
        'alter table t alter column "b" set not null;',
        'alter table t alter column "b" set data type text using "b"::text;',
    ]
    alter = b.alter_table_statements(b2, "t")
    assert alter == [
        'alter table t alter column "b" drop default;',
        'alter table t alter column "b" drop not null;',
        'alter table t alter column "b" set data type varchar(10) using "b"::varchar(10);',
    ]
    b.add_column_clause == 'add column "b"'
    b.drop_column_clause == 'drop column "b"'
    with temporary_database("sqlite") as dburl:
        with raises(NotImplementedError):
            with S(dburl) as s:
                get_inspector(s)