In rails you can setup a rails app, assign the right db driver (I need firebird/fb) and then do a rake db:schema:dump pretty much out of the box.
I'm trying to do a version control for my database schema. How can I just make a ruby script that requires activerecord and fb libraries and achieve the same thing. I dont' need an entire rails app. All I want is a consistent script to extract the schema.
Looking at the source of the db:schema:dump
task, the following code should get you started:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With