类似 Rails 的数据库迁移?

编程入门 行业动态 更新时间:2024-10-28 01:19:06
本文介绍了类似 Rails 的数据库迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有任何易于安装/使用(在 unix 上)的数据库迁移工具,例如 Rails Migrations?我真的很喜欢这个想法,但是纯粹为了管理我的数据库迁移而安装 ruby​​/rails 似乎有点过头了.

Is there any easy to install/use (on unix) database migration tools like Rails Migrations? I really like the idea, but installing ruby/rails purely to manage my database migrations seems overkill.

推荐答案

只需使用 ActiveRecord 和一个简单的 Rakefile.例如,如果您将迁移放在 db/migrate 目录中,并且有一个包含 db 配置的 database.yml 文件,那么这个简单的 Rakefile 应该可以工作:

Just use ActiveRecord and a simple Rakefile. For example, if you put your migrations in a db/migrate directory and have a database.yml file that has your db config, this simple Rakefile should work:

Rakefile:

require 'active_record' require 'yaml' desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" task :migrate => :environment do ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil) end task :environment do ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml'))) ActiveRecord::Base.logger = Logger.new(STDOUT) end

database.yml:

adapter: mysql encoding: utf8 database: test_database username: root password: host: localhost

之后,您将能够运行 rake migrate 并在没有周围的 Rails 应用程序的情况下获得所有迁移优势.

Afterwards, you'll be able to run rake migrate and have all the migration goodness without a surrounding rails app.

另外,我有一组 bash 脚本,它们执行与 ActiveRecord 迁移非常相似的功能,但它们仅适用于 Oracle.在切换到 Ruby 和 Rails 之前,我曾经使用过它们.它们有些复杂,我不为它们提供任何支持,但如果您有兴趣,请随时与我联系.

Alternatively, I have a set of bash scripts that perform a very similar function to ActiveRecord migrations, but they only work with Oracle. I used to use them before switching to Ruby and Rails. They are somewhat complicated and I provide no support for them, but if you are interested, feel free to contact me.

更多推荐

类似 Rails 的数据库迁移?

本文发布于:2023-10-26 23:01:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531599.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类似   数据库   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!