我可以仅使用 Rails 的迁移来维护数据库架构吗?

发布于 2024-08-05 08:48:25 字数 211 浏览 2 评论 0原文

我们的应用程序不会在其最终状态的任何部分使用 Rails,但根据我的经验,迁移是定义模式的一种极好的方式,所以我只想使用 Rails 的一个方面。

这是合理的做法吗?如果没有,是否有任何工具可以用来执行相同类型的工作?我们有一个三阶段的部署环境,包括测试、QA 和生产层,因此这很好地映射到了 Rails 使用的层。然而,我们主要是一家Python商店,所以Pythonic的等价物会很漂亮。

Our application isn't going to use rails for any part of its final state, but migrations are a fantastic way to define schema in my experience, so I'd like to use just that one aspect of rails.

Is this a reasonable thing to do? If not, are there any tools out there than can be used to perform the same sort of job? We have a three-stage deployment environment, with test, QA, and production tiers, so this maps pretty well to the tiers that rails uses. However, we're a python shop primarily, so a pythonic equivalent would be nifty.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

攒一口袋星星 2024-08-12 08:48:25

我没有什么特别的选择可以给你。但是,如果您决定无论如何使用迁移,您必须知道您不需要仅使用整个 Rails 架构来进行迁移。

只要您安装了 active_record gem,您就可以执行以下操作:
在您的 Rakefile

require 'active_record'
require 'yaml'

task :default => :migrate 

同一路径上的文件中:

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(File.open('database.log', 'a'))
end

以及您的迁移在 db/migrate 文件夹中。
您不需要整个活动资源和所有 Rails 基础。

I do not have any particular alternative to give you. But if you decide to use the migrations anyway, you must know that you do not need to use the whole rails architecture only for migrations.

As long as you have the active_record gem installed, you can do :
in your Rakefile

require 'active_record'
require 'yaml'

task :default => :migrate 

In a file on the same path :

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(File.open('database.log', 'a'))
end

And your migrations in the db/migrate folder.
You do not need the whole activeresources and all of rails base.

甜`诱少女 2024-08-12 08:48:25

我会用谷歌搜索Python的等价物。迁移很有趣,如果您喜欢这种工作方式并且它有效,那么它当然是合理的。但是,您应该遵循建议并定期检查 schema.rb,而不是依靠迁移来构建生产服务器。

I would google the python equivalents. Migrations are fun, and if you like working that way and it works, then of course it's reasonable. You should follow the advice however and periodically check in schema.rb, rather than counting on migrations to build your production servers.

只是一片海 2024-08-12 08:48:25

我知道你们是一家 Python 商店,但 ActiveRecord Migrations 包有一个 PHP 端口,它非常独立。

https://github.com/ruckus/ruckusing-migrations

I know you are a Python shop but there is a PHP port of the ActiveRecord Migrations package which is very standalone.

https://github.com/ruckus/ruckusing-migrations

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文