ActiveRecord circuit diagram without rails

In rails, you can configure the rails application, assign the correct db driver (I need firebird / fb), and then make rake db: schema: dump pretty much out of the box.

I am trying to make a version control for my database schema. How can I just make a ruby โ€‹โ€‹script that requires the activerecord and fb libraries and achieve the same. I do not need an application for all rails. All I want is a sequential script to extract the circuit.

+4
source share
2 answers

Considering the source of the taskdb:schema:dump , you should run the following code:

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
+8
source

- , firebird/fb.

require "yaml"
require "active_record"

include ActiveRecord
include ActiveRecord::Tasks

ActiveRecord::Migrator.migrations_path='./db/migrate'

DatabaseTasks.db_dir = './db'

db_config_file = "./config/database.yml"
db_config = YAML.load_file(db_config_file)
db_type = 'development'
db_object = db_config[db_type]

@sldbtask = SQLiteDatabaseTasks.new(db_object, './')

unless File.exist?(db_object['database'])
  @sldbtask.create
  @sldbtask.connection
  # try different migation versions
  migration_version = 0
  ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_path, migration_version)
end 

unless File.exist?('./db/schema.rb')
  #DatabaseTasks.check_schema_file('./db/schema.rb')
  File.open('./db/schema.rb', "w:utf-8") do |file|
    @sldbtask.establish_connection(db_object)
    ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
  end
end

, , Rails-, . , , , , . , , . .

0

All Articles