我正在使用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)
我担心我会不小心为我的数据库提交一个包含用户名/密码信息的文件.我宁愿将这个连接字符串存储在一个地方,并避免意外将其提交给版本控制的风险.
我有什么选择?
我试图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) 在另一台计算机上运行工作程序会导致下面指定的错误.我已按照配置说明操作并同步dags文件夹.
我还要确认RabbitMQ和PostgreSQL只需要安装在Airflow核心机器上,而不需要安装在工作人员上(工作人员只能连接到核心).
设置规范详述如下:
安装了以下内容:
在airflow.cfg中进行的配置:
sql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflowexecutor = CeleryExecutorbroker_url = amqp://username:password@192.168.1.2:5672// celery_result_backend = postgresql+psycopg2://username:password@192.168.1.2:5432/airflow进行的测试:
.
.
安装了以下内容:
airflow.cfg中的配置与服务器中的配置完全相同:
sql_alchemy_conn = postgresql+psycopg2://username:password@192.168.1.2:5432/airflowexecutor = CeleryExecutorbroker_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) 编辑:我可以使用哪些工具来查看可执行文件在尝试访问 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)