コード例 #1
0
def create_db_if_not_exists():
    exists = path.exists("/backend/database/database.db")
    if not exists:
        print("No DB found, creating a new one in /backend/database.")
        db.create_all()
    else:
        print("DB already exists, skipping.")
コード例 #2
0
ファイル: controllers.py プロジェクト: gamegos/cesi
def check_database():
    try:
        ### Create Tables
        db.create_all()
        ### Add Admin User
        admin_user = User.register(username="******", password="******", usertype=0)
    except Exception as e:
        print(e)
コード例 #3
0
ファイル: manager.py プロジェクト: honmaple/flask-maple
def init_db():
    """
    Drops and re-creates the SQL schema
    """
    db.drop_all()
    db.configure_mappers()
    db.create_all()
    db.session.commit()
コード例 #4
0
ファイル: routes.py プロジェクト: lorcosta/Lab4_IS_database
 def setup_db():
     db.create_all()
     if not Role.query.filter_by(authorisation='admin').first() or not Role.query.filter_by(authorisation='user').first():
         role_teacher = Role(name='teacher', authorisation='admin')
         role_student = Role(name='student', authorisation='user')
         with app.app_context():
             db.session.add_all([role_teacher, role_student])
     db.session.commit()
コード例 #5
0
def init_db():
    """
    Drops and re-creates the SQL schema
    """
    db.drop_all()
    db.configure_mappers()
    db.create_all()
    db.session.commit()
コード例 #6
0
def check_database():
    try:
        ### Create Tables
        db.create_all()
        ### Add Admin User
        admin_user = User.register(username="******", password="******", usertype=0)
    except Exception as e:
        print(e)
コード例 #7
0
ファイル: conftest.py プロジェクト: knazin/example_app
def database():
    db.session.remove()
    db.reflect()
    db.drop_all()
    db.create_all()

    yield db  # this is where the testing happens!

    db.drop_all()
コード例 #8
0
def client():
    """ My custom test client.
    """
    app.config['TESTING'] = True
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
    # app.config['SQLALCHEMY_DATABASE_URI'] = \
    #     'mysql+mysqlconnector://test:Test12345678!@localhost/iot_test'

    with app.app_context():
        db.drop_all()
        db.create_all()

        # Add test user
        user = User(username='******', email='*****@*****.**')
        user.set_password('test')
        db.session.add(user)
        db.session.commit()

        # Add test device
        device = Device(name='test', display_name='test', user=user)
        db.session.add(device)
        db.session.commit()

        schema = {
            'test1': ['test1', 2, 1, 0],
            'test2': ['test2', 2, 1, 0],
            'control': ['control', 3, 1, 1],
        }
        device.set_schema(schema)

        # Add test data
        new_data = DeviceData(time=datetime.utcfromtimestamp(1500000000),
                              data={
                                  'test1': 10.0,
                                  'test2': 12.0,
                                  'control': False,
                              },
                              device=device)
        db.session.add(new_data)
        db.session.commit()

        # Get token
        access_token = create_access_token(identity=user.username)
        refresh_token = create_refresh_token(identity=user.username)

        my_client = MyTestClient(access_token,
                                 refresh_token,
                                 default_auth=TokenType.access)

    yield my_client

    with app.app_context():
        db.session.remove()
        db.drop_all()
コード例 #9
0
def clear_db(db):
    confirm = input('Clear all tables? [yes/no]: ')
    if confirm == 'yes':
    # drop/create tables
        print('#'*60)
        print('Dropping all tables')
        print('#'*60)
        db.drop_all()
        print('#'*60)
        print('Creating all tables')
        print('#'*60)
        db.create_all()
        print('All tables cleared')
    elif confirm == 'no':
        exit(1)
    else:
        print('Please type yes or no')
        clear_db(db)
コード例 #10
0
def app():
    """Set up and tear down the test app."""
    from run import create_app, db

    app = create_app('testing')

    app.config['TESTING'] = True

    app_context = app.app_context()
    app_context.push()

    db.create_all()

    yield app

    db.session.remove()
    db.drop_all()
    app_context.pop()
コード例 #11
0
ファイル: init_db.py プロジェクト: dbrown29/run.exit107.com
def clear_db(db):
  confirm = input('Clear all tables? [yes/no]: ')
  if confirm == 'yes':
    # drop/create tables
    print('#'*60)
    print('Dropping all tables')
    print('#'*60)
    db.drop_all()
    print('#'*60)
    print('Creating all tables')
    print('#'*60)
    db.create_all()
    print('All tables cleared')
  elif confirm == 'no':
    exit(1)
  else:
    print('Please type yes or no')
    clear_db(db)
