相关疑难解决方法(0)

是否可以将alembic连接字符串存储在alembic.ini之外?

我正在使用Alembic和SQL Alchemy.使用SQL Alchemy,我倾向于遵循一种模式,即我不将连接字符串与版本化代码一起存储.相反,我的文件secret.py包含任何机密信息.我把这个文件名丢给我,.gitignore所以它不会在GitHub上结束.

这种模式工作正常,但现在我开始使用Alembic进行迁移.看来我无法隐藏连接字符串.而是在alembic.ini中,将连接字符串作为配置参数放置:

# the 'revision' command, regardless of autogenerate
# revision_environment = false

sqlalchemy.url = driver://user:pass@localhost/dbname

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembi
Run Code Online (Sandbox Code Playgroud)

我担心我会不小心为我的数据库提交一个包含用户名/密码信息的文件.我宁愿将这个连接字符串存储在一个地方,并避免意外将其提交给版本控制的风险.

我有什么选择?

python sqlalchemy alembic

52
推荐指数
6
解决办法
9538
查看次数

Alembic - 自发生成空迁移

我试图Alembic第一次使用,并希望使用此处--autogenerate描述的功能

我的项目结构看起来像

project/
       configuration/
                    __init__.py
                    dev.py
                    test.py
       core/
           app/
              models/
                    __init__.py
                    user.py
       db/
          alembic/
                  versions/
                  env.py
          alembic.ini
Run Code Online (Sandbox Code Playgroud)

我使用Flask,并SQLAlchemy和他们的Flask-SQLAlchemy扩展.我的模特User看起来像

class User(UserMixin, db.Model):
    __tablename__ = 'users'
    # noinspection PyShadowingBuiltins
    uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True,
                  unique=True)
    email = Column('email', String, nullable=False, unique=True)
    _password = Column('password', String, nullable=False)
    created_on = Column('created_on', sa.types.DateTime(timezone=True),
                        default=datetime.utcnow())
    last_login = Column('last_login', sa.types.DateTime(timezone=True),
                        onupdate=datetime.utcnow())
Run Code Online (Sandbox Code Playgroud)

如上所述这里,我修改env.py的样子

from configuration import app

alembic_config = config.get_section(config.config_ini_section) …
Run Code Online (Sandbox Code Playgroud)

python migration flask flask-sqlalchemy alembic

19
推荐指数
5
解决办法
2万
查看次数

无法启动Airflow工作人员/花,需要澄清Airflow架构以确认安装是否正确

在另一台计算机上运行工作程序会导致下面指定的错误.我已按照配置说明操作并同步dags文件夹.

我还要确认RabbitMQ和PostgreSQL只需要安装在Airflow核心机器上,而不需要安装在工作人员上(工作人员只能连接到核心).

设置规范详述如下:

气流核心/服务器计算机

安装了以下内容:

  • Python 2.7 with
    • 气流(AIRFLOW_HOME =〜/ airflow)
    • 芹菜
    • psycogp2
  • 的RabbitMQ
  • PostgreSQL的

在airflow.cfg中进行的配置:

  • sql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow
  • executor = CeleryExecutor
  • broker_url = amqp://username:password@192.168.1.2:5672//
  • celery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow

进行的测试:

  • RabbitMQ正在运行
  • 可以连接到PostgreSQL并确认Airflow已创建表
  • 可以启动和查看网络服务器(包括自定义dags)

.

.

气流工人计算机

安装了以下内容:

  • Python 2.7 with
    • 气流(AIRFLOW_HOME =〜/ airflow)
    • 芹菜
    • psycogp2

airflow.cfg中的配置与服务器中的配置完全相同:

  • sql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow
  • executor = CeleryExecutor
  • broker_url = amqp://username:password@192.168.1.2:5672//
  • celery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow

命令输出在工作机器上运行:

运行时airflow flower:

ubuntu@airflow_client:~/airflow$ airflow flower
[2016-06-13 04:19:42,814] {__init__.py:36} INFO - Using executor CeleryExecutor
Traceback (most recent call last): …
Run Code Online (Sandbox Code Playgroud)

python rabbitmq celery airflow

13
推荐指数
2
解决办法
7423
查看次数

cx_Freeze exe 在运行时导致 psycopg2 出现 sqlalchemy.exc.NoSuchmoduleError

编辑:我可以使用哪些工具来查看可执行文件在尝试访问 psycopg2 包时试图查找哪些包/文件?也许这可以帮助分析哪里出了问题。

我有一个 python 脚本,在使用解释器运行时运行得很好,但当我冻结它时,我收到错误:

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgresql.psycopg2
Run Code Online (Sandbox Code Playgroud)

因为它在解释器中运行良好,但在冻结时失败,所以我怀疑我的 setup.py 文件有问题。

#-*- coding: 'utf-8' -*-

from cx_Freeze import setup, Executable
import sys

# Dependencies are automatically detected, but it might need
# fine tuning.

# execute this file with the command: python setup.py build

buildOptions = dict(packages = ['ht_cg.ht_cg_objects'],
                    includes = ['ht_cg.ht_cg_objects'],
                    excludes = ['tkinter', 'PyQt4', 'matplotlib', 'tcl', 'scipy'],
                    include_files = ['./cg_source_prep/readme.txt', "./ht_cg_objects/ht_db_config.cfg"],
                    build_exe = 'build/source_density_exe')

sys.path.append('./')
sys.path.append('../')
executables = [
    Executable(script = "cg_source_save.py",
                initScript = None, …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy psycopg2 cx-freeze python-3.4

3
推荐指数
1
解决办法
673
查看次数