コード例 #1
0
ファイル: manage.py プロジェクト: nk910216/Flask_example
def create_table():
    """ Creates the table
    """
    engine = db.get_engine()
    db_connect_url = engine.url

    # get all info for the connection
    db_name = engine.name
    db_host = db_connect_url.host
    db_port = db_connect_url.port
    db_database = db_connect_url.database
    db_username = db_connect_url.username
    db_password = db_connect_url.password

    db_port = ':' + str(db_port) if db_port else ''
    # connect to database using another engine
    connect_url = '{0}://{1}:{2}@{3}{4}'.format(db_name, db_username,
                                                db_password, db_host, db_port)
    db_engine = create_engine(connect_url)
    existing_dbs = db_engine.execute("SHOW DATABASES")
    existing_dbs = [d[0] for d in existing_dbs]

    # create database if not exist
    if db_database not in existing_dbs:
        db_engine.execute(
            "CREATE DATABASE IF NOT EXISTS {}".format(db_database))
        print('create database')

    # create tables
    db.create_all()
    db.session.commit()
コード例 #2
0
    def forge(user, follow, photo, file, tag, collect, comment):
        """Generate fake data."""

        from server.fakes import fake_admin, fake_comment, fake_follow, fake_photo, fake_file, fake_tag, fake_user, fake_collect

        db.drop_all()
        db.create_all()

        click.echo('Initializing the roles and permissions...')
        Role.init_role()
        click.echo('Generating the administrator...')
        fake_admin()
        click.echo('Generating %d users...' % user)
        fake_user(user)
        click.echo('Generating %d follows...' % follow)
        fake_follow(follow)
        click.echo('Generating %d tags...' % tag)
        fake_tag(tag)
        click.echo('Generating %d photos...' % photo)
        fake_photo(photo)
        click.echo("Generating files ")
        fake_file(file)
        click.echo('Generating %d collects...' % photo)
        fake_collect(collect)
        click.echo('Generating %d comments...' % comment)
        fake_comment(comment)
        click.echo('Done.')
コード例 #3
0
ファイル: base.py プロジェクト: nk910216/Flask_example
    def create_app(cls):

        app = current_app

        db.create_all()
        db.session.commit()

        return app.test_client()
コード例 #4
0
def create_db():
    """Drop and create the database."""
    # Create uuid-ossp extension, if it doesn't exist.
    db.session.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
    db.session.commit()

    db.reflect()
    db.drop_all()
    db.create_all()
コード例 #5
0
    def init():
        """Initialize server."""
        click.echo('Initializing the database...')
        db.create_all()

        click.echo('Initializing the roles and permissions...')
        Role.init_role()

        click.echo('Done.')
コード例 #6
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.')
コード例 #7
0
def db(app):
    """
    Setup our database, this only gets executed once per session.

    :param app: Pytest fixture
    :return: SQLAlchemy database session
    """
    _db.drop_all()
    _db.create_all()

    return _db
コード例 #8
0
ファイル: conftest.py プロジェクト: Nukesor/spacesurvival
def dbmodels(app):
    """Database and models.

    If the database defined in `SQLALCHEMY_DATABASE_URI` already exists, it is
    dropped and re-created.
    """
    with app.app_context():
        # If there is an existing database, make sure to drop it and re-create
        # it in order to make sure that we're getting a clean testrun.
        db.drop_all()
        db.create_all()
コード例 #9
0
def init_database():
    # Create the database and the database table
    db.create_all()

    # Insert user data
    # ...

    # Commit the changes for the users
    db.session.commit()

    yield db  # this is where the testing happens!

    db.drop_all()
コード例 #10
0
ファイル: cmd_db.py プロジェクト: himudianda/REST-Assignment
def init():
    """
    Initialize the database.

    :return: db session create_all result
    """
    db.drop_all()
    return db.create_all()
コード例 #11
0
ファイル: factory.py プロジェクト: adrianplusplus/rest-api
def create_users(app):

    db.create_all()

    for user in app.config['DEFAULT_USERS']:

        found_user = User.query.filter_by(email=user['email']).first()

        if not found_user:
            new_user = User(
                email=user['email'],
                password=user['password'],
                admin=user['admin']
            )
            # insert the user
            db.session.add(new_user)

    db.session.commit()
コード例 #12
0
def init(with_testdb):
    """
    Initialize the database.

    :param with_testdb: Create a test database
    :return: None
    """
    db.reflect()
    db.drop_all()
    db.create_all()

    if with_testdb:
        db_uri = '{0}_test'.format(app.config['SQLALCHEMY_DATABASE_URI'])

        if not database_exists(db_uri):
            create_database(db_uri)

    return None
コード例 #13
0
ファイル: cmd_db.py プロジェクト: himudianda/REST-Assignment
def create(databases):
    """
    Create 1 or more databases.

    :return: db session create_all result
    """
    database = PostgresDatabase(databases)
    database.create()

    # We also do a create all to load the initial schema from our models.
    return db.create_all()
コード例 #14
0
def db(app):
    """
    Setup database, executed once per session.

    :param app: Pytest fixture
    :return: SQLAlchemy database session
    """
    _db.drop_all()
    _db.create_all()

    # Create a single user because a lot of tests do not mutate this user.
    params = {
        'role': 'admin',
        'email': '*****@*****.**',
        'password': '******',
        'coins': 100
    }

    admin = User(**params)

    _db.session.add(admin)
    _db.session.commit()

    return _db
コード例 #15
0

if __name__ == "__main__":

    app = create_app()

    # create tables on the database
    with app.app_context(): 
        print("Dropping tables...")
        db.drop_all()

        print("Dropping functions...")
        db.engine.execute("DROP FUNCTION IF EXISTS modify_updated_at CASCADE;")

        print("Creating tables.")
        db.create_all()


    with open("sam_gov_data.csv") as f:
        data = [tuple(line) for line in csv.reader(f)]


    insert_statment = """
        INSERT INTO sam_vendors(
            duns,
            duns_plus_four,
            cage_code,
            legal_business_name,
            elec_govt_bus_poc_email,
            mailing_address_line1,
            mailing_address_line2,
コード例 #16
0
ファイル: manage.py プロジェクト: Jelvix/Flask-Code-Sample
def create_db():
    """drop all data from db and create new db"""
    db.create_all()
    db.session.commit()
コード例 #17
0
ファイル: base.py プロジェクト: adrianplusplus/rest-api
 def setUp(self):
     with self.app.app_context():
         db.create_all()
コード例 #18
0
def create(empty=False):
    """
    Creates database tables for the application models and loads the seed data
    """
    db.create_all()
コード例 #19
0
def create_db():
    """Creates the db tables."""
    db.create_all()
コード例 #20
0
ファイル: base.py プロジェクト: adrianplusplus/rest-api
 def setUp(self):
     with self.app.app_context():
         db.create_all()