How to use the ara.models.db function in ara

To help you get started, we’ve selected a few ara examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible-community / ara / tests / unit / test_cli.py View on Github external
def setUp(self):
        m.db.create_all()

        self.client = self.app.test_client()
github ansible-community / ara / tests / unit / test_callback.py View on Github external
def tearDown(self):
        m.db.session.remove()
        m.db.drop_all()
github ansible-community / ara / tests / unit / test_filters.py View on Github external
def tearDown(self):
        m.db.session.remove()
        m.db.drop_all()
github ansible-community / ara / tests / unit / test_models.py View on Github external
def setUp(self):
        m.db.create_all()

        self.playbook = m.Playbook(path='testing.yml')

        self.play = m.Play(
            name='test play',
            playbook=self.playbook,
        )

        self.task = m.Task(
            name='test task',
            play=self.play,
            playbook=self.playbook,
        )

        self.data = m.Data(
            playbook=self.playbook,
github ansible-community / ara / ara / plugins / actions / ara_record.py View on Github external
def create_or_update_key(self, playbook_id, key, value, type):
        try:
            data = (models.Data.query
                    .filter_by(key=key)
                    .filter_by(playbook_id=playbook_id)
                    .one())
            data.value = value
            data.type = type
        except models.NoResultFound:
            data = models.Data(playbook_id=playbook_id,
                               key=key,
                               value=value,
                               type=type)
        db.session.add(data)
        db.session.commit()

        return data
github dmsimard / ara-archive / ara / cli / playbook.py View on Github external
res = models.Playbook.query.get(pid)
                if res is None:
                    if args.ignore_errors:
                        self.log.warning('Playbook %s does not exist '
                                         '(ignoring)' % pid)
                    else:
                        raise RuntimeError('Playbook %s does not exist' % pid)
                else:
                    pids.append(pid)

        for pid in pids:
            self.log.warning('deleting playbook %s', pid)
            playbook = models.Playbook.query.get(pid)
            db.session.delete(playbook)

        db.session.commit()
github ansible-community / ara / ara / webapp.py View on Github external
def configure_db(app):
    """
    0.10 is the first version of ARA that ships with a stable database schema.
    We can identify a database that originates from before this by checking if
    there is an alembic revision available.
    If there is no alembic revision available, assume we are running the first
    revision which contains the latest state of the database prior to this.
    """
    models.db.init_app(app)
    log = logging.getLogger('ara.webapp.configure_db')
    log.debug('Setting up database...')

    if app.config.get('ARA_AUTOCREATE_DATABASE'):
        with app.app_context():
            migrations = app.config['DB_MIGRATIONS']
            flask_migrate.Migrate(app, models.db, directory=migrations)
            config = app.extensions['migrate'].migrate.get_config(migrations)

            # Verify if the database tables have been created at all
            inspector = Inspector.from_engine(models.db.engine)
            if len(inspector.get_table_names()) == 0:
                log.info('Initializing new DB from scratch')
                flask_migrate.upgrade(directory=migrations)

            # Get current alembic head revision
github ansible-community / ara / ara / webapp.py View on Github external
def configure_db(app):
    """
    0.10 is the first version of ARA that ships with a stable database schema.
    We can identify a database that originates from before this by checking if
    there is an alembic revision available.
    If there is no alembic revision available, assume we are running the first
    revision which contains the latest state of the database prior to this.
    """
    models.db.init_app(app)
    log = logging.getLogger('ara.webapp.configure_db')
    log.debug('Setting up database...')

    if app.config.get('ARA_AUTOCREATE_DATABASE'):
        with app.app_context():
            migrations = app.config['DB_MIGRATIONS']
            flask_migrate.Migrate(app, models.db, directory=migrations)
            config = app.extensions['migrate'].migrate.get_config(migrations)

            # Verify if the database tables have been created at all
            inspector = Inspector.from_engine(models.db.engine)
            if len(inspector.get_table_names()) == 0:
                log.info('Initializing new DB from scratch')
                flask_migrate.upgrade(directory=migrations)

            # Get current alembic head revision
            script = ScriptDirectory.from_config(config)
            head = script.get_current_head()

            # Get current revision, if available
            connection = models.db.engine.connect()
            context = MigrationContext.configure(connection)
            current = context.get_current_revision()