V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
levon
V2EX  ›  Python

为什么需要 database migration tool ?

  •  
  •   levon · Apr 6, 2013 · 4130 views
    This topic created in 4782 days ago, the information mentioned may be changed or developed.
    alembic: https://pypi.python.org/pypi/alembic

    我弄不懂为什么需要这东西,直接在mysql添加修改字段,表等,不是很方便吗?用这库还需要写代码去执行。
    8 replies    1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
    PRO
       Apr 6, 2013
    假设 PB3 是一个开源软件,客户安装了 1.0 版本,然后在升级到 1.1 时,数据库结构发生改变了,这个时候就绝对需要迁移工具。
    levon
        2
    levon  
    OP
       Apr 6, 2013
    恩,这应该是个实用场景。但是sql也可以搞定,发布一个update.sql,不是更简洁明了吗
    Livid
        3
    Livid  
    MOD
    PRO
       Apr 6, 2013
    @levon 如果是 1.0 -> 1.1 这种简单升级,那么确实可以只用一个差异 sql 搞定。

    但是,如果是 1.1.5 -> 1.4.7 这种复杂升级……
    levon
        4
    levon  
    OP
       Apr 6, 2013
    好吧,我没在实际中使用过,

    意思是这工具在做数据库结构更新比直接写sql还简单,特别是很多修改的情况下。
    chuangbo
        5
    chuangbo  
       Apr 6, 2013   ❤️ 1
    @levon 在以下情况极其必要:多人协作、多分支、部署与数据库回滚。
    因为数据库和代码不一样,不是打 diff 也不能简单的文件替换,没有版本,无法用 Git 或运维工具管理。有了 Migration Tools,数据库就有了版本,就可以像代码一样管理了,可以随意切换合并回滚版本,更灵活更方便。
    duhastmich
        6
    duhastmich  
       Apr 6, 2013
    sql 也可以吧,不过要往前滚,往后滚,逐步滚,得有个脚本来管理大量的sql 文件吧(02-up.sql, 02-down.sql, 03-up.sql...(这样的编号还有冲突的可能...)),还有数据库连接配置, 记录当前滚到哪个版本等
    whtsky
        7
    whtsky  
       Apr 6, 2013 via iPhone
    @Livid 「假设 PB3 是一个开源软件」
    是不是意味着 PB3 不打算开源了?
    holsety
        8
    holsety  
       Apr 6, 2013
    请问有对应mysql的类似工具吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3067 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 12:57 · PVG 20:57 · LAX 05:57 · JFK 08:57
    ♥ Do have faith in what you're doing.