コード例 #12
0
def initial_db():
    ### Drop All tables
    db.reflect()
    db.drop_all()
    ### Clear sessions
    session.clear()
    session.pop('username', None)
    ### Create Tables
    db.create_all()
    ### Create Roles
    administrative_staff = models.Role(name='IdariPersonel')
    teacher = models.Role(name='Ogretmen')
    student = models.Role(name='Ogrenci')
    db.session.add(administrative_staff)
    db.session.add(teacher)
    db.session.add(student)
    db.session.commit()

    ### Create Role Funcs
    func_create_user = models.RoleFuncs(name='CreateUser', role_id=administrative_staff.id)
    func_see_all_user = models.RoleFuncs(name='SeeAllUser', role_id=administrative_staff.id)
    db.session.add(func_create_user)
    db.session.add(func_see_all_user)
    db.session.commit()

    func_danisman_ata = models.RoleFuncs(name='AssignCons', role_id=administrative_staff.id)
    db.session.add(func_danisman_ata)
    db.session.commit()

    ###################### Create Administrative Staff
    new_administrative_staff = create_new_user(
        uname="admin",
        password="******",
        fname= "Mustafa",
        mname= "Kemal",
        sname= "Ataturk",
        email= "*****@*****.**",
        role_id=administrative_staff.id
    )
    return '<a href="/">Ok!</a>'
コード例 #13
0
    def setUp(self):
        self.app = self.create_app().test_client()
        self.database = db
        db.create_all()

        # Add dummy data for test purposes
        user = UserModel(username="******")
        user.email = '*****@*****.**'
        user.password = '******'
        user.save_to_db()

        user2 = UserModel(username="******")
        user2.email = '*****@*****.**'
        user2.password = '******'
        user2.save_to_db()

        user3 = UserModel(username="******")
        user3.email = '*****@*****.**'
        user3.password = '******'
        user3.save_to_db()

        category1 = CategoryModel(name="somerecipecategory", created_by=1)
        category1.save_to_db()
        category2 = CategoryModel(name="somerecipecategory2", created_by=1)
        category2.save_to_db()

        recipe1 = RecipeModel(name="somerecipe1",
                              description="Add one spoonfuls of...",
                              created_by=1,
                              category_id=1)
        recipe1.save_to_db()
        recipe2 = RecipeModel(name="somerecipe2",
                              description="Add two spoonfuls of...",
                              created_by=1,
                              category_id=2)
        recipe2.save_to_db()
コード例 #14
0
from run import db; db.create_all()
コード例 #15
0
def run():
    db.create_all()
    print('run_db')
コード例 #16
0
def insertData():
    Course()
    db.create_all()
    courses = data.load_data()
    res = insertCoursesIntoDatabase(courses)
    return jsonify(res)
コード例 #17
0
def init_db():
    db.create_all()
    db.session.commit()
コード例 #18
0
ファイル: base_test.py プロジェクト: spraetz/gtm_flask
 def setUp(self):
     db.create_all()
コード例 #19
0
ファイル: db_create.py プロジェクト: EvgeniyKolchin/OCR
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from run import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
コード例 #20
0
    @validates("message_type")
    def validate_type(self, key, value):
        assert value in MESSAGE_TYPES
        return value

    def __init__(self, body, message_type):
        self.body = body
        self.message_type = message_type

    @property
    def sms_body(self):
        return "{}: {!r}".format(self.body, self.product)

    def to_dict(self):
        return {
            "pk": self.pk,
            "body": self.body,
            "message_type": self.message_type,
            "product_id": self.product_id,
        }


if __name__ == "__main__":
    # Run this file directly to create the database tables.
    from run import app

    print("Creating database tables...")
    db.create_all(app=app)
    print("Done!")
コード例 #21
0
 def setUp(self):
     db.create_all()
     db.session.commit()
コード例 #22
0
ファイル: database.py プロジェクト: taimasuid/Twilio_SMS
    id = Column('id', Integer, primary_key=True)
    username = Column('username', String(50))
    phone = Column('phone', String(20))

    def __repr__(self):
        return '<Users {}>'.format(self.username)


class Orders(db.Model):

    __tablename__ = "orders"

    id = Column('id', Integer, primary_key=True)
    product_id = Column(Integer, ForeignKey('products.id'))
    customer_phone = Column('customer_phone', String(15))
    shipped = Column('shipped', Boolean())


class Products(db.Model):

    __tablename__ = "products"

    id = Column('id', Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    message = Column('message', String(200))


if __name__ == "__main__":
    db.create_all()
コード例 #23
0
def api_delete_all():
    db.drop_all()
    db.create_all()
    create_test_data()
    return {'status': 'Successfully deleted all database data'}, 200