From 73c245b63d678b5a412945cc3ca4573e682c9ead Mon Sep 17 00:00:00 2001
From: data-repo application owner <hydra@hydravm>
Date: Tue, 21 Feb 2017 22:14:02 +0000
Subject: [PATCH] move noid minter to db

---
 config/initializers/active_fedora-noid.rb        |  5 +++++
 ...te_minter_states.active_fedora_noid_engine.rb | 16 ++++++++++++++++
 ...e_random_to_rand.active_fedora_noid_engine.rb |  7 +++++++
 db/schema.rb                                     | 13 ++++++++++++-
 spec/spec_helper.rb                              |  6 ++++++
 5 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 config/initializers/active_fedora-noid.rb
 create mode 100644 db/migrate/20170221215212_create_minter_states.active_fedora_noid_engine.rb
 create mode 100644 db/migrate/20170221215213_rename_minter_state_random_to_rand.active_fedora_noid_engine.rb

diff --git a/config/initializers/active_fedora-noid.rb b/config/initializers/active_fedora-noid.rb
new file mode 100644
index 0000000..8e7362f
--- /dev/null
+++ b/config/initializers/active_fedora-noid.rb
@@ -0,0 +1,5 @@
+require 'active_fedora/noid'
+
+ActiveFedora::Noid.configure do |config|
+  config.minter_class = ActiveFedora::Noid::Minter::Db
+end
diff --git a/db/migrate/20170221215212_create_minter_states.active_fedora_noid_engine.rb b/db/migrate/20170221215212_create_minter_states.active_fedora_noid_engine.rb
new file mode 100644
index 0000000..e9c86b8
--- /dev/null
+++ b/db/migrate/20170221215212_create_minter_states.active_fedora_noid_engine.rb
@@ -0,0 +1,16 @@
+# This migration comes from active_fedora_noid_engine (originally 20160610010003)
+# frozen_string_literal: true
+class CreateMinterStates < ActiveRecord::Migration
+  def change
+    create_table :minter_states do |t|
+      t.string :namespace, null: false, default: 'default'
+      t.string :template, null: false
+      t.text :counters
+      t.bigint :seq, default: 0
+      t.binary :random
+      t.timestamps null: false
+    end
+    # Use both model and DB-level constraints for consistency while scaling horizontally
+    add_index :minter_states, :namespace, unique: true
+  end
+end
diff --git a/db/migrate/20170221215213_rename_minter_state_random_to_rand.active_fedora_noid_engine.rb b/db/migrate/20170221215213_rename_minter_state_random_to_rand.active_fedora_noid_engine.rb
new file mode 100644
index 0000000..6a14eee
--- /dev/null
+++ b/db/migrate/20170221215213_rename_minter_state_random_to_rand.active_fedora_noid_engine.rb
@@ -0,0 +1,7 @@
+# This migration comes from active_fedora_noid_engine (originally 20161021203429)
+# frozen_string_literal: true
+class RenameMinterStateRandomToRand < ActiveRecord::Migration
+  def change
+    rename_column :minter_states, :random, :rand
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c9417f2..4306075 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20170215173933) do
+ActiveRecord::Schema.define(version: 20170221215213) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -177,6 +177,17 @@ ActiveRecord::Schema.define(version: 20170215173933) do
     t.index ["receiver_id", "receiver_type"], name: "index_mailboxer_receipts_on_receiver_id_and_receiver_type", using: :btree
   end
 
+  create_table "minter_states", force: :cascade do |t|
+    t.string   "namespace",  default: "default", null: false
+    t.string   "template",                       null: false
+    t.text     "counters"
+    t.bigint   "seq",        default: 0
+    t.binary   "rand"
+    t.datetime "created_at",                     null: false
+    t.datetime "updated_at",                     null: false
+    t.index ["namespace"], name: "index_minter_states_on_namespace", unique: true, using: :btree
+  end
+
   create_table "permission_template_accesses", force: :cascade do |t|
     t.integer  "permission_template_id"
     t.string   "agent_type"
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 836b3cd..912924d 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -34,6 +34,7 @@ require 'capybara/rails'
 #require 'equivalent-xml/rspec_matchers'
 require 'database_cleaner'
 require 'support/features'
+require 'active_fedora/noid/rspec'
 #require 'support/backport_test_helpers'
 #require 'support/rake'
 require 'byebug' unless ENV['TRAVIS']
@@ -106,6 +107,8 @@ end
 
 require 'active_fedora/cleaner'
 RSpec.configure do |config|
+  include ActiveFedora::Noid::RSpec
+
   config.expect_with :rspec do |c|
     c.syntax = :expect
   end
@@ -116,6 +119,7 @@ RSpec.configure do |config|
   config.use_transactional_fixtures = false
 
   config.before :suite do
+    disable_production_minter!
     DatabaseCleaner.clean_with(:truncation)
   end
 
@@ -145,6 +149,8 @@ RSpec.configure do |config|
     visit "/assets/application.js"
   end
 
+  config.after(:suite)  { enable_production_minter! }
+
   config.after do
     DatabaseCleaner.clean
   end
-- 
GitLab