Exemplo n.º 1
0
def drop_talbes():
    """
    Drop all model tables
    """
    models = (m for m in globals().values()
              if isinstance(m, type) and issubclass(m, BaseModel))
    drop_model_tables(models, fail_silently=True, cascade=True)
def drop_and_create():
    database.connect()
    drop_model_tables(models,fail_silently=True)
    
    for m in models:
        m.create_table()
        
    database.commit()
Exemplo n.º 3
0
 def inner(self):
     for database in DATABASES:
         try:
             introspector = Introspector.from_database(database)
             self.create_tables(database)
             fn(self, introspector)
         finally:
             drop_model_tables(MODELS)
Exemplo n.º 4
0
 def inner(self):
     for database in DATABASES:
         try:
             introspector = Introspector.from_database(database)
             self.create_tables(database)
             fn(self, introspector)
         finally:
             drop_model_tables(MODELS)
Exemplo n.º 5
0
def setupDatabase(clearDatabase):
    if clearDatabase:
        drop_model_tables([Tick, Execution, Scenario])

    if not Scenario.table_exists():
        Scenario.create_table()
    if not Execution.table_exists():
        Execution.create_table()
    if not Tick.table_exists():
        Tick.create_table()
Exemplo n.º 6
0
def setupDatabase(clearDatabase):
    if clearDatabase:
        drop_model_tables([Tick, Execution, Scenario])
        
    if not Scenario.table_exists():
        Scenario.create_table()
    if not Execution.table_exists():
        Execution.create_table()
    if not Tick.table_exists():
        Tick.create_table()
Exemplo n.º 7
0
    def setUp(self):
        for model_class in MODELS:
            model_class._meta.database = self.database

        drop_model_tables(MODELS, fail_silently=True)
        create_model_tables(MODELS)
        self.migrator = self.migrator_class(self.database)

        if 'newpages' in User._meta.reverse_rel:
            del User._meta.reverse_rel['newpages']
            delattr(User, 'newpages')
Exemplo n.º 8
0
    def setUp(self):
        for model_class in MODELS:
            model_class._meta.database = self.database

        drop_model_tables(MODELS, fail_silently=True)
        create_model_tables(MODELS)
        self.migrator = self.migrator_class(self.database)

        if 'newpages' in User._meta.reverse_rel:
            del User._meta.reverse_rel['newpages']
            delattr(User, 'newpages')
def create_tables():
    tables = []
    module = sys.modules[__name__]
    for sym in dir(module):
        attr = getattr(module, sym)
        if inspect.isclass(attr) and issubclass(attr, db.Model) and not attr.__abstract__:
            tables.append(attr)

    peewee.drop_model_tables(tables, fail_silently=True)
    peewee.create_model_tables(tables, fail_silently=True)

    try:
        from ... import migration
        version, _ = migration.migrations[-1]
    except IndexError:
        version = "000"

    Schema.create(version=version, description="Initial state.")
Exemplo n.º 10
0
def configure_peewee(db_name='sqlite:///:memory:',
                     db_options=None,
                     drop_before=False):

    from peewee import create_model_tables, drop_model_tables

    db_options = db_options or {}

    database = connect(db_name, **db_options)
    database_proxy.initialize(database)

    tables = [
        User, Domain, Mailbox, Mynetwork, Policy, GreylistEntry,
        GreylistMetric, WhiteList, BlackList
    ]
    if drop_before:
        drop_model_tables(tables, fail_silently=True)

    create_model_tables(tables, fail_silently=True)
Exemplo n.º 11
0
def configure_peewee(db_name='sqlite:///:memory:', db_options=None, drop_before=False):
    
    from peewee import create_model_tables, drop_model_tables
    
    db_options = db_options or {}

    database = connect(db_name, **db_options)
    database_proxy.initialize(database)

    tables = [User,
              Domain,
              Mailbox,
              Mynetwork,
              Policy, 
              GreylistEntry, 
              GreylistMetric, 
              WhiteList, 
              BlackList]
    if drop_before:
        drop_model_tables(tables, fail_silently=True)

    create_model_tables(tables, fail_silently=True)
