diff options
| author | mokha <mokha@cisco.com> | 2018-07-12 15:14:05 -0600 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2018-07-12 15:14:05 -0600 |
| commit | 0624eb1362661f5aca9c36d6c42d5f9660824297 (patch) | |
| tree | b496703c030698f508760d23545fdac2b815401c | |
| parent | 8c43f71cc6019ccb12b8a8e995642d212bba23c7 (diff) | |
create legacy business and new organization models.
| -rw-r--r-- | app/models/business.rb | 2 | ||||
| -rw-r--r-- | app/models/legacy_record.rb | 4 | ||||
| -rw-r--r-- | app/models/organization.rb | 2 | ||||
| -rwxr-xr-x | bin/setup | 1 | ||||
| -rw-r--r-- | config/database_legacy.yml | 25 | ||||
| -rw-r--r-- | config/initializers/legacy_dataase.rb | 1 | ||||
| -rw-r--r-- | db/migrate/20180712210517_organization.rb | 9 | ||||
| -rw-r--r-- | db/schema.rb | 23 | ||||
| -rw-r--r-- | db_legacy/migrate/20180712210523_business.rb | 9 | ||||
| -rw-r--r-- | db_legacy/schema.rb | 23 | ||||
| -rw-r--r-- | db_legacy/seeds.rb | 7 | ||||
| -rw-r--r-- | lib/tasks/legacy.rake | 75 |
12 files changed, 181 insertions, 0 deletions
diff --git a/app/models/business.rb b/app/models/business.rb new file mode 100644 index 0000000..11e67ad --- /dev/null +++ b/app/models/business.rb @@ -0,0 +1,2 @@ +class Business < LegacyRecord +end diff --git a/app/models/legacy_record.rb b/app/models/legacy_record.rb new file mode 100644 index 0000000..bb1f09e --- /dev/null +++ b/app/models/legacy_record.rb @@ -0,0 +1,4 @@ +class LegacyRecord < ActiveRecord::Base + establish_connection Rails.configuration.x.legacy[Rails.env] + self.abstract_class = true +end diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 0000000..b27a6b4 --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,2 @@ +class Organization < ApplicationRecord +end @@ -27,6 +27,7 @@ chdir APP_ROOT do puts "\n== Preparing database ==" system! 'bin/rails db:setup' + system! 'bin/rails legacy:db:setup' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/config/database_legacy.yml b/config/database_legacy.yml new file mode 100644 index 0000000..5122319 --- /dev/null +++ b/config/database_legacy.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/legacy_development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/legacy_test.sqlite3 + +production: + <<: *default + database: db/legacy_production.sqlite3 diff --git a/config/initializers/legacy_dataase.rb b/config/initializers/legacy_dataase.rb new file mode 100644 index 0000000..d0846d9 --- /dev/null +++ b/config/initializers/legacy_dataase.rb @@ -0,0 +1 @@ +Rails.configuration.x.legacy = YAML.load(ERB.new(IO.read(Rails.root.join("config","database_legacy.yml"))).result) diff --git a/db/migrate/20180712210517_organization.rb b/db/migrate/20180712210517_organization.rb new file mode 100644 index 0000000..fbcf016 --- /dev/null +++ b/db/migrate/20180712210517_organization.rb @@ -0,0 +1,9 @@ +class Organization < ActiveRecord::Migration[5.2] + def change + create_table :organizations do |t| + t.string :uuid, index: true + t.string :name + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..fb73771 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,23 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2018_07_12_210517) do + + create_table "organizations", force: :cascade do |t| + t.string "uuid" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["uuid"], name: "index_organizations_on_uuid" + end + +end diff --git a/db_legacy/migrate/20180712210523_business.rb b/db_legacy/migrate/20180712210523_business.rb new file mode 100644 index 0000000..512a3ad --- /dev/null +++ b/db_legacy/migrate/20180712210523_business.rb @@ -0,0 +1,9 @@ +class Business < ActiveRecord::Migration[4.2] + def change + create_table :businesses do |t| + t.string :uuid, index: true + t.string :name + t.timestamps + end + end +end diff --git a/db_legacy/schema.rb b/db_legacy/schema.rb new file mode 100644 index 0000000..75b9ea3 --- /dev/null +++ b/db_legacy/schema.rb @@ -0,0 +1,23 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2018_07_12_210523) do + + create_table "businesses", force: :cascade do |t| + t.string "uuid" + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + t.index ["uuid"], name: "index_businesses_on_uuid" + end + +end diff --git a/db_legacy/seeds.rb b/db_legacy/seeds.rb new file mode 100644 index 0000000..1beea2a --- /dev/null +++ b/db_legacy/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/lib/tasks/legacy.rake b/lib/tasks/legacy.rake new file mode 100644 index 0000000..78151c0 --- /dev/null +++ b/lib/tasks/legacy.rake @@ -0,0 +1,75 @@ +namespace :legacy do + namespace :db do |name_space| + task :drop do + Rake::Task["db:drop"].invoke + end + + task :create do + Rake::Task["db:create"].invoke + end + + task :setup do + Rake::Task["db:setup"].invoke + end + + task :migrate do + Rake::Task["db:migrate"].invoke + end + + task :rollback do + Rake::Task["db:rollback"].invoke + end + + task :seed do + Rake::Task["db:seed"].invoke + end + + task :version do + Rake::Task["db:version"].invoke + end + + namespace :schema do + task :load do + Rake::Task["db:schema:load"].invoke + end + + task :dump do + Rake::Task["db:schema:dump"].invoke + end + end + + namespace :test do + task :prepare do + Rake::Task["db:test:prepare"].invoke + end + end + + # append and prepend proper tasks to all the tasks defined here above + name_space.tasks.each do |task| + task.enhance ["legacy:set_custom_config"] do + Rake::Task["legacy:revert_to_original_config"].invoke + end + end + end + + task :set_custom_config do + # save current vars + @original_config = { + env_schema: 'db/schema.rb', + config: Rails.application.config.dup + } + + # set config variables for custom database + ENV['SCHEMA'] = "db_legacy/schema.rb" + Rails.application.config.paths['db'] = ["db_legacy"] + Rails.application.config.paths['db/migrate'] = ["db_legacy/migrate"] + Rails.application.config.paths['db/seeds'] = ["db_legacy/seeds.rb"] + Rails.application.config.paths['config/database'] = ["config/database_legacy.yml"] + end + + task :revert_to_original_config do + # reset config variables to original values + ENV['SCHEMA'] = @original_config[:env_schema] + Rails.application.config = @original_config[:config] + end +end |
