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

To help you get started, we’ve selected a few ihatemoney 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 spiral-project / ihatemoney / ihatemoney / run.py View on Github external
con = db.engine.connect()
        tables_exist = db.engine.dialect.has_table(con, "project")
        alembic_setup = db.engine.dialect.has_table(con, "alembic_version")
        return tables_exist and not alembic_setup

    sqlalchemy_url = app.config.get("SQLALCHEMY_DATABASE_URI")
    if sqlalchemy_url.startswith("sqlite:////tmp"):
        warnings.warn(
            "The database is currently stored in /tmp and might be lost at "
            "next reboot."
        )

    db.init_app(app)
    db.app = app

    Migrate(app, db)
    migrations_path = os.path.join(app.root_path, "migrations")

    if _pre_alembic_db():
        with app.app_context():
            # fake the first migration
            stamp(migrations_path, revision="b9a10d5d63ce")

    # auto-execute migrations on runtime
    with app.app_context():
        upgrade(migrations_path)
github spiral-project / ihatemoney / ihatemoney / manage.py View on Github external
def main():
    QUIET_COMMANDS = ("generate_password_hash", "generate-config")

    exception = None
    backup_stderr = sys.stderr
    # Hack to divert stderr for commands generating content to stdout
    # to avoid confusing the user
    if len(sys.argv) > 1 and sys.argv[1] in QUIET_COMMANDS:
        sys.stderr = open(os.devnull, "w")

    try:
        app = create_app()
        Migrate(app, db)
    except Exception as e:
        exception = e

    # Restore stderr
    sys.stderr = backup_stderr

    if exception:
        raise exception

    manager = Manager(app)
    manager.add_command("db", MigrateCommand)
    manager.add_command("generate_password_hash", GeneratePasswordHash)
    manager.add_command("generate-config", GenerateConfig)
    manager.add_command("delete-project", DeleteProject)
    manager.run()
github spiral-project / ihatemoney / ihatemoney / run.py View on Github external
""" Checks if we are migrating from a pre-alembic ihatemoney
        """
        con = db.engine.connect()
        tables_exist = db.engine.dialect.has_table(con, "project")
        alembic_setup = db.engine.dialect.has_table(con, "alembic_version")
        return tables_exist and not alembic_setup

    sqlalchemy_url = app.config.get("SQLALCHEMY_DATABASE_URI")
    if sqlalchemy_url.startswith("sqlite:////tmp"):
        warnings.warn(
            "The database is currently stored in /tmp and might be lost at "
            "next reboot."
        )

    db.init_app(app)
    db.app = app

    Migrate(app, db)
    migrations_path = os.path.join(app.root_path, "migrations")

    if _pre_alembic_db():
        with app.app_context():
            # fake the first migration
            stamp(migrations_path, revision="b9a10d5d63ce")

    # auto-execute migrations on runtime
    with app.app_context():
        upgrade(migrations_path)