Exemplo n.º 12
0
def rebuilddb(options):
    '''
    Rebuild DB
    '''
    from peewee import drop_model_tables, create_model_tables, find_subclasses
    from models import BaseModel, populate_tables
    print "Reconsruyendo la base de datos..."
    models = find_subclasses(BaseModel)
    print "Drop tables..."
    drop_model_tables(models)
    print "Cereate tables..."
    create_model_tables(models)
    CONFIG = {
            'default':[
                    dict(address='192.168.1.97', description="Placa de prueba 1 "),
                    dict(address='192.168.1.98', description="Placa de prueba 2"),
            ],
            'test':[
                dict(address='127.0.0.1', description=u"Conexión con localhost"),
            ]
        }
    print "Populating..."
    for name, list_of_comaster_cfg in CONFIG.iteritems():
        populate_tables(name, list_of_comaster_cfg)
Exemplo n.º 13
0
 def setUp(self):
     drop_model_tables(MODELS, fail_silently=True)
     create_model_tables(MODELS)
     self.t1 = None
     self.t2 = None
Exemplo n.º 14
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if self.create_tables and self.drop_tables:
         drop_model_tables(self.models, fail_silently=self.fail_silently)
     for i, m in enumerate(self.models):
         m._meta.database = self.orig[i]
Exemplo n.º 15
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if self.create_tables:
         drop_model_tables(self.models, fail_silently=self.fail_silently)
     for i, m in enumerate(self.models):
         m._meta.database = self.orig[i]
Exemplo n.º 16
0
def drop_tables():
    peewee.drop_model_tables(ALL_MODELS)
Exemplo n.º 17
0
 def setUp(self):
     drop_model_tables(MODELS, fail_silently=True)
     create_model_tables(MODELS)
Exemplo n.º 18
0
    def create_tables(self, db):
        for model in MODELS:
            model._meta.database = db

        drop_model_tables(MODELS, fail_silently=True)
        create_model_tables(MODELS)
Exemplo n.º 19
0
def drop_all_tables():
	'''
	Drop 'em like they're hot. Destroys all data contained in those tables as well, so use sparingly.
	'''
	drop_model_tables([School, Fighter, Market, InjuryList, Materials, Skills, FightEvent, FightMatch, TrainingSchedule, FighterEquipment, ItemArmour, ItemWeapon, ArmourType, WeaponType], fail_silently = True)
	
Exemplo n.º 20
0
    def create_tables(self, db):
        for model in MODELS:
            model._meta.database = db

        drop_model_tables(MODELS, fail_silently=True)
        create_model_tables(MODELS)
Exemplo n.º 21
0
def drop_tables(cur):
    database.connect()
    peewee.drop_model_tables([Category, Cocktail, Ingredient, Recipe])
Exemplo n.º 22
0
    def tearDown(self):
        for model_class in MODELS:
            model_class._meta.database = self.database

        drop_model_tables(MODELS, fail_silently=True)
Exemplo n.º 23
0
 def setUpClass(cls):
     peewee.drop_model_tables([Item, Source, Item2Source],
                              fail_silently=True)
     peewee.create_model_tables([Item, Source, Item2Source])
 def drop_tables(self):
     drop_model_tables(*self.models)
Exemplo n.º 25
0
import peewee

from app.sql import Item, Item2Source, Source

peewee.drop_model_tables([Item, Source, Item2Source], fail_silently=True)
peewee.create_model_tables([Item, Source, Item2Source])
Exemplo n.º 26
0
def resetdb():
    drop_model_tables([OLBook], fail_silently=True)
    create_model_tables([OLBook], fail_silently=True)
    return '<h2>Database Reset</h2>'