Beispiel #1
0
    def test0(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class E(db.Entity):
            t2 = orm.Required('T2')

        class T1(db.Entity):
            t2 = orm.Required('T2')
            t3 = orm.Optional('T3')

        class T2(db.Entity):
            t3 = orm.Required('T3')
            t1 = orm.Optional('T1')
            e = orm.Optional('E')

        class T3(db.Entity):
            t1 = orm.Required('T1')
            t2 = orm.Optional('T2')

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #2
0
    def test1(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #3
0
    def test_2(self):
        with open('migrations/0002.py', 'w') as f:
            f.write('''
from pony.migrate import diagram_ops as op
from pony.orm import *

dependencies = ['0001_initial']

def forward(db):
    db.execute('ALTER TABLE base MODIFY COLUMN s INTEGER')
    db.execute('ALTER TABLE base DROP COLUMN classtype')
    db.execute('RENAME TABLE base TO myentity')

def final_state(db):
    class MyEntity(db.Entity):
        int_f = Required(int)
        s = Required(int)

operations = [
    op.Custom(forward=forward, final_state=final_state),
]
            ''')

        db = self.DB
        command.migrate(db, 'apply -v')
Beispiel #4
0
    def test1(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Test(db.Entity):
            field = orm.Required(str)

        class Parent(db.Entity):
            _discriminator_ = 1
            type_field = orm.Discriminator(int)
            field = orm.Required(str)

            orm.composite_index(type_field, field)

        class Child(Parent):
            _discriminator_ = 2
            another_field = orm.Required(str)

            orm.composite_key("type_field", another_field)

        command.migrate(db, "make -v")
        command.migrate(db, "apply -v")

        with orm.db_session():
            Parent(field="abcdef")
            Child(field="qwerty", another_field="1234")
Beispiel #5
0
    def test_0(self):
        db_args, db_kwargs = self.db_params

        self.__class__.DB = db = orm.Database(*db_args, **db_kwargs)

        class MyEntity(db.Entity):
            int_f = orm.Required(int)

        command.migrate(db, 'make')
Beispiel #6
0
    def test2(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class Data(db.Entity):
            created = orm.Required(str)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #7
0
    def test0(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class Data(db.Entity):
            pass

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #8
0
    def test0(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Activity(db.Entity):
            descr = orm.Required(str)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #9
0
    def test1(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class Data(db.Entity):
            number = orm.Optional(int)
            created = orm.Optional(int)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #10
0
    def test1(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class MyEntity(db.Entity):
            int_f = orm.Required(int)
            str_f = orm.Required(str)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #11
0
    def test1(self):
        db_args, db_kwargs = self.db_params
        self.__class__.DB = db = orm.Database(*db_args, **db_kwargs)

        class Data(db.Entity):
            label = orm.Optional(str)

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #12
0
    def test0(self):
        db_args, db_kwargs = self.db_params
        self.__class__.DB = db = orm.Database(*db_args, **db_kwargs)

        class Data(db.Entity):
            created = orm.Required(datetime)

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #13
0
    def test0(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class Data(db.Entity):
            label = orm.Required(str)

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #14
0
    def test0(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Test(db.Entity):
            field = orm.Required(str)

        command.migrate(db, "make -v")
        with open("migrations/0001_initial.py") as f:
            print(f.read())
        command.migrate(db, "apply -v")
Beispiel #15
0
    def test0(self):
        db_args, db_kwargs = self.db_params
        db = self.__class__.db = orm.Database(*db_args, **db_kwargs)

        class T1(db.Entity):
            peers = orm.Set('T2')

        class T2(db.Entity):
            peers = orm.Set('T1')

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #16
0
    def test1(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Activity(db.Entity):
            s = orm.Optional(str)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')

        assert len(glob('migrations/*')) == 2
Beispiel #17
0
    def test_1(self):
        db_args, db_kwargs = self.db_params

        self.__class__.DB = db = orm.Database(*db_args, **db_kwargs)

        class MyEntity(db.Entity):
            int_f = orm.Required(int)
            s = orm.Required(str)

        # db.generate_mapping()

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #18
0
    def test1(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class T1(db.Entity):
            peers = orm.Set('T2')
            f = orm.Required(int, sql_default='3')

        class T2(db.Entity):
            peers = orm.Set('T1')

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #19
0
    def test_2(self):
        with open('migrations/0002.py', 'w') as f:
            f.write('''
from pony.migrate import diagram_ops as op

dependencies = ['0001_initial']

operations = [
    op.RenameAttr('MyEntity', 's', 't'),
    op.RenameEntity('MyEntity', 'YourEntity'),
]
            ''')
        command.migrate(self.DB, 'apply -v')
Beispiel #20
0
    def test(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class MyEntity(db.Entity):
            int_f = orm.Required(int)
            str_f = orm.Required(str)
            other = orm.Set('OtherEntity')

        class OtherEntity(db.Entity):
            fk = orm.PrimaryKey(MyEntity)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #21
0
    def test1(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Activity(db.Entity):
            descr = orm.Optional('Description')

        class Description(db.Entity):
            text = orm.Required(str)
            activity = orm.Required('Activity')

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #22
0
    def test_2(self):
        with open('migrations/0002.py', 'w') as f:
            f.write('''
from pony.migrate import diagram_ops as op
from pony.orm import *

dependencies = ['0001_initial']

operations = [
    op.AddAttr('MyEntity', 's', Required(str, initial='initial')),
]
            ''')

        command.migrate(self.DB, 'apply -v')
Beispiel #23
0
    def test_1(self):
        db_args, db_kwargs = self.db_params
        db = orm.Database(*db_args, **db_kwargs)

        class MyEntity(db.Entity):
            int_f = orm.Required(int)
            s = orm.Required(str)

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        [p] = glob.glob('./migrations/0002*')
        with open(p) as f:
            s = f.read()
        self.assertTrue('op.AddEntity' in s)
Beispiel #24
0
    def test1(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Activity(db.Entity):
            descr = orm.Required(str)
            periods = orm.Set('Time')

        class Time(db.Entity):
            amount = orm.Required(int)
            spent_on = orm.Required('Activity')

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #25
0
    def test_simple(self):
        db_args, db_kwargs = self.db_params
        with open('entities.py', 'w') as f:
            f.write('''\
from pony.orm import *

db = Database(*{}, **{})

class MyEntity(db.Entity):
    int_f = PrimaryKey(int)
    str_f = Required(str)

                '''.format(repr(db_args), repr(db_kwargs)))

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #26
0
    def test2(self):
        db_args, db_kwargs = self.db_params
        self.__class__.DB = db = orm.Database(*db_args, **db_kwargs)

        class News(db.Entity):
            content = orm.Required(str)
            source = orm.Required('Source')

        class Source(db.Entity):
            name = orm.Required(str)
            info = orm.Optional('News')

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #27
0
    def test2(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class Activity(db.Entity):
            descr = orm.Required(str)

        class Time(db.Entity):
            amount = orm.Required(int)
            spent_on = orm.Required(str)

        db.generate_mapping(create_tables=False, check_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #28
0
    def test1(self):
        db_args, db_kwargs = self.db_params

        db = orm.Database(*db_args, **db_kwargs)

        class U(db.Entity):
            peers = orm.Set('T2')
            f = orm.Required(int)

        class T2(db.Entity):
            peers = orm.Set('U')

        db.generate_mapping(check_tables=False, create_tables=False)

        command.migrate(db, 'make -v')
        command.migrate(db, 'apply -v')
Beispiel #29
0
    def test1(self):
        db_args, db_kwargs = self.db_params
        p = os.path.join('migrations', '0002.py')
        with open(p, 'w') as f:
            f.write('''\
from pony import orm
from pony.migrate import diagram_ops as op

dependencies = ['0001_initial']

operations = [
    op.AddAttr('T1', 'f', orm.Optional(int, initial=True)),
]
    '''.format(db_args, db_kwargs))

        command.migrate(self.db, 'apply -v')
Beispiel #30
0
    def test_1(self):
        db_args, db_kwargs = self.db_params
        with open('migrations/0002.py', 'w') as f:
            f.write('''

from pony.migrate import diagram_ops as ops
from pony.orm import *

dependencies = ['0001_initial']

operations = [
    ops.AddAttr('MyEntity', 's', Required(str, initial='S'))
]
            ''')

        db = self.DB
        command.migrate(db, 'apply -v')