Пример #1
0
def initdb(drop):
    ''' initialize the database'''
    if drop:
        click.confirm('this operation will delete the database', abort=True)
        db.drop_all()
        click.echo('drop tables')
    db.create_all()
    click.echo('initialized database')
Пример #2
0
def initdb(drop):
    """Initialize the database."""
    if drop:
        click.confirm('This operation will delete the database, do you want to continue?', abort=True)
        db.drop_all()
        click.echo('Drop tables.')
    db.create_all()
    click.echo('Initialized database.')
Пример #3
0
 def setUp(self):
     app.config.update(
         TESTING=True,
         WTF_CSRF_ENABLED=False,
         SQLALCHEMY_DATABASE_URI='sqlite:///:memory:'
     )
     db.create_all()
     self.client = app.test_client()
     self.runner = app.test_cli_runner()
Пример #4
0
def insert_data():
    db.drop_all()
    db.create_all()

    admin_role = Role(name='Admin')
    mod_role = Role(name='Moderator')
    user_role = Role(name='User')
    user_john = User(username='******', role=admin_role)
    user_susan = User(username='******', role=user_role)
    user_david = User(username='******', role=user_role)

    db.session.add_all(
        [admin_role, mod_role, user_role, user_john, user_susan, user_david])
    db.session.commit()
Пример #5
0
def forge(count):
    ''' generate fake messages'''
    db.drop_all()
    db.create_all()
    click.echo("working...")

    for i in range(count):
        message = Message(name=fake.name(),
                          body=fake.sentence(),
                          age=fake.age(),
                          score=fake.score(),
                          timestamp=fake.date_time_this_year())
        db.session.add(message)
    db.session.commit()
    click.echo('created %d fake messages' % count)
Пример #6
0
def forge(count):
    """Generate fake messages."""
    from faker import Faker

    db.drop_all()
    db.create_all()

    fake = Faker()
    click.echo('Working...')

    for i in range(count):
        message = Message(
            name=fake.name(),
            body=fake.sentence(),
            timestamp=fake.date_time_this_year()
        )
        db.session.add(message)

    db.session.commit()
    click.echo('Created %d fake messages.' % count)
Пример #7
0
from hello import app, db

if __name__ == '__main__':
    db.create_all()
    app.run(debug=True)
Пример #8
0
 def setUp(self):
     db.create_all()
from hello import db

db.create_all() # reads model declarations and creates corresponding tables
Пример #10
0
from hello import db
"""
데이터베이스가 이미 존재할 경우 
테이블을 새로 생성하거나 업데이트 하지 않기에
데이터베이스를 지우고 다시 만든다.
"""
db.drop_all()
db.create_all()  # database 생성
"""행 추가"""
from hello import Role, User
admin_role = Role(name='Admin')
mod_role = Role(name='Moderator')
user_role = Role(name='User')
user_john = User(username='******', role=admin_role)
user_susan = User(username='******', role=user_role)
user_david = User(username='******', role=user_role)
"""
오브젝트는 단지 파이썬에만 존재하며 아직 데이터베이스는 작성되지 않았다.
id값이 아직 설정되지 않았기 때문
"""
print(admin_role.id)
print(mod_role.id)
print(user_role.id)
""" 데이터베이스에 대한 변경 사항은 데이터베이스 세션을 통해 관리됨. 데이터베이스 작성을 위해
오브젝트를 준비하기 위해서는 오브젝트가 세션에 추가되어야 한다."""
db.session.add(admin_role)
db.session.add(mod_role)
db.session.add(user_role)
db.session.add(user_john)
db.session.add(user_susan)
db.session.add(user_david)
Пример #11
0
from hello import db

db.create_all()  # reads model declarations and creates corresponding tables
Пример #12
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()