没有rails的ActiveRecord Schema Dump

Chr*_*ine 4 ruby firebird

在rails中你可以设置一个rails应用程序,分配正确的数据库驱动程序(我需要firebird/fb),然后做一个rake db:schema:dump几乎开箱即用.

我正在尝试为我的数据库架构进行版本控制.我怎样才能制作一个需要activerecord和fb库的ruby脚本并实现相同的功能.我不需要整个rails应用程序.我想要的只是一个提取架构的一致脚本.

Pat*_*ity 8

查看任务的来源db:schema:dump,以下代码可以帮助您入门:

require 'active_record'
require 'active_record/schema_dumper'
require 'activerecord-fb-adapter'

filename = './schema.rb'

ActiveRecord::Base.establish_connection(
  adapter: 'fb',
  database: 'db/development.fdb',
  username: 'SYSDBA',
  password: 'masterkey',
  host: 'localhost',
  encoding: 'UTF-8',
  create: true
)

File.open(filename, "w:utf-8") do |file|
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
Run Code Online (Sandbox Code Playgroud)