mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 10:16:01 +02:00
added rake db:all:setup and friends
This commit is contained in:
parent
545e828fdf
commit
e20e577914
6 changed files with 153 additions and 87 deletions
|
@ -1,5 +1,8 @@
|
||||||
16.01.2015
|
16.01.2015
|
||||||
|
|
||||||
|
* Added new rake tasks: rake db:all:setup to setup all databases
|
||||||
|
Find out more tasks for all databases with rake -T db:all
|
||||||
|
|
||||||
* Staging env added, please change apache conf in staging servers to "RailsEnv staging"
|
* Staging env added, please change apache conf in staging servers to "RailsEnv staging"
|
||||||
Then you need to add or update staging section in
|
Then you need to add or update staging section in
|
||||||
--> config/database.yml
|
--> config/database.yml
|
||||||
|
|
11
README.md
11
README.md
|
@ -37,12 +37,19 @@ Manual demo install and database setup:
|
||||||
cp config/initializers/devise_secret_example.rb.txt config/initializers/devise_secret.rb # and edit
|
cp config/initializers/devise_secret_example.rb.txt config/initializers/devise_secret.rb # and edit
|
||||||
bundle exec rake assets:precompile
|
bundle exec rake assets:precompile
|
||||||
|
|
||||||
Create database manually, example:
|
Create registry database manually, example:
|
||||||
|
|
||||||
create database registry owner registry encoding 'UTF-8' LC_COLLATE 'et_EE.utf8' LC_CTYPE 'et_EE.utf8' template template0;
|
create database registry_production owner registry encoding 'UTF-8' LC_COLLATE 'et_EE.utf8' LC_CTYPE 'et_EE.utf8' template template0;
|
||||||
rake db:schema:load
|
rake db:schema:load
|
||||||
rake db:seeds
|
rake db:seeds
|
||||||
|
|
||||||
|
Or create all databases:
|
||||||
|
|
||||||
|
rake db:all:setup # will create all databases and loads all schemas
|
||||||
|
rake db:all:create # creates all databases
|
||||||
|
rake db:all:schema:load # loads all schemas
|
||||||
|
rake db:all:schema:dump # dumps all schemas
|
||||||
|
|
||||||
Production install (database schema should be loaded and seeds should be present)
|
Production install (database schema should be loaded and seeds should be present)
|
||||||
|
|
||||||
# at your local machine
|
# at your local machine
|
||||||
|
|
72
db/schema.rb
72
db/schema.rb
|
@ -16,7 +16,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
create_table "address_versions", force: true do |t|
|
create_table "address_versions", force: :cascade do |t|
|
||||||
t.string "item_type", null: false
|
t.string "item_type", null: false
|
||||||
t.integer "item_id", null: false
|
t.integer "item_id", null: false
|
||||||
t.string "event", null: false
|
t.string "event", null: false
|
||||||
|
@ -27,7 +27,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "address_versions", ["item_type", "item_id"], name: "index_address_versions_on_item_type_and_item_id", using: :btree
|
add_index "address_versions", ["item_type", "item_id"], name: "index_address_versions_on_item_type_and_item_id", using: :btree
|
||||||
|
|
||||||
create_table "addresses", force: true do |t|
|
create_table "addresses", force: :cascade do |t|
|
||||||
t.integer "contact_id"
|
t.integer "contact_id"
|
||||||
t.integer "country_id"
|
t.integer "country_id"
|
||||||
t.string "city"
|
t.string "city"
|
||||||
|
@ -39,7 +39,15 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.string "street3"
|
t.string "street3"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contact_disclosures", force: true do |t|
|
create_table "cached_nameservers", id: false, force: :cascade do |t|
|
||||||
|
t.string "hostname", limit: 255
|
||||||
|
t.string "ipv4", limit: 255
|
||||||
|
t.string "ipv6", limit: 255
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "cached_nameservers", ["hostname", "ipv4", "ipv6"], name: "index_cached_nameservers_on_hostname_and_ipv4_and_ipv6", unique: true, using: :btree
|
||||||
|
|
||||||
|
create_table "contact_disclosures", force: :cascade do |t|
|
||||||
t.integer "contact_id"
|
t.integer "contact_id"
|
||||||
t.boolean "phone"
|
t.boolean "phone"
|
||||||
t.boolean "fax"
|
t.boolean "fax"
|
||||||
|
@ -51,7 +59,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.boolean "address"
|
t.boolean "address"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contact_statuses", force: true do |t|
|
create_table "contact_statuses", force: :cascade do |t|
|
||||||
t.string "value"
|
t.string "value"
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.integer "contact_id"
|
t.integer "contact_id"
|
||||||
|
@ -59,7 +67,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contact_versions", force: true do |t|
|
create_table "contact_versions", force: :cascade do |t|
|
||||||
t.string "item_type", null: false
|
t.string "item_type", null: false
|
||||||
t.integer "item_id", null: false
|
t.integer "item_id", null: false
|
||||||
t.string "event", null: false
|
t.string "event", null: false
|
||||||
|
@ -70,7 +78,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "contact_versions", ["item_type", "item_id"], name: "index_contact_versions_on_item_type_and_item_id", using: :btree
|
add_index "contact_versions", ["item_type", "item_id"], name: "index_contact_versions_on_item_type_and_item_id", using: :btree
|
||||||
|
|
||||||
create_table "contacts", force: true do |t|
|
create_table "contacts", force: :cascade do |t|
|
||||||
t.string "code"
|
t.string "code"
|
||||||
t.string "type"
|
t.string "type"
|
||||||
t.string "reg_no"
|
t.string "reg_no"
|
||||||
|
@ -89,14 +97,14 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "countries", force: true do |t|
|
create_table "countries", force: :cascade do |t|
|
||||||
t.string "iso"
|
t.string "iso"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "delayed_jobs", force: true do |t|
|
create_table "delayed_jobs", force: :cascade do |t|
|
||||||
t.integer "priority", default: 0, null: false
|
t.integer "priority", default: 0, null: false
|
||||||
t.integer "attempts", default: 0, null: false
|
t.integer "attempts", default: 0, null: false
|
||||||
t.text "handler", null: false
|
t.text "handler", null: false
|
||||||
|
@ -112,7 +120,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
|
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
|
||||||
|
|
||||||
create_table "delegation_signers", force: true do |t|
|
create_table "delegation_signers", force: :cascade do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.string "key_tag"
|
t.string "key_tag"
|
||||||
t.integer "alg"
|
t.integer "alg"
|
||||||
|
@ -120,7 +128,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.string "digest"
|
t.string "digest"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "dnskeys", force: true do |t|
|
create_table "dnskeys", force: :cascade do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.integer "flags"
|
t.integer "flags"
|
||||||
t.integer "protocol"
|
t.integer "protocol"
|
||||||
|
@ -133,7 +141,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.string "ds_digest"
|
t.string "ds_digest"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_contacts", force: true do |t|
|
create_table "domain_contacts", force: :cascade do |t|
|
||||||
t.integer "contact_id"
|
t.integer "contact_id"
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.string "contact_type"
|
t.string "contact_type"
|
||||||
|
@ -142,7 +150,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.string "contact_code_cache"
|
t.string "contact_code_cache"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_status_versions", force: true do |t|
|
create_table "domain_status_versions", force: :cascade do |t|
|
||||||
t.string "item_type", null: false
|
t.string "item_type", null: false
|
||||||
t.integer "item_id", null: false
|
t.integer "item_id", null: false
|
||||||
t.string "event", null: false
|
t.string "event", null: false
|
||||||
|
@ -153,13 +161,13 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "domain_status_versions", ["item_type", "item_id"], name: "index_domain_status_versions_on_item_type_and_item_id", using: :btree
|
add_index "domain_status_versions", ["item_type", "item_id"], name: "index_domain_status_versions_on_item_type_and_item_id", using: :btree
|
||||||
|
|
||||||
create_table "domain_statuses", force: true do |t|
|
create_table "domain_statuses", force: :cascade do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.string "value"
|
t.string "value"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_transfers", force: true do |t|
|
create_table "domain_transfers", force: :cascade do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.string "status"
|
t.string "status"
|
||||||
t.datetime "transfer_requested_at"
|
t.datetime "transfer_requested_at"
|
||||||
|
@ -171,7 +179,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "wait_until"
|
t.datetime "wait_until"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_versions", force: true do |t|
|
create_table "domain_versions", force: :cascade do |t|
|
||||||
t.string "item_type", null: false
|
t.string "item_type", null: false
|
||||||
t.integer "item_id", null: false
|
t.integer "item_id", null: false
|
||||||
t.string "event", null: false
|
t.string "event", null: false
|
||||||
|
@ -183,7 +191,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "domain_versions", ["item_type", "item_id"], name: "index_domain_versions_on_item_type_and_item_id", using: :btree
|
add_index "domain_versions", ["item_type", "item_id"], name: "index_domain_versions_on_item_type_and_item_id", using: :btree
|
||||||
|
|
||||||
create_table "domains", force: true do |t|
|
create_table "domains", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
t.datetime "registered_at"
|
t.datetime "registered_at"
|
||||||
|
@ -200,7 +208,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.string "period_unit", limit: 1
|
t.string "period_unit", limit: 1
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "epp_sessions", force: true do |t|
|
create_table "epp_sessions", force: :cascade do |t|
|
||||||
t.string "session_id"
|
t.string "session_id"
|
||||||
t.text "data"
|
t.text "data"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
|
@ -210,7 +218,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
add_index "epp_sessions", ["session_id"], name: "index_epp_sessions_on_session_id", unique: true, using: :btree
|
add_index "epp_sessions", ["session_id"], name: "index_epp_sessions_on_session_id", unique: true, using: :btree
|
||||||
add_index "epp_sessions", ["updated_at"], name: "index_epp_sessions_on_updated_at", using: :btree
|
add_index "epp_sessions", ["updated_at"], name: "index_epp_sessions_on_updated_at", using: :btree
|
||||||
|
|
||||||
create_table "epp_users", force: true do |t|
|
create_table "epp_users", force: :cascade do |t|
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
t.string "username"
|
t.string "username"
|
||||||
t.string "password"
|
t.string "password"
|
||||||
|
@ -221,7 +229,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "keyrelays", force: true do |t|
|
create_table "keyrelays", force: :cascade do |t|
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.datetime "pa_date"
|
t.datetime "pa_date"
|
||||||
t.string "key_data_flags"
|
t.string "key_data_flags"
|
||||||
|
@ -237,7 +245,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "legal_documents", force: true do |t|
|
create_table "legal_documents", force: :cascade do |t|
|
||||||
t.string "document_type"
|
t.string "document_type"
|
||||||
t.text "body"
|
t.text "body"
|
||||||
t.integer "documentable_id"
|
t.integer "documentable_id"
|
||||||
|
@ -246,7 +254,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "messages", force: true do |t|
|
create_table "messages", force: :cascade do |t|
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
t.string "body"
|
t.string "body"
|
||||||
t.string "attached_obj_type"
|
t.string "attached_obj_type"
|
||||||
|
@ -256,7 +264,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "nameserver_versions", force: true do |t|
|
create_table "nameserver_versions", force: :cascade do |t|
|
||||||
t.string "item_type", null: false
|
t.string "item_type", null: false
|
||||||
t.integer "item_id", null: false
|
t.integer "item_id", null: false
|
||||||
t.string "event", null: false
|
t.string "event", null: false
|
||||||
|
@ -267,7 +275,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "nameserver_versions", ["item_type", "item_id"], name: "index_nameserver_versions_on_item_type_and_item_id", using: :btree
|
add_index "nameserver_versions", ["item_type", "item_id"], name: "index_nameserver_versions_on_item_type_and_item_id", using: :btree
|
||||||
|
|
||||||
create_table "nameservers", force: true do |t|
|
create_table "nameservers", force: :cascade do |t|
|
||||||
t.string "hostname"
|
t.string "hostname"
|
||||||
t.string "ipv4"
|
t.string "ipv4"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
|
@ -276,7 +284,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "registrars", force: true do |t|
|
create_table "registrars", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "reg_no"
|
t.string "reg_no"
|
||||||
t.string "vat_no"
|
t.string "vat_no"
|
||||||
|
@ -287,30 +295,30 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "reserved_domains", force: true do |t|
|
create_table "reserved_domains", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "rights", force: true do |t|
|
create_table "rights", force: :cascade do |t|
|
||||||
t.string "code"
|
t.string "code"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "rights_roles", force: true do |t|
|
create_table "rights_roles", force: :cascade do |t|
|
||||||
t.integer "right_id"
|
t.integer "right_id"
|
||||||
t.integer "role_id"
|
t.integer "role_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "roles", force: true do |t|
|
create_table "roles", force: :cascade do |t|
|
||||||
t.string "code"
|
t.string "code"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "settings", force: true do |t|
|
create_table "settings", force: :cascade do |t|
|
||||||
t.string "var", null: false
|
t.string "var", null: false
|
||||||
t.text "value"
|
t.text "value"
|
||||||
t.integer "thing_id"
|
t.integer "thing_id"
|
||||||
|
@ -321,7 +329,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
|
add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "users", force: true do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "username"
|
t.string "username"
|
||||||
t.string "password"
|
t.string "password"
|
||||||
t.integer "role_id"
|
t.integer "role_id"
|
||||||
|
@ -337,7 +345,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
t.integer "country_id"
|
t.integer "country_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "versions", force: true do |t|
|
create_table "versions", force: :cascade do |t|
|
||||||
t.string "item_type", null: false
|
t.string "item_type", null: false
|
||||||
t.integer "item_id", null: false
|
t.integer "item_id", null: false
|
||||||
t.string "event", null: false
|
t.string "event", null: false
|
||||||
|
@ -348,7 +356,7 @@ ActiveRecord::Schema.define(version: 20150109081914) do
|
||||||
|
|
||||||
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
|
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
|
||||||
|
|
||||||
create_table "zonefile_settings", force: true do |t|
|
create_table "zonefile_settings", force: :cascade do |t|
|
||||||
t.string "origin"
|
t.string "origin"
|
||||||
t.integer "ttl"
|
t.integer "ttl"
|
||||||
t.integer "refresh"
|
t.integer "refresh"
|
||||||
|
|
28
db/whois_schema.rb
Normal file
28
db/whois_schema.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
# 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: 20150113113236) do
|
||||||
|
|
||||||
|
# These are extensions that must be enabled in order to support this database
|
||||||
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
create_table "domains", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.text "whois_body"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "domains", ["name"], name: "index_domains_on_name", using: :btree
|
||||||
|
|
||||||
|
end
|
73
lib/tasks/db.rake
Normal file
73
lib/tasks/db.rake
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
namespace :db do
|
||||||
|
def databases
|
||||||
|
@db ||= ["#{Rails.env}", "api_log_#{Rails.env}", "whois_#{Rails.env}"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def schema_file(db)
|
||||||
|
case db
|
||||||
|
when databases.first
|
||||||
|
'schema.rb'
|
||||||
|
when databases.second
|
||||||
|
'api_log_schema.rb'
|
||||||
|
when databases.third
|
||||||
|
'whois_schema.rb'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :all do
|
||||||
|
desc 'Create all databases: registry, api_log and whois'
|
||||||
|
task :setup => [:environment] do
|
||||||
|
Rake::Task['db:all:create'].invoke
|
||||||
|
Rake::Task['db:all:schema:load'].invoke
|
||||||
|
Rake::Task['db:seed'].invoke
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Create all databases: registry, api_log and whois'
|
||||||
|
task :create => [:environment] do
|
||||||
|
databases.each do |name|
|
||||||
|
begin
|
||||||
|
conf = ActiveRecord::Base.configurations
|
||||||
|
ActiveRecord::Base.clear_all_connections!
|
||||||
|
ActiveRecord::Base.connection.create_database(conf[name]['database'], conf[name])
|
||||||
|
rescue => e
|
||||||
|
puts "\n#{e}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :schema do
|
||||||
|
desc 'Schema load for all databases: registry, api_log and whois'
|
||||||
|
task :load => [:environment] do
|
||||||
|
databases.each do |name|
|
||||||
|
begin
|
||||||
|
puts "\n---------------------------- #{name} ----------------------------------------\n"
|
||||||
|
ActiveRecord::Base.establish_connection(name)
|
||||||
|
if ActiveRecord::Base.connection.table_exists?('schema_migrations')
|
||||||
|
puts 'Found tables, skip schema load!'
|
||||||
|
else
|
||||||
|
load("#{Rails.root}/db/#{schema_file(name)}")
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
puts "\n#{e}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Schema load for all databases: registry, api_log and whois'
|
||||||
|
task :dump => [:environment] do
|
||||||
|
databases.each do |name|
|
||||||
|
begin
|
||||||
|
puts "\n---------------------------- #{name} ----------------------------------------\n"
|
||||||
|
filename = "#{Rails.root}/db/#{schema_file(name)}"
|
||||||
|
File.open(filename, 'w:utf-8') do |file|
|
||||||
|
ActiveRecord::Base.establish_connection(name)
|
||||||
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
puts "\n#{e}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,53 +0,0 @@
|
||||||
DATABASES = [
|
|
||||||
{ database: 'whois_public', host: 'localhost', adapter: 'postgresql', encoding: 'unicode',
|
|
||||||
pool: '5', username: 'whois', password: 'test', port: '5432' },
|
|
||||||
{ database: 'whois_private', host: 'localhost', adapter: 'postgresql', encoding: 'unicode',
|
|
||||||
pool: '5', username: 'whois', password: 'test', port: '5432' }
|
|
||||||
]
|
|
||||||
|
|
||||||
namespace :whois do
|
|
||||||
task :load_config do
|
|
||||||
require 'active_record'
|
|
||||||
require 'pg'
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Create whois databases'
|
|
||||||
task create: [:load_config] do
|
|
||||||
DATABASES.each do |conf|
|
|
||||||
create_database(conf)
|
|
||||||
migrate
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
task 'Migrate whois databases'
|
|
||||||
task migrate: [:load_config] do
|
|
||||||
DATABASES.each do |conf|
|
|
||||||
ActiveRecord::Base.establish_connection(conf)
|
|
||||||
migrate
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_database(conf)
|
|
||||||
ActiveRecord::Base.establish_connection(conf.merge(database: 'postgres'))
|
|
||||||
ActiveRecord::Base.connection.create_database(conf[:database])
|
|
||||||
ActiveRecord::Base.establish_connection(conf)
|
|
||||||
end
|
|
||||||
|
|
||||||
def migrate
|
|
||||||
CreateWhoisBase.up
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class CreateWhoisBase < ActiveRecord::Migration
|
|
||||||
def self.up
|
|
||||||
create_table :domains do |t|
|
|
||||||
t.string :name
|
|
||||||
t.text :body
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.down
|
|
||||||
drob_table :domains
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue