kithe 2.0.0.pre.alpha2 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/app/indexing/kithe/indexable/record_index_updater.rb +1 -1
  4. data/app/jobs/kithe/create_derivatives_job.rb +2 -2
  5. data/app/models/kithe/asset.rb +82 -154
  6. data/app/models/kithe/asset/derivative_creator.rb +32 -62
  7. data/app/models/kithe/asset/derivative_definition.rb +12 -13
  8. data/app/models/kithe/asset/set_shrine_uploader.rb +64 -0
  9. data/app/models/kithe/collection.rb +0 -6
  10. data/app/models/kithe/model.rb +0 -21
  11. data/app/models/kithe/work.rb +0 -5
  12. data/app/uploaders/kithe/asset_uploader.rb +15 -78
  13. data/lib/kithe.rb +22 -20
  14. data/{app/models → lib}/kithe/config_base.rb +6 -1
  15. data/lib/kithe/engine.rb +14 -3
  16. data/lib/kithe/indexable_settings.rb +1 -1
  17. data/lib/kithe/patch_fx.rb +39 -0
  18. data/lib/kithe/version.rb +4 -1
  19. data/lib/shrine/plugins/kithe_checksum_signatures.rb +41 -0
  20. data/lib/shrine/plugins/kithe_controllable_backgrounding.rb +53 -0
  21. data/lib/shrine/plugins/kithe_derivative_definitions.rb +101 -0
  22. data/lib/shrine/plugins/kithe_derivatives.rb +54 -0
  23. data/lib/shrine/plugins/kithe_determine_mime_type.rb +39 -0
  24. data/lib/shrine/plugins/kithe_persisted_derivatives.rb +161 -0
  25. data/lib/shrine/plugins/kithe_promotion_callbacks.rb +4 -0
  26. data/lib/shrine/plugins/kithe_promotion_directives.rb +33 -3
  27. data/lib/shrine/plugins/kithe_storage_location.rb +53 -4
  28. data/lib/tasks/kithe_tasks.rake +22 -15
  29. data/spec/dummy/app/models/plain_active_record.rb +3 -0
  30. data/spec/dummy/config/database.yml +6 -0
  31. data/spec/dummy/db/schema.rb +102 -0
  32. data/spec/dummy/log/development.log +3616 -0
  33. data/spec/dummy/log/test.log +86464 -0
  34. data/spec/dummy/tmp/development_secret.txt +1 -1
  35. data/spec/indexing/indexable_spec.rb +1 -1
  36. data/spec/models/kithe/asset/asset_derivatives_spec.rb +137 -0
  37. data/spec/models/kithe/asset/asset_promotion_hooks_spec.rb +26 -5
  38. data/spec/models/kithe/asset/set_shrine_uploader_spec.rb +39 -0
  39. data/spec/models/kithe/asset_spec.rb +9 -59
  40. data/spec/models/kithe/model_spec.rb +0 -32
  41. data/spec/models/kithe_spec.rb +10 -0
  42. data/spec/shrine/kithe_accept_remote_url_spec.rb +49 -0
  43. data/spec/shrine/kithe_checksum_signatures_spec.rb +63 -0
  44. data/spec/shrine/kithe_derivative_definitions_spec.rb +303 -0
  45. data/spec/shrine/kithe_persisted_derivatives_spec.rb +424 -0
  46. data/spec/shrine/kithe_storage_location_spec.rb +43 -15
  47. data/spec/spec_helper.rb +0 -19
  48. data/spec/test_support/images/3x3_pixel.jpg +0 -0
  49. data/spec/test_support/shrine_spec_support.rb +2 -1
  50. metadata +60 -36
  51. data/app/models/kithe/asset/derivative_updater.rb +0 -119
  52. data/app/models/kithe/derivative.rb +0 -15
  53. data/app/uploaders/kithe/derivative_uploader.rb +0 -48
  54. data/spec/dummy/db/structure.sql +0 -309
  55. data/spec/models/kithe/asset/asset_create_derivatives_spec.rb +0 -320
  56. data/spec/models/kithe/derivative_spec.rb +0 -168
@@ -24,6 +24,10 @@ class Shrine
24
24
  # was convenient and avoided confusion to isolate wrapping in a class method that can be used
25
25
  # anywhere, and only depends on args passed in, no implicit state anywhere.
26
26
  class KithePromotionCallbacks
27
+ def self.load_dependencies(uploader, *)
28
+ uploader.plugin :kithe_promotion_directives
29
+ end
30
+
27
31
  # promotion logic differs somewhat in different modes of use (bg or inline promotion),
28
32
  # so we extract the wrapping logic here. Exactly what the logic wrapped is can
29
33
  # differ.
@@ -89,15 +89,15 @@ class Shrine
89
89
  # some_model.save!
90
90
  def set_promotion_directives(hash)
91
91
  # ActiveJob sometimes has trouble if there are symbols in there, somewhat
92
- # unpredictably.
93
- hash = hash.collect { |k, v| [k.to_s, v === Symbol ? v.to_s : v.to_s]}.to_h
92
+ # unpredictably. And for other reasons, standardize on everything a string.
93
+ hash = hash.collect { |k, v| [k.to_s, v.to_s]}.to_h
94
94
 
95
95
  unrecognized = hash.keys.collect(&:to_sym) - KithePromotionDirectives.allowed_promotion_directives
96
96
  unless unrecognized.length == 0
97
97
  raise ArgumentError.new("Unrecognized promotion directive key: #{unrecognized.join('')}")
98
98
  end
99
99
 
100
- promotion_directives.merge!(hash)
100
+ context[:promotion_directives] = promotion_directives.merge(hash).freeze
101
101
  end
102
102
 
103
103
  # context[:promotion_directives], lazily initializing to hash for convenience.
@@ -105,6 +105,36 @@ class Shrine
105
105
  context[:promotion_directives] ||= {}
106
106
  end
107
107
  end
108
+
109
+ # VERY hacky way to try to preserve promotion_directives on Asset.reload.
110
+ #
111
+ # This may not be necessary in a future shrine version if shrine resolves
112
+ # issue. See: https://github.com/shrinerb/shrine/issues/463
113
+ #
114
+ # It is the activerecord plugin implementation that erases all shrine context
115
+ # (and thus our promotion directives) on reload.
116
+ # https://github.com/shrinerb/shrine/blob/b5fc2e1432e51e6fde87c120bc6cf6abeb286c68/lib/shrine/plugins/activerecord.rb#L56-L60
117
+ #
118
+ # It is quite tricky to override the activerecord plugin's own override, because
119
+ # of the way shrine does these overrides. We've figured out a pretty crazy way
120
+ # below.
121
+ module AttachmentMethods
122
+ def included(model)
123
+ super
124
+
125
+ original_reload = instance_method(:reload)
126
+
127
+ define_method :reload do |*args|
128
+ previous_promotion_directives = file_attacher.promotion_directives
129
+
130
+ result = original_reload.bind(self).call(*args)
131
+ file_attacher.set_promotion_directives(previous_promotion_directives)
132
+
133
+ result
134
+ end
135
+ end
136
+ end
137
+
108
138
  end
109
139
  register_plugin(:kithe_promotion_directives, KithePromotionDirectives)
110
140
  end
@@ -2,25 +2,74 @@ require 'shrine/storage/url'
2
2
 
3
3
  class Shrine
4
4
  module Plugins
5
- # Set file location to "asset/#{asset_uuid_id}/#{unique_file_id}" -- regardless of
6
- # asset sub-class, since they all have unique ids, just all under asset/.
5
+ # Set custom storage locations/paths for both the original file which is the main
6
+ # file in the shrine attachment at Asset#file, and any shrine derivatives.
7
+ #
8
+ # Shrine's default is to just put both of these at top-level `[randomID].suffix`. We
9
+ # instead:
10
+ #
11
+ # ## Original file
12
+ #
13
+ # Stored at `asset/#{asset_uuid_id}/#{unique_file_id}.suffix` -- regardless of
14
+ # asset sub-class, since they all have unique ids, just all under asset/. (In retrospect,
15
+ # maybe shoudl have left `asset/` off, and let consumer specify a prefix when configuring
16
+ # storage).
7
17
  #
8
18
  # If no Asset pk is available (direct upload or unsaved Asset), will be stored just
9
19
  # under "asset/#{unique_file_id}.#{suffix}"
10
20
  #
11
21
  # We are choosing to store under Asset UUID PK instead of friendlier_id, friendlier_id
12
22
  # is good for public URLs and UI, but actual PK is more reliable/immutable.
23
+ #
24
+ # ## Derivatives
25
+ #
26
+ # Stored at `#{asset_uuid_id}/derivative_key/#{unique_file_id}.suffix`.
27
+ #
28
+ # If asset uuid pk is not available, will raise a TypeError and refuse to store
29
+ # derivative. (This may have to be thought through more.)
30
+ #
31
+ # If you want an additional prefix, supply it hwen configuring kithe_derivatives
32
+ # storage.
13
33
  module KitheStorageLocation
14
34
  module InstanceMethods
15
- def generate_location(io, context)
35
+ def generate_location(io, derivative: nil, **context)
36
+ original = super
37
+
38
+ if derivative
39
+ _kithe_generate_derivative_location(io, original: original, derivative: derivative, **context)
40
+ else
41
+ _kithe_generate_main_location(io, original: original, **context)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def _kithe_generate_main_location(io, original:, **context)
16
48
  # If it doesn't have a id, we're probably storing in cache, possibly as part
17
49
  # of direct upload endpoint. A better path will be created on store.
18
50
  id = context[:record].id if context[:record].respond_to?(:id)
19
51
 
20
- basename = super
52
+ basename = original
21
53
 
22
54
  ["asset", id, basename].compact.join("/")
23
55
  end
56
+
57
+ # Usually NOT in the same bucket/prefix as the originals/main attachments.
58
+ # You can set a prefix yourself in your shrine storage config if you want them
59
+ # on the same bucket, and probably should.
60
+ def _kithe_generate_derivative_location(io, original:, derivative:, record:, **context)
61
+ # for now to be save, insist the record exist and have an id so we can get the
62
+ # correct derivative location. This is consistent with kithe 1.x behavior. We can
63
+ # enhance later maybe.
64
+ unless record && record.id
65
+ raise TypeError.new("Can't determine correct derivative location without a persisted record. Record: #{record}")
66
+ end
67
+ unless derivative && original
68
+ raise ArgumentError.new("Missing required argument")
69
+ end
70
+
71
+ [record.id, derivative, original].join("/")
72
+ end
24
73
  end
25
74
  end
26
75
  register_plugin(:kithe_storage_location, KitheStorageLocation)
@@ -8,11 +8,10 @@ namespace :kithe do
8
8
  options = {}
9
9
  OptionParser.new do |opts|
10
10
  opts.banner = "Usage: ./bin/rake kithe:create_derivatives -- [options]"
11
- opts.on("--derivatives TYPES", "comma-seperated list of type keys") { |ids| options[:derivative_keys] = ids.split(",")}
12
- opts.on("--lazy","Lazy create") { options[:lazy] = true }
13
- opts.on("--asset-id FRIENDLIER_IDS", "comma-seperated list of asset (friendlier) ids") { |ids| options[:asset_ids] = ids.split(",") }
14
- opts.on("--work-id FRIENDLIER_IDS", "comma-seperated list of work (friendlier) ids") { |ids| options[:work_ids] = ids.split(",") }
15
- opts.on("--mark-derivatives-created", "set derivatives_created? flag on assets") { |ids| options[:mark_derivatives_created] = true }
11
+ opts.on("--derivatives=TYPES", "comma-seperated list of type keys") { |ids| options[:derivative_keys] = ids.split(",")}
12
+ opts.on("--lazy", "Lazy create") { options[:lazy] = true }
13
+ opts.on("--asset-id=FRIENDLIER_IDS", "comma-seperated list of asset (friendlier) ids") { |ids| options[:asset_ids] = ids.split(",") }
14
+ opts.on("--work-id=FRIENDLIER_IDS", "comma-seperated list of work (friendlier) ids") { |ids| options[:work_ids] = ids.split(",") }
16
15
  end.tap do |parser|
17
16
  parser.parse!(parser.order(ARGV) {})
18
17
  end
@@ -22,17 +21,20 @@ namespace :kithe do
22
21
  scope = scope.joins(:parent).where("parents_kithe_models.friendlier_id": options[:work_ids])
23
22
  end
24
23
  scope = scope.where(friendlier_id: options[:asset_ids]) if options[:asset_ids]
25
- scope = scope.includes(:derivatives) if options[:lazy]
26
24
 
27
25
  progress_bar = ProgressBar.create(total: scope.count, format: Kithe::STANDARD_PROGRESS_BAR_FORMAT)
28
26
 
29
27
  scope.find_each do |asset|
30
- progress_bar.title = asset.friendlier_id
31
- asset.create_derivatives(
32
- only: options[:derivative_keys],
33
- lazy: !!options[:lazy],
34
- mark_created: options[:mark_derivatives_created]
35
- )
28
+ begin
29
+ progress_bar.title = asset.friendlier_id
30
+ asset.create_derivatives(
31
+ only: options[:derivative_keys],
32
+ lazy: !!options[:lazy]
33
+ )
34
+ rescue Shrine::FileNotFound => e
35
+ progress_bar.log("original missing for #{asset.friendlier_id}")
36
+ # it's cool, skip it
37
+ end
36
38
  progress_bar.increment
37
39
  end
38
40
  end
@@ -43,9 +45,14 @@ namespace :kithe do
43
45
  task :lazy_defaults => :environment do
44
46
  progress_bar = ProgressBar.create(total: Kithe::Asset.count, format: Kithe::STANDARD_PROGRESS_BAR_FORMAT)
45
47
 
46
- Kithe::Asset.includes(:derivatives).find_each do |asset|
47
- progress_bar.title = asset.friendlier_id
48
- asset.create_derivatives(lazy: true)
48
+ Kithe::Asset.find_each do |asset|
49
+ begin
50
+ progress_bar.title = asset.friendlier_id
51
+ asset.create_derivatives(lazy: true)
52
+ rescue Shrine::FileNotFound => e
53
+ progress_bar.log("original missing for #{asset.friendlier_id}")
54
+ # it's cool, skip it
55
+ end
49
56
  progress_bar.increment
50
57
  end
51
58
  end
@@ -0,0 +1,3 @@
1
+ # A Plain Old ActiveRecord (ha) for tests.
2
+ class PlainActiveRecord < ApplicationRecord
3
+ end
@@ -58,6 +58,12 @@ development:
58
58
  test:
59
59
  <<: *default
60
60
  database: kithe_test
61
+ # ENV POSTGRES_USER and POSTGRES_PASSWORD set in CI, usually empty
62
+ # in local tests, where pg is usually running with no authentication required
63
+ host: <%= ENV['POSTGRES_HOST'] %>
64
+ username: <%= ENV['POSTGRES_USER'] %>
65
+ password: <%= ENV['POSTGRES_PASSWORD'] %>
66
+
61
67
 
62
68
  # As with config/secrets.yml, you never want to store sensitive information,
63
69
  # like your database password, in your source code. If your source code is
@@ -0,0 +1,102 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2019_04_04_144551) do
14
+
15
+ # These are extensions that must be enabled in order to support this database
16
+ enable_extension "pgcrypto"
17
+ enable_extension "plpgsql"
18
+
19
+
20
+ create_function :kithe_models_friendlier_id_gen, sql_definition: <<-SQL
21
+ CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
22
+ RETURNS text
23
+ LANGUAGE plpgsql
24
+ AS $function$
25
+ DECLARE
26
+ new_id_int bigint;
27
+ new_id_str character varying := '';
28
+ done bool;
29
+ tries integer;
30
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
31
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
32
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
33
+ alphabet_length integer := array_length(alphabet, 1);
34
+
35
+ BEGIN
36
+ done := false;
37
+ tries := 0;
38
+ WHILE (NOT done) LOOP
39
+ tries := tries + 1;
40
+ IF (tries > 3) THEN
41
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
42
+ END IF;
43
+
44
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
45
+
46
+ -- convert bigint to a Base-36 alphanumeric string
47
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
48
+ -- https://gist.github.com/btbytes/7159902
49
+ WHILE new_id_int != 0 LOOP
50
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
51
+ new_id_int := new_id_int / alphabet_length;
52
+ END LOOP;
53
+
54
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
55
+ END LOOP;
56
+ RETURN new_id_str;
57
+ END;
58
+ $function$
59
+ SQL
60
+ create_table "kithe_derivatives", force: :cascade do |t|
61
+ t.string "key", null: false
62
+ t.jsonb "file_data"
63
+ t.uuid "asset_id", null: false
64
+ t.datetime "created_at", null: false
65
+ t.datetime "updated_at", null: false
66
+ t.index ["asset_id", "key"], name: "index_kithe_derivatives_on_asset_id_and_key", unique: true
67
+ t.index ["asset_id"], name: "index_kithe_derivatives_on_asset_id"
68
+ end
69
+
70
+ create_table "kithe_model_contains", id: false, force: :cascade do |t|
71
+ t.uuid "containee_id"
72
+ t.uuid "container_id"
73
+ t.index ["containee_id"], name: "index_kithe_model_contains_on_containee_id"
74
+ t.index ["container_id"], name: "index_kithe_model_contains_on_container_id"
75
+ end
76
+
77
+ create_table "kithe_models", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
78
+ t.string "title", null: false
79
+ t.string "type", null: false
80
+ t.integer "position"
81
+ t.jsonb "json_attributes"
82
+ t.datetime "created_at", null: false
83
+ t.datetime "updated_at", null: false
84
+ t.uuid "parent_id"
85
+ t.string "friendlier_id", default: -> { "kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint)" }, null: false
86
+ t.jsonb "file_data"
87
+ t.uuid "representative_id"
88
+ t.uuid "leaf_representative_id"
89
+ t.integer "kithe_model_type", null: false
90
+ t.index ["friendlier_id"], name: "index_kithe_models_on_friendlier_id", unique: true
91
+ t.index ["leaf_representative_id"], name: "index_kithe_models_on_leaf_representative_id"
92
+ t.index ["parent_id"], name: "index_kithe_models_on_parent_id"
93
+ t.index ["representative_id"], name: "index_kithe_models_on_representative_id"
94
+ end
95
+
96
+ add_foreign_key "kithe_derivatives", "kithe_models", column: "asset_id"
97
+ add_foreign_key "kithe_model_contains", "kithe_models", column: "containee_id"
98
+ add_foreign_key "kithe_model_contains", "kithe_models", column: "container_id"
99
+ add_foreign_key "kithe_models", "kithe_models", column: "leaf_representative_id"
100
+ add_foreign_key "kithe_models", "kithe_models", column: "parent_id"
101
+ add_foreign_key "kithe_models", "kithe_models", column: "representative_id"
102
+ end
@@ -108670,3 +108670,3619 @@ Preloading Single-Table Inheritance type Kithe::Asset for Kithe::Model
108670
108670
  Kithe::Asset Update (3.3ms) UPDATE "kithe_models" SET "updated_at" = $1, "file_data" = $2 WHERE "kithe_models"."id" = $3 [["updated_at", "2020-05-12 19:16:26.883198"], ["file_data", "{\"id\":\"asset/e7e4d65b-b65f-43f4-a31a-9e6721a2116e/db52cb74ee881897ced47baa2bcd65c7.jpg\",\"storage\":\"store\",\"metadata\":{\"md5\":\"13a91cf5b51e9c7f0c1e4c1971d68348\",\"sha1\":\"8de724f54e231a7c41c618cf1918a1bb4070e6c9\",\"size\":209630,\"width\":717,\"height\":478,\"sha512\":\"3a7df0d5dfeb8219f379c873d33518f3f01f85e8706546a633029226a81294a0aff0858b29dffecd7f0a5816be766dd8182c58f18ae364c0798308cd17e810f6\",\"filename\":null,\"mime_type\":\"image/jpeg\",\"derivatives_created\":true},\"derivatives\":{\"animage\":{\"id\":\"e7e4d65b-b65f-43f4-a31a-9e6721a2116e/animage/a010cb42443f085e9f7a800d9051721e.jpeg\",\"storage\":\"kithe_derivatives\",\"metadata\":{\"filename\":\"kithe_models_friendlier_id_gen(1,10000000000)_animage.jpeg\",\"size\":312648,\"mime_type\":\"image/jpeg\",\"width\":2045,\"height\":1376,\"md5\":\"e55e2c43660e252ae58ab9e65912a509\",\"sha1\":\"ee867b5ea12915115a6b9706b0d281b4bf067968\",\"sha512\":\"28072fde08738656e73a2f8ee2ebc35c8df32cb86e03656285c5ce787b28df339bfe30612ae191ae818d5d1eca0cf85ec3f2643f752cb12e28d5a3b5215c3836\"}}}}"], ["id", "e7e4d65b-b65f-43f4-a31a-9e6721a2116e"]]
108671
108671
   (0.7ms) COMMIT
108672
108672
  Kithe::Asset Load (0.5ms) SELECT "kithe_models"."id", "kithe_models"."title", "kithe_models"."type", "kithe_models"."position", "kithe_models"."json_attributes", "kithe_models"."created_at", "kithe_models"."updated_at", "kithe_models"."parent_id", "kithe_models"."friendlier_id", "kithe_models"."file_data", "kithe_models"."kithe_model_type" FROM "kithe_models" WHERE "kithe_models"."type" = $1 AND "kithe_models"."id" = $2 LIMIT $3 [["type", "Kithe::Asset"], ["id", "e7e4d65b-b65f-43f4-a31a-9e6721a2116e"], ["LIMIT", 1]]
108673
+  (2.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108674
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108675
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108676
+  (23.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108677
+  (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108678
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108679
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108680
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108681
+  (233.0ms) DROP DATABASE IF EXISTS "kithe_development"
108682
+  (316.2ms) DROP DATABASE IF EXISTS "kithe_test"
108683
+  (480.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
108684
+  (446.4ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
108685
+  (6.9ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
108686
+  (22.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
108687
+  (0.4ms) SELECT pg_try_advisory_lock(1601470156486188030)
108688
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108689
+ Migrating to EnablePgcryptoExtension (20181015143259)
108690
+  (0.2ms) BEGIN
108691
+ SQL (33.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
108692
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
108693
+  (6.5ms) COMMIT
108694
+ Migrating to CreateKitheModels (20181015143413)
108695
+  (0.7ms) BEGIN
108696
+  (28.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
108697
+  (1.2ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
108698
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
108699
+  (2.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
108700
+ FOREIGN KEY ("parent_id")
108701
+ REFERENCES "kithe_models" ("id")
108702
+ 
108703
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
108704
+  (0.8ms) COMMIT
108705
+ Migrating to KitheModelsFriendlierId (20181015143737)
108706
+  (0.3ms) BEGIN
108707
+  (21.5ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
108708
+ DECLARE
108709
+ new_id_int bigint;
108710
+ new_id_str character varying := '';
108711
+ done bool;
108712
+ tries integer;
108713
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
108714
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
108715
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
108716
+ alphabet_length integer := array_length(alphabet, 1);
108717
+
108718
+ BEGIN
108719
+ done := false;
108720
+ tries := 0;
108721
+ WHILE (NOT done) LOOP
108722
+ tries := tries + 1;
108723
+ IF (tries > 3) THEN
108724
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
108725
+ END IF;
108726
+
108727
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
108728
+
108729
+ -- convert bigint to a Base-36 alphanumeric string
108730
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
108731
+ -- https://gist.github.com/btbytes/7159902
108732
+ WHILE new_id_int != 0 LOOP
108733
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
108734
+ new_id_int := new_id_int / alphabet_length;
108735
+ END LOOP;
108736
+
108737
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
108738
+ END LOOP;
108739
+ RETURN new_id_str;
108740
+ END;
108741
+ $$ LANGUAGE plpgsql;
108742
+ 
108743
+  (28.2ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
108744
+  (1.0ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
108745
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
108746
+  (1.2ms) COMMIT
108747
+ Migrating to AddFileDataToModel (20181031190647)
108748
+  (0.3ms) BEGIN
108749
+  (1.0ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
108750
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
108751
+  (13.7ms) COMMIT
108752
+ Migrating to CreateKitheDerivatives (20181128185658)
108753
+  (0.3ms) BEGIN
108754
+  (17.8ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
108755
+ FOREIGN KEY ("asset_id")
108756
+ REFERENCES "kithe_models" ("id")
108757
+ )
108758
+  (6.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
108759
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
108760
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
108761
+  (0.4ms) COMMIT
108762
+ Migrating to AddRepresentativeRelations (20190103144947)
108763
+  (12.1ms) BEGIN
108764
+  (0.9ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
108765
+  (6.7ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
108766
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
108767
+ FOREIGN KEY ("representative_id")
108768
+ REFERENCES "kithe_models" ("id")
108769
+ 
108770
+  (0.5ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
108771
+  (1.0ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
108772
+  (1.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
108773
+ FOREIGN KEY ("leaf_representative_id")
108774
+ REFERENCES "kithe_models" ("id")
108775
+ 
108776
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
108777
+  (0.4ms) COMMIT
108778
+ Migrating to ContainsAssociation (20190109192252)
108779
+  (0.3ms) BEGIN
108780
+  (2.7ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
108781
+ FOREIGN KEY ("containee_id")
108782
+ REFERENCES "kithe_models" ("id")
108783
+ , CONSTRAINT "fk_rails_091010187b"
108784
+ FOREIGN KEY ("container_id")
108785
+ REFERENCES "kithe_models" ("id")
108786
+ )
108787
+  (7.4ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
108788
+  (5.9ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
108789
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
108790
+  (0.4ms) COMMIT
108791
+ Migrating to KitheModelType (20190404144551)
108792
+  (0.3ms) BEGIN
108793
+  (0.7ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
108794
+  (0.4ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
108795
+  (13.1ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
108796
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
108797
+  (5.9ms) COMMIT
108798
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
108799
+  (0.2ms) BEGIN
108800
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 19:49:53.472252"], ["updated_at", "2020-05-20 19:49:53.472252"]]
108801
+  (6.1ms) COMMIT
108802
+  (0.3ms) SELECT pg_advisory_unlock(1601470156486188030)
108803
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108804
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108805
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108806
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108807
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108808
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108809
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108810
+  (206.8ms) DROP DATABASE IF EXISTS "kithe_development"
108811
+  (203.9ms) DROP DATABASE IF EXISTS "kithe_test"
108812
+  (539.9ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
108813
+  (419.2ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
108814
+  (5.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
108815
+  (4.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
108816
+  (0.2ms) SELECT pg_try_advisory_lock(1601470156486188030)
108817
+  (0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108818
+ Migrating to EnablePgcryptoExtension (20181015143259)
108819
+  (0.2ms) BEGIN
108820
+ SQL (18.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
108821
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
108822
+  (6.1ms) COMMIT
108823
+ Migrating to CreateKitheModels (20181015143413)
108824
+  (0.3ms) BEGIN
108825
+  (18.8ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
108826
+  (0.5ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
108827
+  (1.1ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
108828
+  (3.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
108829
+ FOREIGN KEY ("parent_id")
108830
+ REFERENCES "kithe_models" ("id")
108831
+ 
108832
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
108833
+  (0.5ms) COMMIT
108834
+ Migrating to KitheModelsFriendlierId (20181015143737)
108835
+  (0.3ms) BEGIN
108836
+  (2.3ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
108837
+ DECLARE
108838
+ new_id_int bigint;
108839
+ new_id_str character varying := '';
108840
+ done bool;
108841
+ tries integer;
108842
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
108843
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
108844
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
108845
+ alphabet_length integer := array_length(alphabet, 1);
108846
+
108847
+ BEGIN
108848
+ done := false;
108849
+ tries := 0;
108850
+ WHILE (NOT done) LOOP
108851
+ tries := tries + 1;
108852
+ IF (tries > 3) THEN
108853
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
108854
+ END IF;
108855
+
108856
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
108857
+
108858
+ -- convert bigint to a Base-36 alphanumeric string
108859
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
108860
+ -- https://gist.github.com/btbytes/7159902
108861
+ WHILE new_id_int != 0 LOOP
108862
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
108863
+ new_id_int := new_id_int / alphabet_length;
108864
+ END LOOP;
108865
+
108866
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
108867
+ END LOOP;
108868
+ RETURN new_id_str;
108869
+ END;
108870
+ $$ LANGUAGE plpgsql;
108871
+ 
108872
+  (24.7ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
108873
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
108874
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
108875
+  (1.2ms) COMMIT
108876
+ Migrating to AddFileDataToModel (20181031190647)
108877
+  (0.4ms) BEGIN
108878
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
108879
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
108880
+  (11.3ms) COMMIT
108881
+ Migrating to CreateKitheDerivatives (20181128185658)
108882
+  (0.4ms) BEGIN
108883
+  (27.7ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
108884
+ FOREIGN KEY ("asset_id")
108885
+ REFERENCES "kithe_models" ("id")
108886
+ )
108887
+  (1.6ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
108888
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
108889
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
108890
+  (0.4ms) COMMIT
108891
+ Migrating to AddRepresentativeRelations (20190103144947)
108892
+  (43.7ms) BEGIN
108893
+  (0.4ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
108894
+  (2.8ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
108895
+  (2.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
108896
+ FOREIGN KEY ("representative_id")
108897
+ REFERENCES "kithe_models" ("id")
108898
+ 
108899
+  (0.6ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
108900
+  (25.7ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
108901
+  (12.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
108902
+ FOREIGN KEY ("leaf_representative_id")
108903
+ REFERENCES "kithe_models" ("id")
108904
+ 
108905
+ primary::SchemaMigration Create (5.1ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
108906
+  (2.0ms) COMMIT
108907
+ Migrating to ContainsAssociation (20190109192252)
108908
+  (0.9ms) BEGIN
108909
+  (23.6ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
108910
+ FOREIGN KEY ("containee_id")
108911
+ REFERENCES "kithe_models" ("id")
108912
+ , CONSTRAINT "fk_rails_091010187b"
108913
+ FOREIGN KEY ("container_id")
108914
+ REFERENCES "kithe_models" ("id")
108915
+ )
108916
+  (1.1ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
108917
+  (1.0ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
108918
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
108919
+  (0.4ms) COMMIT
108920
+ Migrating to KitheModelType (20190404144551)
108921
+  (0.2ms) BEGIN
108922
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
108923
+  (0.4ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
108924
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
108925
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
108926
+  (6.4ms) COMMIT
108927
+ ActiveRecord::InternalMetadata Load (0.8ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
108928
+  (0.1ms) BEGIN
108929
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 19:50:47.121307"], ["updated_at", "2020-05-20 19:50:47.121307"]]
108930
+  (0.4ms) COMMIT
108931
+  (0.2ms) SELECT pg_advisory_unlock(1601470156486188030)
108932
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108933
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108934
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108935
+  (5.5ms)  SELECT
108936
+ pp.proname AS name,
108937
+ pg_get_functiondef(pp.oid) AS definition
108938
+ FROM pg_proc pp
108939
+ JOIN pg_namespace pn
108940
+ ON pn.oid = pp.pronamespace
108941
+ LEFT JOIN pg_depend pd
108942
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
108943
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
108944
+ ORDER BY pp.oid;
108945
+ 
108946
+  (1.5ms)  SELECT
108947
+ pt.tgname AS name,
108948
+ pg_get_triggerdef(pt.oid) AS definition
108949
+ FROM pg_trigger pt
108950
+ JOIN pg_class pc
108951
+ ON (pc.oid = pt.tgrelid)
108952
+ JOIN pg_proc pp
108953
+ ON (pp.oid = pt.tgfoid)
108954
+ WHERE pt.tgname
108955
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
108956
+ ORDER BY pc.oid;
108957
+ 
108958
+  (0.2ms) SELECT pg_try_advisory_lock(1601470156486188030)
108959
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108960
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
108961
+  (0.4ms) SELECT pg_advisory_unlock(1601470156486188030)
108962
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108963
+  (4.1ms)  SELECT
108964
+ pp.proname AS name,
108965
+ pg_get_functiondef(pp.oid) AS definition
108966
+ FROM pg_proc pp
108967
+ JOIN pg_namespace pn
108968
+ ON pn.oid = pp.pronamespace
108969
+ LEFT JOIN pg_depend pd
108970
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
108971
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
108972
+ ORDER BY pp.oid;
108973
+ 
108974
+  (1.3ms)  SELECT
108975
+ pt.tgname AS name,
108976
+ pg_get_triggerdef(pt.oid) AS definition
108977
+ FROM pg_trigger pt
108978
+ JOIN pg_class pc
108979
+ ON (pc.oid = pt.tgrelid)
108980
+ JOIN pg_proc pp
108981
+ ON (pp.oid = pt.tgfoid)
108982
+ WHERE pt.tgname
108983
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
108984
+ ORDER BY pc.oid;
108985
+ 
108986
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108987
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108988
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108989
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108990
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
108991
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
108992
+  (285.0ms) DROP DATABASE IF EXISTS "kithe_development"
108993
+  (211.1ms) DROP DATABASE IF EXISTS "kithe_test"
108994
+  (491.7ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
108995
+  (411.0ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
108996
+ SQL (36.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
108997
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
108998
+  (10.5ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
108999
+ RETURNS text
109000
+ LANGUAGE plpgsql
109001
+ AS $function$
109002
+ DECLARE
109003
+ new_id_int bigint;
109004
+ new_id_str character varying := '';
109005
+ done bool;
109006
+ tries integer;
109007
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109008
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109009
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109010
+ alphabet_length integer := array_length(alphabet, 1);
109011
+
109012
+ BEGIN
109013
+ done := false;
109014
+ tries := 0;
109015
+ WHILE (NOT done) LOOP
109016
+ tries := tries + 1;
109017
+ IF (tries > 3) THEN
109018
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109019
+ END IF;
109020
+
109021
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109022
+
109023
+ -- convert bigint to a Base-36 alphanumeric string
109024
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109025
+ -- https://gist.github.com/btbytes/7159902
109026
+ WHILE new_id_int != 0 LOOP
109027
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109028
+ new_id_int := new_id_int / alphabet_length;
109029
+ END LOOP;
109030
+
109031
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109032
+ END LOOP;
109033
+ RETURN new_id_str;
109034
+ END;
109035
+ $function$
109036
+ 
109037
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109038
+  (20.0ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109039
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109040
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109041
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109042
+  (8.4ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109043
+  (11.8ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109044
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109045
+  (0.3ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109046
+  (4.1ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109047
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109048
+  (1.4ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109049
+  (2.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109050
+  (1.9ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109051
+  (4.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
109052
+ FOREIGN KEY ("asset_id")
109053
+ REFERENCES "kithe_models" ("id")
109054
+ 
109055
+  (2.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
109056
+ FOREIGN KEY ("containee_id")
109057
+ REFERENCES "kithe_models" ("id")
109058
+ 
109059
+  (2.1ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
109060
+ FOREIGN KEY ("container_id")
109061
+ REFERENCES "kithe_models" ("id")
109062
+ 
109063
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109064
+ FOREIGN KEY ("leaf_representative_id")
109065
+ REFERENCES "kithe_models" ("id")
109066
+ 
109067
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109068
+ FOREIGN KEY ("parent_id")
109069
+ REFERENCES "kithe_models" ("id")
109070
+ 
109071
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109072
+ FOREIGN KEY ("representative_id")
109073
+ REFERENCES "kithe_models" ("id")
109074
+ 
109075
+  (3.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109076
+  (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109077
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
109078
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES
109079
+ (20181015143259),
109080
+ (20181015143413),
109081
+ (20181015143737),
109082
+ (20181031190647),
109083
+ (20181128185658),
109084
+ (20190103144947),
109085
+ (20190109192252);
109086
+
109087
+ 
109088
+  (21.8ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109089
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109090
+  (0.2ms) BEGIN
109091
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 20:49:47.747085"], ["updated_at", "2020-05-20 20:49:47.747085"]]
109092
+  (0.3ms) COMMIT
109093
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109094
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
109095
+  (0.3ms) BEGIN
109096
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "658d6ce4e52abaa31072af6cc4edca545468d72b"], ["created_at", "2020-05-20 20:49:47.755335"], ["updated_at", "2020-05-20 20:49:47.755335"]]
109097
+  (0.4ms) COMMIT
109098
+ SQL (11.5ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109099
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109100
+  (2.1ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109101
+ RETURNS text
109102
+ LANGUAGE plpgsql
109103
+ AS $function$
109104
+ DECLARE
109105
+ new_id_int bigint;
109106
+ new_id_str character varying := '';
109107
+ done bool;
109108
+ tries integer;
109109
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109110
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109111
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109112
+ alphabet_length integer := array_length(alphabet, 1);
109113
+
109114
+ BEGIN
109115
+ done := false;
109116
+ tries := 0;
109117
+ WHILE (NOT done) LOOP
109118
+ tries := tries + 1;
109119
+ IF (tries > 3) THEN
109120
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109121
+ END IF;
109122
+
109123
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109124
+
109125
+ -- convert bigint to a Base-36 alphanumeric string
109126
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109127
+ -- https://gist.github.com/btbytes/7159902
109128
+ WHILE new_id_int != 0 LOOP
109129
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109130
+ new_id_int := new_id_int / alphabet_length;
109131
+ END LOOP;
109132
+
109133
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109134
+ END LOOP;
109135
+ RETURN new_id_str;
109136
+ END;
109137
+ $function$
109138
+ 
109139
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109140
+  (6.0ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109141
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109142
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109143
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109144
+  (1.1ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109145
+  (2.5ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109146
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109147
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109148
+  (5.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109149
+  (1.7ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109150
+  (2.0ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109151
+  (1.6ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109152
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109153
+  (2.9ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
109154
+ FOREIGN KEY ("asset_id")
109155
+ REFERENCES "kithe_models" ("id")
109156
+ 
109157
+  (1.6ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
109158
+ FOREIGN KEY ("containee_id")
109159
+ REFERENCES "kithe_models" ("id")
109160
+ 
109161
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
109162
+ FOREIGN KEY ("container_id")
109163
+ REFERENCES "kithe_models" ("id")
109164
+ 
109165
+  (2.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109166
+ FOREIGN KEY ("leaf_representative_id")
109167
+ REFERENCES "kithe_models" ("id")
109168
+ 
109169
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109170
+ FOREIGN KEY ("parent_id")
109171
+ REFERENCES "kithe_models" ("id")
109172
+ 
109173
+  (2.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109174
+ FOREIGN KEY ("representative_id")
109175
+ REFERENCES "kithe_models" ("id")
109176
+ 
109177
+  (3.7ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109178
+  (0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109179
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
109180
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES
109181
+ (20181015143259),
109182
+ (20181015143413),
109183
+ (20181015143737),
109184
+ (20181031190647),
109185
+ (20181128185658),
109186
+ (20190103144947),
109187
+ (20190109192252);
109188
+
109189
+ 
109190
+  (3.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109191
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109192
+  (0.1ms) BEGIN
109193
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 20:49:47.932037"], ["updated_at", "2020-05-20 20:49:47.932037"]]
109194
+  (0.5ms) COMMIT
109195
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109196
+  (0.2ms) BEGIN
109197
+ ActiveRecord::InternalMetadata Update (0.7ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-20 20:49:47.940151"], ["key", "environment"]]
109198
+  (5.7ms) COMMIT
109199
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
109200
+  (0.2ms) BEGIN
109201
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "658d6ce4e52abaa31072af6cc4edca545468d72b"], ["created_at", "2020-05-20 20:49:47.953802"], ["updated_at", "2020-05-20 20:49:47.953802"]]
109202
+  (6.4ms) COMMIT
109203
+  (7.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109204
+  (30.7ms)  SELECT
109205
+ pp.proname AS name,
109206
+ pg_get_functiondef(pp.oid) AS definition
109207
+ FROM pg_proc pp
109208
+ JOIN pg_namespace pn
109209
+ ON pn.oid = pp.pronamespace
109210
+ LEFT JOIN pg_depend pd
109211
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109212
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109213
+ ORDER BY pp.oid;
109214
+ 
109215
+  (1.8ms)  SELECT
109216
+ pt.tgname AS name,
109217
+ pg_get_triggerdef(pt.oid) AS definition
109218
+ FROM pg_trigger pt
109219
+ JOIN pg_class pc
109220
+ ON (pc.oid = pt.tgrelid)
109221
+ JOIN pg_proc pp
109222
+ ON (pp.oid = pt.tgfoid)
109223
+ WHERE pt.tgname
109224
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109225
+ ORDER BY pc.oid;
109226
+ 
109227
+  (1.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109228
+  (4.5ms)  SELECT
109229
+ pp.proname AS name,
109230
+ pg_get_functiondef(pp.oid) AS definition
109231
+ FROM pg_proc pp
109232
+ JOIN pg_namespace pn
109233
+ ON pn.oid = pp.pronamespace
109234
+ LEFT JOIN pg_depend pd
109235
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109236
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109237
+ ORDER BY pp.oid;
109238
+ 
109239
+  (2.0ms)  SELECT
109240
+ pt.tgname AS name,
109241
+ pg_get_triggerdef(pt.oid) AS definition
109242
+ FROM pg_trigger pt
109243
+ JOIN pg_class pc
109244
+ ON (pc.oid = pt.tgrelid)
109245
+ JOIN pg_proc pp
109246
+ ON (pp.oid = pt.tgfoid)
109247
+ WHERE pt.tgname
109248
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109249
+ ORDER BY pc.oid;
109250
+ 
109251
+  (1.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109252
+  (4.2ms)  SELECT
109253
+ pp.proname AS name,
109254
+ pg_get_functiondef(pp.oid) AS definition
109255
+ FROM pg_proc pp
109256
+ JOIN pg_namespace pn
109257
+ ON pn.oid = pp.pronamespace
109258
+ LEFT JOIN pg_depend pd
109259
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109260
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109261
+ ORDER BY pp.oid;
109262
+ 
109263
+  (1.4ms)  SELECT
109264
+ pt.tgname AS name,
109265
+ pg_get_triggerdef(pt.oid) AS definition
109266
+ FROM pg_trigger pt
109267
+ JOIN pg_class pc
109268
+ ON (pc.oid = pt.tgrelid)
109269
+ JOIN pg_proc pp
109270
+ ON (pp.oid = pt.tgfoid)
109271
+ WHERE pt.tgname
109272
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109273
+ ORDER BY pc.oid;
109274
+ 
109275
+  (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109276
+  (4.4ms)  SELECT
109277
+ pp.proname AS name,
109278
+ pg_get_functiondef(pp.oid) AS definition
109279
+ FROM pg_proc pp
109280
+ JOIN pg_namespace pn
109281
+ ON pn.oid = pp.pronamespace
109282
+ LEFT JOIN pg_depend pd
109283
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109284
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109285
+ ORDER BY pp.oid;
109286
+ 
109287
+  (1.4ms)  SELECT
109288
+ pt.tgname AS name,
109289
+ pg_get_triggerdef(pt.oid) AS definition
109290
+ FROM pg_trigger pt
109291
+ JOIN pg_class pc
109292
+ ON (pc.oid = pt.tgrelid)
109293
+ JOIN pg_proc pp
109294
+ ON (pp.oid = pt.tgfoid)
109295
+ WHERE pt.tgname
109296
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109297
+ ORDER BY pc.oid;
109298
+ 
109299
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109300
+  (4.2ms)  SELECT
109301
+ pp.proname AS name,
109302
+ pg_get_functiondef(pp.oid) AS definition
109303
+ FROM pg_proc pp
109304
+ JOIN pg_namespace pn
109305
+ ON pn.oid = pp.pronamespace
109306
+ LEFT JOIN pg_depend pd
109307
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109308
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109309
+ ORDER BY pp.oid;
109310
+ 
109311
+  (1.3ms)  SELECT
109312
+ pt.tgname AS name,
109313
+ pg_get_triggerdef(pt.oid) AS definition
109314
+ FROM pg_trigger pt
109315
+ JOIN pg_class pc
109316
+ ON (pc.oid = pt.tgrelid)
109317
+ JOIN pg_proc pp
109318
+ ON (pp.oid = pt.tgfoid)
109319
+ WHERE pt.tgname
109320
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109321
+ ORDER BY pc.oid;
109322
+ 
109323
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109324
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109325
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109326
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109327
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109328
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109329
+  (216.4ms) DROP DATABASE IF EXISTS "kithe_development"
109330
+  (228.1ms) DROP DATABASE IF EXISTS "kithe_test"
109331
+  (494.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109332
+  (422.6ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109333
+ SQL (63.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109334
+ SQL (50.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109335
+  (34.8ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109336
+ RETURNS text
109337
+ LANGUAGE plpgsql
109338
+ AS $function$
109339
+ DECLARE
109340
+ new_id_int bigint;
109341
+ new_id_str character varying := '';
109342
+ done bool;
109343
+ tries integer;
109344
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109345
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109346
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109347
+ alphabet_length integer := array_length(alphabet, 1);
109348
+
109349
+ BEGIN
109350
+ done := false;
109351
+ tries := 0;
109352
+ WHILE (NOT done) LOOP
109353
+ tries := tries + 1;
109354
+ IF (tries > 3) THEN
109355
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109356
+ END IF;
109357
+
109358
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109359
+
109360
+ -- convert bigint to a Base-36 alphanumeric string
109361
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109362
+ -- https://gist.github.com/btbytes/7159902
109363
+ WHILE new_id_int != 0 LOOP
109364
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109365
+ new_id_int := new_id_int / alphabet_length;
109366
+ END LOOP;
109367
+
109368
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109369
+ END LOOP;
109370
+ RETURN new_id_str;
109371
+ END;
109372
+ $function$
109373
+ 
109374
+  (0.4ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109375
+  (12.8ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109376
+  (2.0ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109377
+  (1.5ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109378
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109379
+  (1.1ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109380
+  (1.1ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109381
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109382
+  (0.4ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109383
+  (4.4ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109384
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109385
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109386
+  (1.1ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109387
+  (1.1ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109388
+  (3.2ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
109389
+ FOREIGN KEY ("asset_id")
109390
+ REFERENCES "kithe_models" ("id")
109391
+ 
109392
+  (2.3ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
109393
+ FOREIGN KEY ("containee_id")
109394
+ REFERENCES "kithe_models" ("id")
109395
+ 
109396
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
109397
+ FOREIGN KEY ("container_id")
109398
+ REFERENCES "kithe_models" ("id")
109399
+ 
109400
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109401
+ FOREIGN KEY ("leaf_representative_id")
109402
+ REFERENCES "kithe_models" ("id")
109403
+ 
109404
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109405
+ FOREIGN KEY ("parent_id")
109406
+ REFERENCES "kithe_models" ("id")
109407
+ 
109408
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109409
+ FOREIGN KEY ("representative_id")
109410
+ REFERENCES "kithe_models" ("id")
109411
+ 
109412
+  (7.6ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109413
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109414
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
109415
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES
109416
+ (20181015143259),
109417
+ (20181015143413),
109418
+ (20181015143737),
109419
+ (20181031190647),
109420
+ (20181128185658),
109421
+ (20190103144947),
109422
+ (20190109192252);
109423
+
109424
+ 
109425
+  (3.8ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109426
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109427
+  (0.2ms) BEGIN
109428
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 21:22:55.681291"], ["updated_at", "2020-05-20 21:22:55.681291"]]
109429
+  (0.5ms) COMMIT
109430
+ ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109431
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
109432
+  (0.1ms) BEGIN
109433
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-20 21:22:55.690278"], ["updated_at", "2020-05-20 21:22:55.690278"]]
109434
+  (0.5ms) COMMIT
109435
+ SQL (10.7ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109436
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109437
+  (2.1ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109438
+ RETURNS text
109439
+ LANGUAGE plpgsql
109440
+ AS $function$
109441
+ DECLARE
109442
+ new_id_int bigint;
109443
+ new_id_str character varying := '';
109444
+ done bool;
109445
+ tries integer;
109446
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109447
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109448
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109449
+ alphabet_length integer := array_length(alphabet, 1);
109450
+
109451
+ BEGIN
109452
+ done := false;
109453
+ tries := 0;
109454
+ WHILE (NOT done) LOOP
109455
+ tries := tries + 1;
109456
+ IF (tries > 3) THEN
109457
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109458
+ END IF;
109459
+
109460
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109461
+
109462
+ -- convert bigint to a Base-36 alphanumeric string
109463
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109464
+ -- https://gist.github.com/btbytes/7159902
109465
+ WHILE new_id_int != 0 LOOP
109466
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109467
+ new_id_int := new_id_int / alphabet_length;
109468
+ END LOOP;
109469
+
109470
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109471
+ END LOOP;
109472
+ RETURN new_id_str;
109473
+ END;
109474
+ $function$
109475
+ 
109476
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109477
+  (6.5ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109478
+  (1.7ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109479
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109480
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109481
+  (1.0ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109482
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109483
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109484
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109485
+  (3.4ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109486
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109487
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109488
+  (1.4ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109489
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109490
+  (2.8ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
109491
+ FOREIGN KEY ("asset_id")
109492
+ REFERENCES "kithe_models" ("id")
109493
+ 
109494
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
109495
+ FOREIGN KEY ("containee_id")
109496
+ REFERENCES "kithe_models" ("id")
109497
+ 
109498
+  (1.5ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
109499
+ FOREIGN KEY ("container_id")
109500
+ REFERENCES "kithe_models" ("id")
109501
+ 
109502
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109503
+ FOREIGN KEY ("leaf_representative_id")
109504
+ REFERENCES "kithe_models" ("id")
109505
+ 
109506
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109507
+ FOREIGN KEY ("parent_id")
109508
+ REFERENCES "kithe_models" ("id")
109509
+ 
109510
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109511
+ FOREIGN KEY ("representative_id")
109512
+ REFERENCES "kithe_models" ("id")
109513
+ 
109514
+  (3.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109515
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109516
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
109517
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES
109518
+ (20181015143259),
109519
+ (20181015143413),
109520
+ (20181015143737),
109521
+ (20181031190647),
109522
+ (20181128185658),
109523
+ (20190103144947),
109524
+ (20190109192252);
109525
+
109526
+ 
109527
+  (2.9ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109528
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109529
+  (0.1ms) BEGIN
109530
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 21:22:55.842211"], ["updated_at", "2020-05-20 21:22:55.842211"]]
109531
+  (0.4ms) COMMIT
109532
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109533
+  (0.1ms) BEGIN
109534
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-20 21:22:55.848684"], ["key", "environment"]]
109535
+  (0.3ms) COMMIT
109536
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
109537
+  (0.1ms) BEGIN
109538
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-20 21:22:55.854305"], ["updated_at", "2020-05-20 21:22:55.854305"]]
109539
+  (0.4ms) COMMIT
109540
+  (4.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109541
+  (6.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109542
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109543
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109544
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109545
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109546
+  (415.7ms) DROP DATABASE IF EXISTS "kithe_development"
109547
+  (199.9ms) DROP DATABASE IF EXISTS "kithe_test"
109548
+  (849.8ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109549
+  (615.6ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109550
+  (27.8ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109551
+  (5.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109552
+  (11.6ms) SELECT pg_try_advisory_lock(1601470156486188030)
109553
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109554
+ Migrating to EnablePgcryptoExtension (20181015143259)
109555
+  (0.6ms) BEGIN
109556
+ SQL (188.1ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109557
+ primary::SchemaMigration Create (4.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
109558
+  (24.5ms) COMMIT
109559
+ Migrating to CreateKitheModels (20181015143413)
109560
+  (0.8ms) BEGIN
109561
+  (24.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109562
+  (0.5ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
109563
+  (8.0ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109564
+  (17.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109565
+ FOREIGN KEY ("parent_id")
109566
+ REFERENCES "kithe_models" ("id")
109567
+ 
109568
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
109569
+  (0.5ms) COMMIT
109570
+ Migrating to KitheModelsFriendlierId (20181015143737)
109571
+  (0.3ms) BEGIN
109572
+  (42.9ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
109573
+ DECLARE
109574
+ new_id_int bigint;
109575
+ new_id_str character varying := '';
109576
+ done bool;
109577
+ tries integer;
109578
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109579
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109580
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109581
+ alphabet_length integer := array_length(alphabet, 1);
109582
+
109583
+ BEGIN
109584
+ done := false;
109585
+ tries := 0;
109586
+ WHILE (NOT done) LOOP
109587
+ tries := tries + 1;
109588
+ IF (tries > 3) THEN
109589
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109590
+ END IF;
109591
+
109592
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109593
+
109594
+ -- convert bigint to a Base-36 alphanumeric string
109595
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109596
+ -- https://gist.github.com/btbytes/7159902
109597
+ WHILE new_id_int != 0 LOOP
109598
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109599
+ new_id_int := new_id_int / alphabet_length;
109600
+ END LOOP;
109601
+
109602
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109603
+ END LOOP;
109604
+ RETURN new_id_str;
109605
+ END;
109606
+ $$ LANGUAGE plpgsql;
109607
+ 
109608
+  (43.1ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
109609
+  (14.4ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109610
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
109611
+  (30.0ms) COMMIT
109612
+ Migrating to AddFileDataToModel (20181031190647)
109613
+  (0.3ms) BEGIN
109614
+  (0.7ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
109615
+ primary::SchemaMigration Create (1.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
109616
+  (12.2ms) COMMIT
109617
+ Migrating to CreateKitheDerivatives (20181128185658)
109618
+  (0.2ms) BEGIN
109619
+  (91.1ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
109620
+ FOREIGN KEY ("asset_id")
109621
+ REFERENCES "kithe_models" ("id")
109622
+ )
109623
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109624
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109625
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
109626
+  (2.1ms) COMMIT
109627
+ Migrating to AddRepresentativeRelations (20190103144947)
109628
+  (12.0ms) BEGIN
109629
+  (1.3ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
109630
+  (7.7ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109631
+  (96.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109632
+ FOREIGN KEY ("representative_id")
109633
+ REFERENCES "kithe_models" ("id")
109634
+ 
109635
+  (0.9ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
109636
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109637
+  (3.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109638
+ FOREIGN KEY ("leaf_representative_id")
109639
+ REFERENCES "kithe_models" ("id")
109640
+ 
109641
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
109642
+  (6.3ms) COMMIT
109643
+ Migrating to ContainsAssociation (20190109192252)
109644
+  (0.3ms) BEGIN
109645
+  (7.3ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
109646
+ FOREIGN KEY ("containee_id")
109647
+ REFERENCES "kithe_models" ("id")
109648
+ , CONSTRAINT "fk_rails_091010187b"
109649
+ FOREIGN KEY ("container_id")
109650
+ REFERENCES "kithe_models" ("id")
109651
+ )
109652
+  (13.6ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109653
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109654
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
109655
+  (6.4ms) COMMIT
109656
+ Migrating to KitheModelType (20190404144551)
109657
+  (0.3ms) BEGIN
109658
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
109659
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
109660
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
109661
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
109662
+  (0.5ms) COMMIT
109663
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109664
+  (0.2ms) BEGIN
109665
+ ActiveRecord::InternalMetadata Create (0.8ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 15:56:52.813959"], ["updated_at", "2020-05-27 15:56:52.813959"]]
109666
+  (6.0ms) COMMIT
109667
+  (0.7ms) SELECT pg_advisory_unlock(1601470156486188030)
109668
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109669
+  (4.7ms)  SELECT
109670
+ pp.proname AS name,
109671
+ pg_get_functiondef(pp.oid) AS definition
109672
+ FROM pg_proc pp
109673
+ JOIN pg_namespace pn
109674
+ ON pn.oid = pp.pronamespace
109675
+ LEFT JOIN pg_depend pd
109676
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109677
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109678
+ ORDER BY pp.oid;
109679
+ 
109680
+  (1.5ms)  SELECT
109681
+ pt.tgname AS name,
109682
+ pg_get_triggerdef(pt.oid) AS definition
109683
+ FROM pg_trigger pt
109684
+ JOIN pg_class pc
109685
+ ON (pc.oid = pt.tgrelid)
109686
+ JOIN pg_proc pp
109687
+ ON (pp.oid = pt.tgfoid)
109688
+ WHERE pt.tgname
109689
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109690
+ ORDER BY pc.oid;
109691
+ 
109692
+  (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109693
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109694
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109695
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109696
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109697
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109698
+  (209.2ms) DROP DATABASE IF EXISTS "kithe_development"
109699
+  (238.3ms) DROP DATABASE IF EXISTS "kithe_test"
109700
+  (743.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109701
+  (452.5ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109702
+ SQL (22.5ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109703
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109704
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109705
+  (76.0ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109706
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109707
+  (1.1ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109708
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109709
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109710
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109711
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109712
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109713
+  (3.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109714
+  (222.1ms) DROP DATABASE IF EXISTS "kithe_development"
109715
+  (216.1ms) DROP DATABASE IF EXISTS "kithe_test"
109716
+  (1076.2ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109717
+  (619.8ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109718
+  (6.6ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109719
+  (27.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109720
+  (0.4ms) SELECT pg_try_advisory_lock(1601470156486188030)
109721
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109722
+ Migrating to EnablePgcryptoExtension (20181015143259)
109723
+  (0.4ms) BEGIN
109724
+ SQL (28.3ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109725
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
109726
+  (5.5ms) COMMIT
109727
+ Migrating to CreateKitheModels (20181015143413)
109728
+  (0.3ms) BEGIN
109729
+  (17.4ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109730
+  (0.5ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
109731
+  (7.0ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109732
+  (3.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109733
+ FOREIGN KEY ("parent_id")
109734
+ REFERENCES "kithe_models" ("id")
109735
+ 
109736
+ primary::SchemaMigration Create (2.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
109737
+  (1.9ms) COMMIT
109738
+ Migrating to KitheModelsFriendlierId (20181015143737)
109739
+  (0.3ms) BEGIN
109740
+  (4.5ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
109741
+ DECLARE
109742
+ new_id_int bigint;
109743
+ new_id_str character varying := '';
109744
+ done bool;
109745
+ tries integer;
109746
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109747
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109748
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109749
+ alphabet_length integer := array_length(alphabet, 1);
109750
+
109751
+ BEGIN
109752
+ done := false;
109753
+ tries := 0;
109754
+ WHILE (NOT done) LOOP
109755
+ tries := tries + 1;
109756
+ IF (tries > 3) THEN
109757
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109758
+ END IF;
109759
+
109760
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109761
+
109762
+ -- convert bigint to a Base-36 alphanumeric string
109763
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109764
+ -- https://gist.github.com/btbytes/7159902
109765
+ WHILE new_id_int != 0 LOOP
109766
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109767
+ new_id_int := new_id_int / alphabet_length;
109768
+ END LOOP;
109769
+
109770
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109771
+ END LOOP;
109772
+ RETURN new_id_str;
109773
+ END;
109774
+ $$ LANGUAGE plpgsql;
109775
+ 
109776
+  (41.5ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
109777
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109778
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
109779
+  (1.2ms) COMMIT
109780
+ Migrating to AddFileDataToModel (20181031190647)
109781
+  (0.9ms) BEGIN
109782
+  (0.6ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
109783
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
109784
+  (5.4ms) COMMIT
109785
+ Migrating to CreateKitheDerivatives (20181128185658)
109786
+  (0.2ms) BEGIN
109787
+  (26.1ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
109788
+ FOREIGN KEY ("asset_id")
109789
+ REFERENCES "kithe_models" ("id")
109790
+ )
109791
+  (9.1ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109792
+  (1.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109793
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
109794
+  (0.6ms) COMMIT
109795
+ Migrating to AddRepresentativeRelations (20190103144947)
109796
+  (6.4ms) BEGIN
109797
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
109798
+  (7.1ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109799
+  (4.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109800
+ FOREIGN KEY ("representative_id")
109801
+ REFERENCES "kithe_models" ("id")
109802
+ 
109803
+  (0.6ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
109804
+  (7.0ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109805
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109806
+ FOREIGN KEY ("leaf_representative_id")
109807
+ REFERENCES "kithe_models" ("id")
109808
+ 
109809
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
109810
+  (13.6ms) COMMIT
109811
+ Migrating to ContainsAssociation (20190109192252)
109812
+  (0.3ms) BEGIN
109813
+  (3.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
109814
+ FOREIGN KEY ("containee_id")
109815
+ REFERENCES "kithe_models" ("id")
109816
+ , CONSTRAINT "fk_rails_091010187b"
109817
+ FOREIGN KEY ("container_id")
109818
+ REFERENCES "kithe_models" ("id")
109819
+ )
109820
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109821
+  (137.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109822
+ primary::SchemaMigration Create (0.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
109823
+  (0.6ms) COMMIT
109824
+ Migrating to KitheModelType (20190404144551)
109825
+  (0.7ms) BEGIN
109826
+  (1.6ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
109827
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
109828
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
109829
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
109830
+  (15.6ms) COMMIT
109831
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109832
+  (0.2ms) BEGIN
109833
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:23.911025"], ["updated_at", "2020-05-27 16:05:23.911025"]]
109834
+  (18.0ms) COMMIT
109835
+  (0.8ms) SELECT pg_advisory_unlock(1601470156486188030)
109836
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109837
+  (5.4ms)  SELECT
109838
+ pp.proname AS name,
109839
+ pg_get_functiondef(pp.oid) AS definition
109840
+ FROM pg_proc pp
109841
+ JOIN pg_namespace pn
109842
+ ON pn.oid = pp.pronamespace
109843
+ LEFT JOIN pg_depend pd
109844
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109845
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109846
+ ORDER BY pp.oid;
109847
+ 
109848
+  (1.5ms)  SELECT
109849
+ pt.tgname AS name,
109850
+ pg_get_triggerdef(pt.oid) AS definition
109851
+ FROM pg_trigger pt
109852
+ JOIN pg_class pc
109853
+ ON (pc.oid = pt.tgrelid)
109854
+ JOIN pg_proc pp
109855
+ ON (pp.oid = pt.tgfoid)
109856
+ WHERE pt.tgname
109857
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109858
+ ORDER BY pc.oid;
109859
+ 
109860
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109861
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109862
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109863
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109864
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109865
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109866
+  (281.6ms) DROP DATABASE IF EXISTS "kithe_development"
109867
+  (206.0ms) DROP DATABASE IF EXISTS "kithe_test"
109868
+  (430.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109869
+  (507.9ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109870
+ SQL (44.1ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109871
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109872
+  (2.2ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109873
+ RETURNS text
109874
+ LANGUAGE plpgsql
109875
+ AS $function$
109876
+ DECLARE
109877
+ new_id_int bigint;
109878
+ new_id_str character varying := '';
109879
+ done bool;
109880
+ tries integer;
109881
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109882
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109883
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109884
+ alphabet_length integer := array_length(alphabet, 1);
109885
+
109886
+ BEGIN
109887
+ done := false;
109888
+ tries := 0;
109889
+ WHILE (NOT done) LOOP
109890
+ tries := tries + 1;
109891
+ IF (tries > 3) THEN
109892
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109893
+ END IF;
109894
+
109895
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109896
+
109897
+ -- convert bigint to a Base-36 alphanumeric string
109898
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109899
+ -- https://gist.github.com/btbytes/7159902
109900
+ WHILE new_id_int != 0 LOOP
109901
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109902
+ new_id_int := new_id_int / alphabet_length;
109903
+ END LOOP;
109904
+
109905
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109906
+ END LOOP;
109907
+ RETURN new_id_str;
109908
+ END;
109909
+ $function$
109910
+ 
109911
+  (0.4ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109912
+  (8.6ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109913
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109914
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109915
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109916
+  (1.8ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109917
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109918
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109919
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109920
+  (3.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109921
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109922
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109923
+  (1.5ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109924
+  (1.7ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109925
+  (4.7ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
109926
+ FOREIGN KEY ("asset_id")
109927
+ REFERENCES "kithe_models" ("id")
109928
+ 
109929
+  (4.2ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
109930
+ FOREIGN KEY ("containee_id")
109931
+ REFERENCES "kithe_models" ("id")
109932
+ 
109933
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
109934
+ FOREIGN KEY ("container_id")
109935
+ REFERENCES "kithe_models" ("id")
109936
+ 
109937
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109938
+ FOREIGN KEY ("leaf_representative_id")
109939
+ REFERENCES "kithe_models" ("id")
109940
+ 
109941
+  (2.2ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109942
+ FOREIGN KEY ("parent_id")
109943
+ REFERENCES "kithe_models" ("id")
109944
+ 
109945
+  (2.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109946
+ FOREIGN KEY ("representative_id")
109947
+ REFERENCES "kithe_models" ("id")
109948
+ 
109949
+  (3.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109950
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109951
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
109952
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES
109953
+ (20181015143259),
109954
+ (20181015143413),
109955
+ (20181015143737),
109956
+ (20181031190647),
109957
+ (20181128185658),
109958
+ (20190103144947),
109959
+ (20190109192252);
109960
+
109961
+ 
109962
+  (3.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109963
+ ActiveRecord::InternalMetadata Load (2.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109964
+  (0.2ms) BEGIN
109965
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:36.100092"], ["updated_at", "2020-05-27 16:05:36.100092"]]
109966
+  (6.3ms) COMMIT
109967
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109968
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
109969
+  (0.1ms) BEGIN
109970
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:05:36.114811"], ["updated_at", "2020-05-27 16:05:36.114811"]]
109971
+  (5.0ms) COMMIT
109972
+ SQL (43.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109973
+ SQL (0.9ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109974
+  (2.4ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109975
+ RETURNS text
109976
+ LANGUAGE plpgsql
109977
+ AS $function$
109978
+ DECLARE
109979
+ new_id_int bigint;
109980
+ new_id_str character varying := '';
109981
+ done bool;
109982
+ tries integer;
109983
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109984
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109985
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109986
+ alphabet_length integer := array_length(alphabet, 1);
109987
+
109988
+ BEGIN
109989
+ done := false;
109990
+ tries := 0;
109991
+ WHILE (NOT done) LOOP
109992
+ tries := tries + 1;
109993
+ IF (tries > 3) THEN
109994
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109995
+ END IF;
109996
+
109997
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109998
+
109999
+ -- convert bigint to a Base-36 alphanumeric string
110000
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110001
+ -- https://gist.github.com/btbytes/7159902
110002
+ WHILE new_id_int != 0 LOOP
110003
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110004
+ new_id_int := new_id_int / alphabet_length;
110005
+ END LOOP;
110006
+
110007
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110008
+ END LOOP;
110009
+ RETURN new_id_str;
110010
+ END;
110011
+ $function$
110012
+ 
110013
+  (1.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110014
+  (27.4ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110015
+  (2.0ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110016
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110017
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110018
+  (3.5ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110019
+  (2.0ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110020
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110021
+  (0.5ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110022
+  (8.2ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110023
+  (1.4ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110024
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110025
+  (1.4ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110026
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110027
+  (15.7ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110028
+ FOREIGN KEY ("asset_id")
110029
+ REFERENCES "kithe_models" ("id")
110030
+ 
110031
+  (2.2ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110032
+ FOREIGN KEY ("containee_id")
110033
+ REFERENCES "kithe_models" ("id")
110034
+ 
110035
+  (3.1ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110036
+ FOREIGN KEY ("container_id")
110037
+ REFERENCES "kithe_models" ("id")
110038
+ 
110039
+  (3.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110040
+ FOREIGN KEY ("leaf_representative_id")
110041
+ REFERENCES "kithe_models" ("id")
110042
+ 
110043
+  (3.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110044
+ FOREIGN KEY ("parent_id")
110045
+ REFERENCES "kithe_models" ("id")
110046
+ 
110047
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110048
+ FOREIGN KEY ("representative_id")
110049
+ REFERENCES "kithe_models" ("id")
110050
+ 
110051
+  (3.2ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110052
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110053
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
110054
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
110055
+ (20181015143259),
110056
+ (20181015143413),
110057
+ (20181015143737),
110058
+ (20181031190647),
110059
+ (20181128185658),
110060
+ (20190103144947),
110061
+ (20190109192252);
110062
+
110063
+ 
110064
+  (3.5ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110065
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110066
+  (0.2ms) BEGIN
110067
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:36.379857"], ["updated_at", "2020-05-27 16:05:36.379857"]]
110068
+  (0.4ms) COMMIT
110069
+ ActiveRecord::InternalMetadata Load (0.7ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110070
+  (0.3ms) BEGIN
110071
+ ActiveRecord::InternalMetadata Update (1.3ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:05:36.388452"], ["key", "environment"]]
110072
+  (0.6ms) COMMIT
110073
+ ActiveRecord::InternalMetadata Load (0.7ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110074
+  (0.2ms) BEGIN
110075
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:05:36.399100"], ["updated_at", "2020-05-27 16:05:36.399100"]]
110076
+  (0.4ms) COMMIT
110077
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110078
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110079
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110080
+  (0.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110081
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110082
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110083
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110084
+ SQL (0.8ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110085
+  (3.0ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110086
+ RETURNS text
110087
+ LANGUAGE plpgsql
110088
+ AS $function$
110089
+ DECLARE
110090
+ new_id_int bigint;
110091
+ new_id_str character varying := '';
110092
+ done bool;
110093
+ tries integer;
110094
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110095
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110096
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110097
+ alphabet_length integer := array_length(alphabet, 1);
110098
+
110099
+ BEGIN
110100
+ done := false;
110101
+ tries := 0;
110102
+ WHILE (NOT done) LOOP
110103
+ tries := tries + 1;
110104
+ IF (tries > 3) THEN
110105
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110106
+ END IF;
110107
+
110108
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110109
+
110110
+ -- convert bigint to a Base-36 alphanumeric string
110111
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110112
+ -- https://gist.github.com/btbytes/7159902
110113
+ WHILE new_id_int != 0 LOOP
110114
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110115
+ new_id_int := new_id_int / alphabet_length;
110116
+ END LOOP;
110117
+
110118
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110119
+ END LOOP;
110120
+ RETURN new_id_str;
110121
+ END;
110122
+ $function$
110123
+ 
110124
+  (6.9ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110125
+  (6.6ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110126
+  (2.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110127
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110128
+  (2.9ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110129
+  (1.5ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110130
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110131
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110132
+  (4.0ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110133
+  (4.1ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110134
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110135
+  (1.7ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110136
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110137
+  (3.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110138
+  (15.9ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110139
+ FOREIGN KEY ("asset_id")
110140
+ REFERENCES "kithe_models" ("id")
110141
+ 
110142
+  (4.6ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110143
+ FOREIGN KEY ("containee_id")
110144
+ REFERENCES "kithe_models" ("id")
110145
+ 
110146
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110147
+ FOREIGN KEY ("container_id")
110148
+ REFERENCES "kithe_models" ("id")
110149
+ 
110150
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110151
+ FOREIGN KEY ("leaf_representative_id")
110152
+ REFERENCES "kithe_models" ("id")
110153
+ 
110154
+  (3.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110155
+ FOREIGN KEY ("parent_id")
110156
+ REFERENCES "kithe_models" ("id")
110157
+ 
110158
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110159
+ FOREIGN KEY ("representative_id")
110160
+ REFERENCES "kithe_models" ("id")
110161
+ 
110162
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110163
+ ActiveRecord::InternalMetadata Load (1.0ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110164
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110165
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110166
+ SQL (0.6ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110167
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110168
+  (9.8ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110169
+ RETURNS text
110170
+ LANGUAGE plpgsql
110171
+ AS $function$
110172
+ DECLARE
110173
+ new_id_int bigint;
110174
+ new_id_str character varying := '';
110175
+ done bool;
110176
+ tries integer;
110177
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110178
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110179
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110180
+ alphabet_length integer := array_length(alphabet, 1);
110181
+
110182
+ BEGIN
110183
+ done := false;
110184
+ tries := 0;
110185
+ WHILE (NOT done) LOOP
110186
+ tries := tries + 1;
110187
+ IF (tries > 3) THEN
110188
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110189
+ END IF;
110190
+
110191
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110192
+
110193
+ -- convert bigint to a Base-36 alphanumeric string
110194
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110195
+ -- https://gist.github.com/btbytes/7159902
110196
+ WHILE new_id_int != 0 LOOP
110197
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110198
+ new_id_int := new_id_int / alphabet_length;
110199
+ END LOOP;
110200
+
110201
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110202
+ END LOOP;
110203
+ RETURN new_id_str;
110204
+ END;
110205
+ $function$
110206
+ 
110207
+  (23.1ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110208
+  (43.6ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110209
+  (16.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110210
+  (21.5ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110211
+  (3.4ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110212
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110213
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110214
+  (2.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110215
+  (6.6ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110216
+  (6.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110217
+  (1.4ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110218
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110219
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110220
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110221
+  (4.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110222
+ FOREIGN KEY ("asset_id")
110223
+ REFERENCES "kithe_models" ("id")
110224
+ 
110225
+  (3.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110226
+ FOREIGN KEY ("containee_id")
110227
+ REFERENCES "kithe_models" ("id")
110228
+ 
110229
+  (2.3ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110230
+ FOREIGN KEY ("container_id")
110231
+ REFERENCES "kithe_models" ("id")
110232
+ 
110233
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110234
+ FOREIGN KEY ("leaf_representative_id")
110235
+ REFERENCES "kithe_models" ("id")
110236
+ 
110237
+  (4.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110238
+ FOREIGN KEY ("parent_id")
110239
+ REFERENCES "kithe_models" ("id")
110240
+ 
110241
+  (3.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110242
+ FOREIGN KEY ("representative_id")
110243
+ REFERENCES "kithe_models" ("id")
110244
+ 
110245
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110246
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110247
+  (0.2ms) BEGIN
110248
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "development"], ["updated_at", "2020-05-27 16:05:50.059067"], ["key", "environment"]]
110249
+  (0.4ms) COMMIT
110250
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110251
+  (0.2ms) BEGIN
110252
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:05:50.071778"], ["key", "environment"]]
110253
+  (0.4ms) COMMIT
110254
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110255
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110256
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110257
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110258
+  (0.8ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110259
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110260
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110261
+  (215.0ms) DROP DATABASE IF EXISTS "kithe_development"
110262
+  (247.1ms) DROP DATABASE IF EXISTS "kithe_test"
110263
+  (572.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110264
+  (498.2ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110265
+  (15.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110266
+  (26.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110267
+  (0.8ms) SELECT pg_try_advisory_lock(1601470156486188030)
110268
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110269
+ Migrating to EnablePgcryptoExtension (20181015143259)
110270
+  (0.7ms) BEGIN
110271
+ SQL (29.6ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110272
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110273
+  (1.1ms) COMMIT
110274
+ Migrating to CreateKitheModels (20181015143413)
110275
+  (0.2ms) BEGIN
110276
+  (21.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110277
+  (0.4ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110278
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110279
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110280
+ FOREIGN KEY ("parent_id")
110281
+ REFERENCES "kithe_models" ("id")
110282
+ 
110283
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110284
+  (0.4ms) COMMIT
110285
+ Migrating to KitheModelsFriendlierId (20181015143737)
110286
+  (0.3ms) BEGIN
110287
+  (6.8ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110288
+ DECLARE
110289
+ new_id_int bigint;
110290
+ new_id_str character varying := '';
110291
+ done bool;
110292
+ tries integer;
110293
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110294
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110295
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110296
+ alphabet_length integer := array_length(alphabet, 1);
110297
+
110298
+ BEGIN
110299
+ done := false;
110300
+ tries := 0;
110301
+ WHILE (NOT done) LOOP
110302
+ tries := tries + 1;
110303
+ IF (tries > 3) THEN
110304
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110305
+ END IF;
110306
+
110307
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110308
+
110309
+ -- convert bigint to a Base-36 alphanumeric string
110310
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110311
+ -- https://gist.github.com/btbytes/7159902
110312
+ WHILE new_id_int != 0 LOOP
110313
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110314
+ new_id_int := new_id_int / alphabet_length;
110315
+ END LOOP;
110316
+
110317
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110318
+ END LOOP;
110319
+ RETURN new_id_str;
110320
+ END;
110321
+ $$ LANGUAGE plpgsql;
110322
+ 
110323
+  (25.2ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110324
+  (2.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110325
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110326
+  (1.3ms) COMMIT
110327
+ Migrating to AddFileDataToModel (20181031190647)
110328
+  (0.3ms) BEGIN
110329
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
110330
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
110331
+  (6.1ms) COMMIT
110332
+ Migrating to CreateKitheDerivatives (20181128185658)
110333
+  (0.7ms) BEGIN
110334
+  (17.2ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
110335
+ FOREIGN KEY ("asset_id")
110336
+ REFERENCES "kithe_models" ("id")
110337
+ )
110338
+  (5.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110339
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110340
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
110341
+  (0.4ms) COMMIT
110342
+ Migrating to AddRepresentativeRelations (20190103144947)
110343
+  (6.0ms) BEGIN
110344
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
110345
+  (13.1ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110346
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110347
+ FOREIGN KEY ("representative_id")
110348
+ REFERENCES "kithe_models" ("id")
110349
+ 
110350
+  (0.5ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
110351
+  (1.1ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110352
+  (1.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110353
+ FOREIGN KEY ("leaf_representative_id")
110354
+ REFERENCES "kithe_models" ("id")
110355
+ 
110356
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
110357
+  (0.9ms) COMMIT
110358
+ Migrating to ContainsAssociation (20190109192252)
110359
+  (0.3ms) BEGIN
110360
+  (2.1ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
110361
+ FOREIGN KEY ("containee_id")
110362
+ REFERENCES "kithe_models" ("id")
110363
+ , CONSTRAINT "fk_rails_091010187b"
110364
+ FOREIGN KEY ("container_id")
110365
+ REFERENCES "kithe_models" ("id")
110366
+ )
110367
+  (7.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110368
+  (7.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110369
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
110370
+  (0.4ms) COMMIT
110371
+ Migrating to KitheModelType (20190404144551)
110372
+  (0.2ms) BEGIN
110373
+  (0.5ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
110374
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
110375
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
110376
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
110377
+  (6.4ms) COMMIT
110378
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110379
+  (0.2ms) BEGIN
110380
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:23.265055"], ["updated_at", "2020-05-27 16:15:23.265055"]]
110381
+  (0.4ms) COMMIT
110382
+  (0.5ms) SELECT pg_advisory_unlock(1601470156486188030)
110383
+  (1.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110384
+  (4.8ms)  SELECT
110385
+ pp.proname AS name,
110386
+ pg_get_functiondef(pp.oid) AS definition
110387
+ FROM pg_proc pp
110388
+ JOIN pg_namespace pn
110389
+ ON pn.oid = pp.pronamespace
110390
+ LEFT JOIN pg_depend pd
110391
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
110392
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
110393
+ ORDER BY pp.oid;
110394
+ 
110395
+  (1.5ms)  SELECT
110396
+ pt.tgname AS name,
110397
+ pg_get_triggerdef(pt.oid) AS definition
110398
+ FROM pg_trigger pt
110399
+ JOIN pg_class pc
110400
+ ON (pc.oid = pt.tgrelid)
110401
+ JOIN pg_proc pp
110402
+ ON (pp.oid = pt.tgfoid)
110403
+ WHERE pt.tgname
110404
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
110405
+ ORDER BY pc.oid;
110406
+ 
110407
+  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110408
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110409
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110410
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110411
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110412
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110413
+  (207.6ms) DROP DATABASE IF EXISTS "kithe_development"
110414
+  (204.7ms) DROP DATABASE IF EXISTS "kithe_test"
110415
+  (434.7ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110416
+  (556.2ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110417
+ SQL (13.4ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110418
+ SQL (0.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110419
+  (2.7ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110420
+ RETURNS text
110421
+ LANGUAGE plpgsql
110422
+ AS $function$
110423
+ DECLARE
110424
+ new_id_int bigint;
110425
+ new_id_str character varying := '';
110426
+ done bool;
110427
+ tries integer;
110428
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110429
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110430
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110431
+ alphabet_length integer := array_length(alphabet, 1);
110432
+
110433
+ BEGIN
110434
+ done := false;
110435
+ tries := 0;
110436
+ WHILE (NOT done) LOOP
110437
+ tries := tries + 1;
110438
+ IF (tries > 3) THEN
110439
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110440
+ END IF;
110441
+
110442
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110443
+
110444
+ -- convert bigint to a Base-36 alphanumeric string
110445
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110446
+ -- https://gist.github.com/btbytes/7159902
110447
+ WHILE new_id_int != 0 LOOP
110448
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110449
+ new_id_int := new_id_int / alphabet_length;
110450
+ END LOOP;
110451
+
110452
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110453
+ END LOOP;
110454
+ RETURN new_id_str;
110455
+ END;
110456
+ $function$
110457
+ 
110458
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110459
+  (7.5ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110460
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110461
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110462
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110463
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110464
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110465
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110466
+  (0.4ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110467
+  (7.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110468
+  (2.5ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110469
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110470
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110471
+  (1.9ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110472
+  (3.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110473
+ FOREIGN KEY ("asset_id")
110474
+ REFERENCES "kithe_models" ("id")
110475
+ 
110476
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110477
+ FOREIGN KEY ("containee_id")
110478
+ REFERENCES "kithe_models" ("id")
110479
+ 
110480
+  (2.1ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110481
+ FOREIGN KEY ("container_id")
110482
+ REFERENCES "kithe_models" ("id")
110483
+ 
110484
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110485
+ FOREIGN KEY ("leaf_representative_id")
110486
+ REFERENCES "kithe_models" ("id")
110487
+ 
110488
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110489
+ FOREIGN KEY ("parent_id")
110490
+ REFERENCES "kithe_models" ("id")
110491
+ 
110492
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110493
+ FOREIGN KEY ("representative_id")
110494
+ REFERENCES "kithe_models" ("id")
110495
+ 
110496
+  (6.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110497
+  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110498
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
110499
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES
110500
+ (20181015143259),
110501
+ (20181015143413),
110502
+ (20181015143737),
110503
+ (20181031190647),
110504
+ (20181128185658),
110505
+ (20190103144947),
110506
+ (20190109192252);
110507
+
110508
+ 
110509
+  (3.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110510
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110511
+  (0.2ms) BEGIN
110512
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:41.046597"], ["updated_at", "2020-05-27 16:15:41.046597"]]
110513
+  (0.4ms) COMMIT
110514
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110515
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110516
+  (0.2ms) BEGIN
110517
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:15:41.055003"], ["updated_at", "2020-05-27 16:15:41.055003"]]
110518
+  (0.4ms) COMMIT
110519
+ SQL (17.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110520
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110521
+  (9.5ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110522
+ RETURNS text
110523
+ LANGUAGE plpgsql
110524
+ AS $function$
110525
+ DECLARE
110526
+ new_id_int bigint;
110527
+ new_id_str character varying := '';
110528
+ done bool;
110529
+ tries integer;
110530
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110531
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110532
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110533
+ alphabet_length integer := array_length(alphabet, 1);
110534
+
110535
+ BEGIN
110536
+ done := false;
110537
+ tries := 0;
110538
+ WHILE (NOT done) LOOP
110539
+ tries := tries + 1;
110540
+ IF (tries > 3) THEN
110541
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110542
+ END IF;
110543
+
110544
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110545
+
110546
+ -- convert bigint to a Base-36 alphanumeric string
110547
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110548
+ -- https://gist.github.com/btbytes/7159902
110549
+ WHILE new_id_int != 0 LOOP
110550
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110551
+ new_id_int := new_id_int / alphabet_length;
110552
+ END LOOP;
110553
+
110554
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110555
+ END LOOP;
110556
+ RETURN new_id_str;
110557
+ END;
110558
+ $function$
110559
+ 
110560
+  (0.5ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110561
+  (8.3ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110562
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110563
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110564
+  (0.3ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110565
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110566
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110567
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110568
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110569
+  (6.3ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110570
+  (2.7ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110571
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110572
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110573
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110574
+  (3.6ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110575
+ FOREIGN KEY ("asset_id")
110576
+ REFERENCES "kithe_models" ("id")
110577
+ 
110578
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110579
+ FOREIGN KEY ("containee_id")
110580
+ REFERENCES "kithe_models" ("id")
110581
+ 
110582
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110583
+ FOREIGN KEY ("container_id")
110584
+ REFERENCES "kithe_models" ("id")
110585
+ 
110586
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110587
+ FOREIGN KEY ("leaf_representative_id")
110588
+ REFERENCES "kithe_models" ("id")
110589
+ 
110590
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110591
+ FOREIGN KEY ("parent_id")
110592
+ REFERENCES "kithe_models" ("id")
110593
+ 
110594
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110595
+ FOREIGN KEY ("representative_id")
110596
+ REFERENCES "kithe_models" ("id")
110597
+ 
110598
+  (3.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110599
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110600
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
110601
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
110602
+ (20181015143259),
110603
+ (20181015143413),
110604
+ (20181015143737),
110605
+ (20181031190647),
110606
+ (20181128185658),
110607
+ (20190103144947),
110608
+ (20190109192252);
110609
+
110610
+ 
110611
+  (4.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110612
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110613
+  (0.2ms) BEGIN
110614
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:41.295599"], ["updated_at", "2020-05-27 16:15:41.295599"]]
110615
+  (0.9ms) COMMIT
110616
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110617
+  (0.2ms) BEGIN
110618
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:15:41.302574"], ["key", "environment"]]
110619
+  (0.4ms) COMMIT
110620
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110621
+  (0.2ms) BEGIN
110622
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:15:41.308393"], ["updated_at", "2020-05-27 16:15:41.308393"]]
110623
+  (0.4ms) COMMIT
110624
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110625
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110626
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110627
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110628
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110629
+  (0.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110630
+  (217.9ms) DROP DATABASE IF EXISTS "kithe_development"
110631
+  (219.9ms) DROP DATABASE IF EXISTS "kithe_test"
110632
+  (498.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110633
+  (549.0ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110634
+  (16.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110635
+  (111.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110636
+  (1.1ms) SELECT pg_try_advisory_lock(1601470156486188030)
110637
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110638
+ Migrating to EnablePgcryptoExtension (20181015143259)
110639
+  (0.2ms) BEGIN
110640
+ SQL (13.7ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110641
+ primary::SchemaMigration Create (20.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110642
+  (2.0ms) COMMIT
110643
+ Migrating to CreateKitheModels (20181015143413)
110644
+  (0.5ms) BEGIN
110645
+  (5.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110646
+  (0.6ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110647
+  (1.7ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110648
+  (4.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110649
+ FOREIGN KEY ("parent_id")
110650
+ REFERENCES "kithe_models" ("id")
110651
+ 
110652
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110653
+  (0.7ms) COMMIT
110654
+ Migrating to KitheModelsFriendlierId (20181015143737)
110655
+  (0.3ms) BEGIN
110656
+  (8.1ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110657
+ DECLARE
110658
+ new_id_int bigint;
110659
+ new_id_str character varying := '';
110660
+ done bool;
110661
+ tries integer;
110662
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110663
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110664
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110665
+ alphabet_length integer := array_length(alphabet, 1);
110666
+
110667
+ BEGIN
110668
+ done := false;
110669
+ tries := 0;
110670
+ WHILE (NOT done) LOOP
110671
+ tries := tries + 1;
110672
+ IF (tries > 3) THEN
110673
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110674
+ END IF;
110675
+
110676
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110677
+
110678
+ -- convert bigint to a Base-36 alphanumeric string
110679
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110680
+ -- https://gist.github.com/btbytes/7159902
110681
+ WHILE new_id_int != 0 LOOP
110682
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110683
+ new_id_int := new_id_int / alphabet_length;
110684
+ END LOOP;
110685
+
110686
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110687
+ END LOOP;
110688
+ RETURN new_id_str;
110689
+ END;
110690
+ $$ LANGUAGE plpgsql;
110691
+ 
110692
+  (5.6ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110693
+  (1.0ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110694
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110695
+  (1.1ms) COMMIT
110696
+ Migrating to AddFileDataToModel (20181031190647)
110697
+  (0.3ms) BEGIN
110698
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
110699
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
110700
+  (0.4ms) COMMIT
110701
+ Migrating to CreateKitheDerivatives (20181128185658)
110702
+  (0.3ms) BEGIN
110703
+  (7.2ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
110704
+ FOREIGN KEY ("asset_id")
110705
+ REFERENCES "kithe_models" ("id")
110706
+ )
110707
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110708
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110709
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
110710
+  (0.7ms) COMMIT
110711
+ Migrating to AddRepresentativeRelations (20190103144947)
110712
+  (3.1ms) BEGIN
110713
+  (1.3ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
110714
+  (1.4ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110715
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110716
+ FOREIGN KEY ("representative_id")
110717
+ REFERENCES "kithe_models" ("id")
110718
+ 
110719
+  (0.5ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
110720
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110721
+  (3.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110722
+ FOREIGN KEY ("leaf_representative_id")
110723
+ REFERENCES "kithe_models" ("id")
110724
+ 
110725
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
110726
+  (5.4ms) COMMIT
110727
+ Migrating to ContainsAssociation (20190109192252)
110728
+  (0.2ms) BEGIN
110729
+  (2.3ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
110730
+ FOREIGN KEY ("containee_id")
110731
+ REFERENCES "kithe_models" ("id")
110732
+ , CONSTRAINT "fk_rails_091010187b"
110733
+ FOREIGN KEY ("container_id")
110734
+ REFERENCES "kithe_models" ("id")
110735
+ )
110736
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110737
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110738
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
110739
+  (0.4ms) COMMIT
110740
+ Migrating to KitheModelType (20190404144551)
110741
+  (0.2ms) BEGIN
110742
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
110743
+  (0.6ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
110744
+  (0.5ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
110745
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
110746
+  (0.7ms) COMMIT
110747
+ ActiveRecord::InternalMetadata Load (1.0ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110748
+  (0.1ms) BEGIN
110749
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:16:55.002081"], ["updated_at", "2020-05-27 16:16:55.002081"]]
110750
+  (0.4ms) COMMIT
110751
+  (0.5ms) SELECT pg_advisory_unlock(1601470156486188030)
110752
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110753
+  (5.2ms)  SELECT
110754
+ pp.proname AS name,
110755
+ pg_get_functiondef(pp.oid) AS definition
110756
+ FROM pg_proc pp
110757
+ JOIN pg_namespace pn
110758
+ ON pn.oid = pp.pronamespace
110759
+ LEFT JOIN pg_depend pd
110760
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
110761
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
110762
+ ORDER BY pp.oid;
110763
+ 
110764
+  (2.2ms)  SELECT
110765
+ pt.tgname AS name,
110766
+ pg_get_triggerdef(pt.oid) AS definition
110767
+ FROM pg_trigger pt
110768
+ JOIN pg_class pc
110769
+ ON (pc.oid = pt.tgrelid)
110770
+ JOIN pg_proc pp
110771
+ ON (pp.oid = pt.tgfoid)
110772
+ WHERE pt.tgname
110773
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
110774
+ ORDER BY pc.oid;
110775
+ 
110776
+  (1.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110777
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110778
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110779
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110780
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110781
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110782
+  (205.7ms) DROP DATABASE IF EXISTS "kithe_development"
110783
+  (212.8ms) DROP DATABASE IF EXISTS "kithe_test"
110784
+  (538.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110785
+  (495.1ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110786
+  (54.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110787
+  (5.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110788
+  (0.4ms) SELECT pg_try_advisory_lock(1601470156486188030)
110789
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110790
+ Migrating to EnablePgcryptoExtension (20181015143259)
110791
+  (0.3ms) BEGIN
110792
+ SQL (21.7ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110793
+ primary::SchemaMigration Create (1.7ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110794
+  (2.1ms) COMMIT
110795
+ Migrating to CreateKitheModels (20181015143413)
110796
+  (0.2ms) BEGIN
110797
+  (4.0ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110798
+  (0.8ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110799
+  (1.4ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110800
+  (2.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110801
+ FOREIGN KEY ("parent_id")
110802
+ REFERENCES "kithe_models" ("id")
110803
+ 
110804
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110805
+  (0.4ms) COMMIT
110806
+ Migrating to KitheModelsFriendlierId (20181015143737)
110807
+  (0.4ms) BEGIN
110808
+  (7.4ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110809
+ DECLARE
110810
+ new_id_int bigint;
110811
+ new_id_str character varying := '';
110812
+ done bool;
110813
+ tries integer;
110814
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110815
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110816
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110817
+ alphabet_length integer := array_length(alphabet, 1);
110818
+
110819
+ BEGIN
110820
+ done := false;
110821
+ tries := 0;
110822
+ WHILE (NOT done) LOOP
110823
+ tries := tries + 1;
110824
+ IF (tries > 3) THEN
110825
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110826
+ END IF;
110827
+
110828
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110829
+
110830
+ -- convert bigint to a Base-36 alphanumeric string
110831
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110832
+ -- https://gist.github.com/btbytes/7159902
110833
+ WHILE new_id_int != 0 LOOP
110834
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110835
+ new_id_int := new_id_int / alphabet_length;
110836
+ END LOOP;
110837
+
110838
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110839
+ END LOOP;
110840
+ RETURN new_id_str;
110841
+ END;
110842
+ $$ LANGUAGE plpgsql;
110843
+ 
110844
+  (20.1ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110845
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110846
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110847
+  (1.4ms) COMMIT
110848
+ Migrating to AddFileDataToModel (20181031190647)
110849
+  (0.3ms) BEGIN
110850
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
110851
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
110852
+  (0.4ms) COMMIT
110853
+ Migrating to CreateKitheDerivatives (20181128185658)
110854
+  (0.2ms) BEGIN
110855
+  (8.1ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
110856
+ FOREIGN KEY ("asset_id")
110857
+ REFERENCES "kithe_models" ("id")
110858
+ )
110859
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110860
+  (1.4ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110861
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
110862
+  (0.5ms) COMMIT
110863
+ Migrating to AddRepresentativeRelations (20190103144947)
110864
+  (6.4ms) BEGIN
110865
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
110866
+  (7.5ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110867
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110868
+ FOREIGN KEY ("representative_id")
110869
+ REFERENCES "kithe_models" ("id")
110870
+ 
110871
+  (0.4ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
110872
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110873
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110874
+ FOREIGN KEY ("leaf_representative_id")
110875
+ REFERENCES "kithe_models" ("id")
110876
+ 
110877
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
110878
+  (0.4ms) COMMIT
110879
+ Migrating to ContainsAssociation (20190109192252)
110880
+  (0.3ms) BEGIN
110881
+  (2.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
110882
+ FOREIGN KEY ("containee_id")
110883
+ REFERENCES "kithe_models" ("id")
110884
+ , CONSTRAINT "fk_rails_091010187b"
110885
+ FOREIGN KEY ("container_id")
110886
+ REFERENCES "kithe_models" ("id")
110887
+ )
110888
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110889
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110890
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
110891
+  (0.4ms) COMMIT
110892
+ Migrating to KitheModelType (20190404144551)
110893
+  (0.2ms) BEGIN
110894
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
110895
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
110896
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
110897
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
110898
+  (0.5ms) COMMIT
110899
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110900
+  (0.2ms) BEGIN
110901
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:01.957849"], ["updated_at", "2020-05-27 16:19:01.957849"]]
110902
+  (0.4ms) COMMIT
110903
+  (0.7ms) SELECT pg_advisory_unlock(1601470156486188030)
110904
+  (2.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110905
+  (5.0ms)  SELECT
110906
+ pp.proname AS name,
110907
+ pg_get_functiondef(pp.oid) AS definition
110908
+ FROM pg_proc pp
110909
+ JOIN pg_namespace pn
110910
+ ON pn.oid = pp.pronamespace
110911
+ LEFT JOIN pg_depend pd
110912
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
110913
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
110914
+ ORDER BY pp.oid;
110915
+ 
110916
+  (1.8ms)  SELECT
110917
+ pt.tgname AS name,
110918
+ pg_get_triggerdef(pt.oid) AS definition
110919
+ FROM pg_trigger pt
110920
+ JOIN pg_class pc
110921
+ ON (pc.oid = pt.tgrelid)
110922
+ JOIN pg_proc pp
110923
+ ON (pp.oid = pt.tgfoid)
110924
+ WHERE pt.tgname
110925
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
110926
+ ORDER BY pc.oid;
110927
+ 
110928
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110929
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110930
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110931
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110932
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110933
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110934
+  (209.2ms) DROP DATABASE IF EXISTS "kithe_development"
110935
+  (206.0ms) DROP DATABASE IF EXISTS "kithe_test"
110936
+  (512.2ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110937
+  (434.6ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110938
+  (7.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110939
+  (6.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110940
+  (0.3ms) SELECT pg_try_advisory_lock(1601470156486188030)
110941
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110942
+ Migrating to EnablePgcryptoExtension (20181015143259)
110943
+  (0.2ms) BEGIN
110944
+ SQL (17.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110945
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110946
+  (1.4ms) COMMIT
110947
+ Migrating to CreateKitheModels (20181015143413)
110948
+  (0.2ms) BEGIN
110949
+  (4.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110950
+  (0.6ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110951
+  (16.7ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110952
+  (7.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110953
+ FOREIGN KEY ("parent_id")
110954
+ REFERENCES "kithe_models" ("id")
110955
+ 
110956
+ primary::SchemaMigration Create (82.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110957
+  (6.1ms) COMMIT
110958
+ Migrating to KitheModelsFriendlierId (20181015143737)
110959
+  (0.3ms) BEGIN
110960
+  (2.7ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110961
+ DECLARE
110962
+ new_id_int bigint;
110963
+ new_id_str character varying := '';
110964
+ done bool;
110965
+ tries integer;
110966
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110967
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110968
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110969
+ alphabet_length integer := array_length(alphabet, 1);
110970
+
110971
+ BEGIN
110972
+ done := false;
110973
+ tries := 0;
110974
+ WHILE (NOT done) LOOP
110975
+ tries := tries + 1;
110976
+ IF (tries > 3) THEN
110977
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110978
+ END IF;
110979
+
110980
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110981
+
110982
+ -- convert bigint to a Base-36 alphanumeric string
110983
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110984
+ -- https://gist.github.com/btbytes/7159902
110985
+ WHILE new_id_int != 0 LOOP
110986
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110987
+ new_id_int := new_id_int / alphabet_length;
110988
+ END LOOP;
110989
+
110990
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110991
+ END LOOP;
110992
+ RETURN new_id_str;
110993
+ END;
110994
+ $$ LANGUAGE plpgsql;
110995
+ 
110996
+  (16.0ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110997
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110998
+ primary::SchemaMigration Create (1.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110999
+  (2.0ms) COMMIT
111000
+ Migrating to AddFileDataToModel (20181031190647)
111001
+  (1.1ms) BEGIN
111002
+  (1.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
111003
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
111004
+  (0.8ms) COMMIT
111005
+ Migrating to CreateKitheDerivatives (20181128185658)
111006
+  (1.9ms) BEGIN
111007
+  (7.2ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
111008
+ FOREIGN KEY ("asset_id")
111009
+ REFERENCES "kithe_models" ("id")
111010
+ )
111011
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111012
+  (1.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111013
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
111014
+  (0.5ms) COMMIT
111015
+ Migrating to AddRepresentativeRelations (20190103144947)
111016
+  (0.4ms) BEGIN
111017
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
111018
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111019
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111020
+ FOREIGN KEY ("representative_id")
111021
+ REFERENCES "kithe_models" ("id")
111022
+ 
111023
+  (0.7ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
111024
+  (3.9ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111025
+  (3.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111026
+ FOREIGN KEY ("leaf_representative_id")
111027
+ REFERENCES "kithe_models" ("id")
111028
+ 
111029
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
111030
+  (0.5ms) COMMIT
111031
+ Migrating to ContainsAssociation (20190109192252)
111032
+  (0.3ms) BEGIN
111033
+  (2.0ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
111034
+ FOREIGN KEY ("containee_id")
111035
+ REFERENCES "kithe_models" ("id")
111036
+ , CONSTRAINT "fk_rails_091010187b"
111037
+ FOREIGN KEY ("container_id")
111038
+ REFERENCES "kithe_models" ("id")
111039
+ )
111040
+  (2.0ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111041
+  (1.0ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111042
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
111043
+  (0.4ms) COMMIT
111044
+ Migrating to KitheModelType (20190404144551)
111045
+  (0.3ms) BEGIN
111046
+  (0.5ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
111047
+  (1.3ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
111048
+  (0.9ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
111049
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
111050
+  (0.4ms) COMMIT
111051
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111052
+  (0.2ms) BEGIN
111053
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:20.045824"], ["updated_at", "2020-05-27 16:19:20.045824"]]
111054
+  (0.8ms) COMMIT
111055
+  (0.5ms) SELECT pg_advisory_unlock(1601470156486188030)
111056
+  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111057
+  (5.0ms)  SELECT
111058
+ pp.proname AS name,
111059
+ pg_get_functiondef(pp.oid) AS definition
111060
+ FROM pg_proc pp
111061
+ JOIN pg_namespace pn
111062
+ ON pn.oid = pp.pronamespace
111063
+ LEFT JOIN pg_depend pd
111064
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
111065
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
111066
+ ORDER BY pp.oid;
111067
+ 
111068
+  (1.9ms)  SELECT
111069
+ pt.tgname AS name,
111070
+ pg_get_triggerdef(pt.oid) AS definition
111071
+ FROM pg_trigger pt
111072
+ JOIN pg_class pc
111073
+ ON (pc.oid = pt.tgrelid)
111074
+ JOIN pg_proc pp
111075
+ ON (pp.oid = pt.tgfoid)
111076
+ WHERE pt.tgname
111077
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
111078
+ ORDER BY pc.oid;
111079
+ 
111080
+  (18.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111081
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111082
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111083
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111084
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111085
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111086
+  (215.3ms) DROP DATABASE IF EXISTS "kithe_development"
111087
+  (375.5ms) DROP DATABASE IF EXISTS "kithe_test"
111088
+  (458.1ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
111089
+  (933.1ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
111090
+ SQL (12.8ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111091
+ SQL (0.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111092
+  (2.4ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111093
+ RETURNS text
111094
+ LANGUAGE plpgsql
111095
+ AS $function$
111096
+ DECLARE
111097
+ new_id_int bigint;
111098
+ new_id_str character varying := '';
111099
+ done bool;
111100
+ tries integer;
111101
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111102
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111103
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111104
+ alphabet_length integer := array_length(alphabet, 1);
111105
+
111106
+ BEGIN
111107
+ done := false;
111108
+ tries := 0;
111109
+ WHILE (NOT done) LOOP
111110
+ tries := tries + 1;
111111
+ IF (tries > 3) THEN
111112
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111113
+ END IF;
111114
+
111115
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111116
+
111117
+ -- convert bigint to a Base-36 alphanumeric string
111118
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111119
+ -- https://gist.github.com/btbytes/7159902
111120
+ WHILE new_id_int != 0 LOOP
111121
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111122
+ new_id_int := new_id_int / alphabet_length;
111123
+ END LOOP;
111124
+
111125
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111126
+ END LOOP;
111127
+ RETURN new_id_str;
111128
+ END;
111129
+ $function$
111130
+ 
111131
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111132
+  (6.7ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111133
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111134
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111135
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111136
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111137
+  (1.5ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111138
+  (2.5ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111139
+  (0.5ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111140
+  (7.8ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111141
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111142
+  (23.6ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111143
+  (8.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111144
+  (1.6ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111145
+  (3.6ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111146
+ FOREIGN KEY ("asset_id")
111147
+ REFERENCES "kithe_models" ("id")
111148
+ 
111149
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111150
+ FOREIGN KEY ("containee_id")
111151
+ REFERENCES "kithe_models" ("id")
111152
+ 
111153
+  (2.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111154
+ FOREIGN KEY ("container_id")
111155
+ REFERENCES "kithe_models" ("id")
111156
+ 
111157
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111158
+ FOREIGN KEY ("leaf_representative_id")
111159
+ REFERENCES "kithe_models" ("id")
111160
+ 
111161
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111162
+ FOREIGN KEY ("parent_id")
111163
+ REFERENCES "kithe_models" ("id")
111164
+ 
111165
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111166
+ FOREIGN KEY ("representative_id")
111167
+ REFERENCES "kithe_models" ("id")
111168
+ 
111169
+  (3.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111170
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111171
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111172
+  (10.3ms) INSERT INTO "schema_migrations" (version) VALUES
111173
+ (20181015143259),
111174
+ (20181015143413),
111175
+ (20181015143737),
111176
+ (20181031190647),
111177
+ (20181128185658),
111178
+ (20190103144947),
111179
+ (20190109192252);
111180
+
111181
+ 
111182
+  (13.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111183
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111184
+  (0.2ms) BEGIN
111185
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:32.359365"], ["updated_at", "2020-05-27 16:19:32.359365"]]
111186
+  (0.4ms) COMMIT
111187
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111188
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111189
+  (0.2ms) BEGIN
111190
+ ActiveRecord::InternalMetadata Create (0.8ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "42c53de0cd440a8a7ed21435cee78257b6e0c991"], ["created_at", "2020-05-27 16:19:32.368638"], ["updated_at", "2020-05-27 16:19:32.368638"]]
111191
+  (0.6ms) COMMIT
111192
+ SQL (19.4ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111193
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111194
+  (2.5ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111195
+ RETURNS text
111196
+ LANGUAGE plpgsql
111197
+ AS $function$
111198
+ DECLARE
111199
+ new_id_int bigint;
111200
+ new_id_str character varying := '';
111201
+ done bool;
111202
+ tries integer;
111203
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111204
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111205
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111206
+ alphabet_length integer := array_length(alphabet, 1);
111207
+
111208
+ BEGIN
111209
+ done := false;
111210
+ tries := 0;
111211
+ WHILE (NOT done) LOOP
111212
+ tries := tries + 1;
111213
+ IF (tries > 3) THEN
111214
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111215
+ END IF;
111216
+
111217
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111218
+
111219
+ -- convert bigint to a Base-36 alphanumeric string
111220
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111221
+ -- https://gist.github.com/btbytes/7159902
111222
+ WHILE new_id_int != 0 LOOP
111223
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111224
+ new_id_int := new_id_int / alphabet_length;
111225
+ END LOOP;
111226
+
111227
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111228
+ END LOOP;
111229
+ RETURN new_id_str;
111230
+ END;
111231
+ $function$
111232
+ 
111233
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111234
+  (15.3ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111235
+  (4.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111236
+  (2.7ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111237
+  (0.4ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111238
+  (3.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111239
+  (2.3ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111240
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111241
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111242
+  (3.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111243
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111244
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111245
+  (2.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111246
+  (2.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111247
+  (5.0ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111248
+ FOREIGN KEY ("asset_id")
111249
+ REFERENCES "kithe_models" ("id")
111250
+ 
111251
+  (2.2ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111252
+ FOREIGN KEY ("containee_id")
111253
+ REFERENCES "kithe_models" ("id")
111254
+ 
111255
+  (45.4ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111256
+ FOREIGN KEY ("container_id")
111257
+ REFERENCES "kithe_models" ("id")
111258
+ 
111259
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111260
+ FOREIGN KEY ("leaf_representative_id")
111261
+ REFERENCES "kithe_models" ("id")
111262
+ 
111263
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111264
+ FOREIGN KEY ("parent_id")
111265
+ REFERENCES "kithe_models" ("id")
111266
+ 
111267
+  (9.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111268
+ FOREIGN KEY ("representative_id")
111269
+ REFERENCES "kithe_models" ("id")
111270
+ 
111271
+  (5.2ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111272
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111273
+  (3.2ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111274
+  (4.5ms) INSERT INTO "schema_migrations" (version) VALUES
111275
+ (20181015143259),
111276
+ (20181015143413),
111277
+ (20181015143737),
111278
+ (20181031190647),
111279
+ (20181128185658),
111280
+ (20190103144947),
111281
+ (20190109192252);
111282
+
111283
+ 
111284
+  (42.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111285
+ ActiveRecord::InternalMetadata Load (2.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111286
+  (0.2ms) BEGIN
111287
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:32.703724"], ["updated_at", "2020-05-27 16:19:32.703724"]]
111288
+  (0.4ms) COMMIT
111289
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111290
+  (0.2ms) BEGIN
111291
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:19:32.711074"], ["key", "environment"]]
111292
+  (0.4ms) COMMIT
111293
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111294
+  (0.2ms) BEGIN
111295
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "42c53de0cd440a8a7ed21435cee78257b6e0c991"], ["created_at", "2020-05-27 16:19:32.718252"], ["updated_at", "2020-05-27 16:19:32.718252"]]
111296
+  (0.7ms) COMMIT
111297
+  (16.6ms) SELECT pg_try_advisory_lock(1601470156486188030)
111298
+  (2.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111299
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111300
+  (0.3ms) SELECT pg_advisory_unlock(1601470156486188030)
111301
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111302
+  (66.1ms)  SELECT
111303
+ pp.proname AS name,
111304
+ pg_get_functiondef(pp.oid) AS definition
111305
+ FROM pg_proc pp
111306
+ JOIN pg_namespace pn
111307
+ ON pn.oid = pp.pronamespace
111308
+ LEFT JOIN pg_depend pd
111309
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
111310
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
111311
+ ORDER BY pp.oid;
111312
+ 
111313
+  (2.0ms)  SELECT
111314
+ pt.tgname AS name,
111315
+ pg_get_triggerdef(pt.oid) AS definition
111316
+ FROM pg_trigger pt
111317
+ JOIN pg_class pc
111318
+ ON (pc.oid = pt.tgrelid)
111319
+ JOIN pg_proc pp
111320
+ ON (pp.oid = pt.tgfoid)
111321
+ WHERE pt.tgname
111322
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
111323
+ ORDER BY pc.oid;
111324
+ 
111325
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111326
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111327
+  (0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111328
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111329
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111330
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111331
+  (239.7ms) DROP DATABASE IF EXISTS "kithe_development"
111332
+  (242.5ms) DROP DATABASE IF EXISTS "kithe_test"
111333
+  (905.5ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
111334
+  (604.8ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
111335
+ SQL (73.8ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111336
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111337
+  (98.8ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111338
+ RETURNS text
111339
+ LANGUAGE plpgsql
111340
+ AS $function$
111341
+ DECLARE
111342
+ new_id_int bigint;
111343
+ new_id_str character varying := '';
111344
+ done bool;
111345
+ tries integer;
111346
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111347
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111348
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111349
+ alphabet_length integer := array_length(alphabet, 1);
111350
+
111351
+ BEGIN
111352
+ done := false;
111353
+ tries := 0;
111354
+ WHILE (NOT done) LOOP
111355
+ tries := tries + 1;
111356
+ IF (tries > 3) THEN
111357
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111358
+ END IF;
111359
+
111360
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111361
+
111362
+ -- convert bigint to a Base-36 alphanumeric string
111363
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111364
+ -- https://gist.github.com/btbytes/7159902
111365
+ WHILE new_id_int != 0 LOOP
111366
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111367
+ new_id_int := new_id_int / alphabet_length;
111368
+ END LOOP;
111369
+
111370
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111371
+ END LOOP;
111372
+ RETURN new_id_str;
111373
+ END;
111374
+ $function$
111375
+ 
111376
+  (5.8ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111377
+  (23.5ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111378
+  (2.7ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111379
+  (2.7ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111380
+  (0.4ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111381
+  (2.9ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111382
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111383
+  (3.0ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111384
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111385
+  (5.1ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111386
+  (1.5ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111387
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111388
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111389
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111390
+  (7.8ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111391
+ FOREIGN KEY ("asset_id")
111392
+ REFERENCES "kithe_models" ("id")
111393
+ 
111394
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111395
+ FOREIGN KEY ("containee_id")
111396
+ REFERENCES "kithe_models" ("id")
111397
+ 
111398
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111399
+ FOREIGN KEY ("container_id")
111400
+ REFERENCES "kithe_models" ("id")
111401
+ 
111402
+  (2.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111403
+ FOREIGN KEY ("leaf_representative_id")
111404
+ REFERENCES "kithe_models" ("id")
111405
+ 
111406
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111407
+ FOREIGN KEY ("parent_id")
111408
+ REFERENCES "kithe_models" ("id")
111409
+ 
111410
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111411
+ FOREIGN KEY ("representative_id")
111412
+ REFERENCES "kithe_models" ("id")
111413
+ 
111414
+  (3.5ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111415
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111416
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111417
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES
111418
+ (20181015143259),
111419
+ (20181015143413),
111420
+ (20181015143737),
111421
+ (20181031190647),
111422
+ (20181128185658),
111423
+ (20190103144947),
111424
+ (20190109192252);
111425
+
111426
+ 
111427
+  (3.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111428
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111429
+  (0.2ms) BEGIN
111430
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-28 13:26:55.432158"], ["updated_at", "2020-05-28 13:26:55.432158"]]
111431
+  (0.5ms) COMMIT
111432
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111433
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111434
+  (0.1ms) BEGIN
111435
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-28 13:26:55.460004"], ["updated_at", "2020-05-28 13:26:55.460004"]]
111436
+  (0.4ms) COMMIT
111437
+ SQL (16.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111438
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111439
+  (2.3ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111440
+ RETURNS text
111441
+ LANGUAGE plpgsql
111442
+ AS $function$
111443
+ DECLARE
111444
+ new_id_int bigint;
111445
+ new_id_str character varying := '';
111446
+ done bool;
111447
+ tries integer;
111448
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111449
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111450
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111451
+ alphabet_length integer := array_length(alphabet, 1);
111452
+
111453
+ BEGIN
111454
+ done := false;
111455
+ tries := 0;
111456
+ WHILE (NOT done) LOOP
111457
+ tries := tries + 1;
111458
+ IF (tries > 3) THEN
111459
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111460
+ END IF;
111461
+
111462
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111463
+
111464
+ -- convert bigint to a Base-36 alphanumeric string
111465
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111466
+ -- https://gist.github.com/btbytes/7159902
111467
+ WHILE new_id_int != 0 LOOP
111468
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111469
+ new_id_int := new_id_int / alphabet_length;
111470
+ END LOOP;
111471
+
111472
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111473
+ END LOOP;
111474
+ RETURN new_id_str;
111475
+ END;
111476
+ $function$
111477
+ 
111478
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111479
+  (6.7ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111480
+  (2.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111481
+  (1.8ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111482
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111483
+  (1.6ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111484
+  (1.9ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111485
+  (1.5ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111486
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111487
+  (3.9ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111488
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111489
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111490
+  (12.7ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111491
+  (12.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111492
+  (5.1ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111493
+ FOREIGN KEY ("asset_id")
111494
+ REFERENCES "kithe_models" ("id")
111495
+ 
111496
+  (2.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111497
+ FOREIGN KEY ("containee_id")
111498
+ REFERENCES "kithe_models" ("id")
111499
+ 
111500
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111501
+ FOREIGN KEY ("container_id")
111502
+ REFERENCES "kithe_models" ("id")
111503
+ 
111504
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111505
+ FOREIGN KEY ("leaf_representative_id")
111506
+ REFERENCES "kithe_models" ("id")
111507
+ 
111508
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111509
+ FOREIGN KEY ("parent_id")
111510
+ REFERENCES "kithe_models" ("id")
111511
+ 
111512
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111513
+ FOREIGN KEY ("representative_id")
111514
+ REFERENCES "kithe_models" ("id")
111515
+ 
111516
+  (3.7ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111517
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111518
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111519
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
111520
+ (20181015143259),
111521
+ (20181015143413),
111522
+ (20181015143737),
111523
+ (20181031190647),
111524
+ (20181128185658),
111525
+ (20190103144947),
111526
+ (20190109192252);
111527
+
111528
+ 
111529
+  (3.3ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111530
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111531
+  (0.2ms) BEGIN
111532
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-28 13:26:55.653588"], ["updated_at", "2020-05-28 13:26:55.653588"]]
111533
+  (0.7ms) COMMIT
111534
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111535
+  (0.2ms) BEGIN
111536
+ ActiveRecord::InternalMetadata Update (0.6ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-28 13:26:55.661463"], ["key", "environment"]]
111537
+  (0.3ms) COMMIT
111538
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111539
+  (0.2ms) BEGIN
111540
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-28 13:26:55.668516"], ["updated_at", "2020-05-28 13:26:55.668516"]]
111541
+  (0.5ms) COMMIT
111542
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111543
+  (2.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111544
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111545
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111546
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111547
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111548
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111549
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111550
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111551
+  (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111552
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111553
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111554
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111555
+ SQL (38.3ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111556
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111557
+  (32.7ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111558
+ RETURNS text
111559
+ LANGUAGE plpgsql
111560
+ AS $function$
111561
+ DECLARE
111562
+ new_id_int bigint;
111563
+ new_id_str character varying := '';
111564
+ done bool;
111565
+ tries integer;
111566
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111567
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111568
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111569
+ alphabet_length integer := array_length(alphabet, 1);
111570
+
111571
+ BEGIN
111572
+ done := false;
111573
+ tries := 0;
111574
+ WHILE (NOT done) LOOP
111575
+ tries := tries + 1;
111576
+ IF (tries > 3) THEN
111577
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111578
+ END IF;
111579
+
111580
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111581
+
111582
+ -- convert bigint to a Base-36 alphanumeric string
111583
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111584
+ -- https://gist.github.com/btbytes/7159902
111585
+ WHILE new_id_int != 0 LOOP
111586
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111587
+ new_id_int := new_id_int / alphabet_length;
111588
+ END LOOP;
111589
+
111590
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111591
+ END LOOP;
111592
+ RETURN new_id_str;
111593
+ END;
111594
+ $function$
111595
+ 
111596
+  (45.1ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111597
+  (50.4ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111598
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111599
+  (1.5ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111600
+  (3.6ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111601
+  (4.5ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111602
+  (2.0ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111603
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111604
+  (7.3ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111605
+  (12.2ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111606
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111607
+  (1.8ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111608
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111609
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111610
+  (8.9ms) CREATE TABLE "plain_old_ar" ("id" bigserial primary key, "title" character varying, "description" text)
111611
+  (6.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111612
+ FOREIGN KEY ("asset_id")
111613
+ REFERENCES "kithe_models" ("id")
111614
+ 
111615
+  (3.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111616
+ FOREIGN KEY ("containee_id")
111617
+ REFERENCES "kithe_models" ("id")
111618
+ 
111619
+  (2.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111620
+ FOREIGN KEY ("container_id")
111621
+ REFERENCES "kithe_models" ("id")
111622
+ 
111623
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111624
+ FOREIGN KEY ("leaf_representative_id")
111625
+ REFERENCES "kithe_models" ("id")
111626
+ 
111627
+  (3.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111628
+ FOREIGN KEY ("parent_id")
111629
+ REFERENCES "kithe_models" ("id")
111630
+ 
111631
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111632
+ FOREIGN KEY ("representative_id")
111633
+ REFERENCES "kithe_models" ("id")
111634
+ 
111635
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111636
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111637
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111638
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111639
+  (0.2ms) BEGIN
111640
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "03c1babae3d781ef770d42f3017561a4fadf7200"], ["updated_at", "2020-06-04 16:46:18.145376"], ["key", "schema_sha1"]]
111641
+  (0.4ms) COMMIT
111642
+ SQL (2.6ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111643
+ SQL (0.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111644
+  (28.9ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111645
+ RETURNS text
111646
+ LANGUAGE plpgsql
111647
+ AS $function$
111648
+ DECLARE
111649
+ new_id_int bigint;
111650
+ new_id_str character varying := '';
111651
+ done bool;
111652
+ tries integer;
111653
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111654
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111655
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111656
+ alphabet_length integer := array_length(alphabet, 1);
111657
+
111658
+ BEGIN
111659
+ done := false;
111660
+ tries := 0;
111661
+ WHILE (NOT done) LOOP
111662
+ tries := tries + 1;
111663
+ IF (tries > 3) THEN
111664
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111665
+ END IF;
111666
+
111667
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111668
+
111669
+ -- convert bigint to a Base-36 alphanumeric string
111670
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111671
+ -- https://gist.github.com/btbytes/7159902
111672
+ WHILE new_id_int != 0 LOOP
111673
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111674
+ new_id_int := new_id_int / alphabet_length;
111675
+ END LOOP;
111676
+
111677
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111678
+ END LOOP;
111679
+ RETURN new_id_str;
111680
+ END;
111681
+ $function$
111682
+ 
111683
+  (29.1ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111684
+  (24.3ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111685
+  (2.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111686
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111687
+  (2.7ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111688
+  (1.3ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111689
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111690
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111691
+  (6.6ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111692
+  (5.2ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111693
+  (1.5ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111694
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111695
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111696
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111697
+  (4.5ms) CREATE TABLE "plain_old_ar" ("id" bigserial primary key, "title" character varying, "description" text)
111698
+  (6.6ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111699
+ FOREIGN KEY ("asset_id")
111700
+ REFERENCES "kithe_models" ("id")
111701
+ 
111702
+  (2.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111703
+ FOREIGN KEY ("containee_id")
111704
+ REFERENCES "kithe_models" ("id")
111705
+ 
111706
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111707
+ FOREIGN KEY ("container_id")
111708
+ REFERENCES "kithe_models" ("id")
111709
+ 
111710
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111711
+ FOREIGN KEY ("leaf_representative_id")
111712
+ REFERENCES "kithe_models" ("id")
111713
+ 
111714
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111715
+ FOREIGN KEY ("parent_id")
111716
+ REFERENCES "kithe_models" ("id")
111717
+ 
111718
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111719
+ FOREIGN KEY ("representative_id")
111720
+ REFERENCES "kithe_models" ("id")
111721
+ 
111722
+  (1.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111723
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111724
+  (0.2ms) BEGIN
111725
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "development"], ["updated_at", "2020-06-04 16:46:18.411648"], ["key", "environment"]]
111726
+  (0.5ms) COMMIT
111727
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111728
+  (0.2ms) BEGIN
111729
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-06-04 16:46:18.418618"], ["key", "environment"]]
111730
+  (0.4ms) COMMIT
111731
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111732
+  (0.2ms) BEGIN
111733
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "03c1babae3d781ef770d42f3017561a4fadf7200"], ["updated_at", "2020-06-04 16:46:18.423797"], ["key", "schema_sha1"]]
111734
+  (0.5ms) COMMIT
111735
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111736
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111737
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111738
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111739
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111740
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111741
+  (340.9ms) DROP DATABASE IF EXISTS "kithe_development"
111742
+  (224.9ms) DROP DATABASE IF EXISTS "kithe_test"
111743
+  (701.4ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
111744
+  (483.4ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
111745
+ SQL (182.5ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111746
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111747
+  (2.2ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111748
+ RETURNS text
111749
+ LANGUAGE plpgsql
111750
+ AS $function$
111751
+ DECLARE
111752
+ new_id_int bigint;
111753
+ new_id_str character varying := '';
111754
+ done bool;
111755
+ tries integer;
111756
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111757
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111758
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111759
+ alphabet_length integer := array_length(alphabet, 1);
111760
+
111761
+ BEGIN
111762
+ done := false;
111763
+ tries := 0;
111764
+ WHILE (NOT done) LOOP
111765
+ tries := tries + 1;
111766
+ IF (tries > 3) THEN
111767
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111768
+ END IF;
111769
+
111770
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111771
+
111772
+ -- convert bigint to a Base-36 alphanumeric string
111773
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111774
+ -- https://gist.github.com/btbytes/7159902
111775
+ WHILE new_id_int != 0 LOOP
111776
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111777
+ new_id_int := new_id_int / alphabet_length;
111778
+ END LOOP;
111779
+
111780
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111781
+ END LOOP;
111782
+ RETURN new_id_str;
111783
+ END;
111784
+ $function$
111785
+ 
111786
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111787
+  (10.4ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111788
+  (2.6ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111789
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111790
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111791
+  (1.7ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111792
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111793
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111794
+  (0.3ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111795
+  (4.2ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111796
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111797
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111798
+  (1.5ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111799
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111800
+  (8.7ms) CREATE TABLE "plain_old_ars" ("id" bigserial primary key, "title" character varying, "description" text)
111801
+  (3.4ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111802
+ FOREIGN KEY ("asset_id")
111803
+ REFERENCES "kithe_models" ("id")
111804
+ 
111805
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111806
+ FOREIGN KEY ("containee_id")
111807
+ REFERENCES "kithe_models" ("id")
111808
+ 
111809
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111810
+ FOREIGN KEY ("container_id")
111811
+ REFERENCES "kithe_models" ("id")
111812
+ 
111813
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111814
+ FOREIGN KEY ("leaf_representative_id")
111815
+ REFERENCES "kithe_models" ("id")
111816
+ 
111817
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111818
+ FOREIGN KEY ("parent_id")
111819
+ REFERENCES "kithe_models" ("id")
111820
+ 
111821
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111822
+ FOREIGN KEY ("representative_id")
111823
+ REFERENCES "kithe_models" ("id")
111824
+ 
111825
+  (3.8ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111826
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111827
+  (5.9ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111828
+  (21.1ms) INSERT INTO "schema_migrations" (version) VALUES
111829
+ (20181015143259),
111830
+ (20181015143413),
111831
+ (20181015143737),
111832
+ (20181031190647),
111833
+ (20181128185658),
111834
+ (20190103144947),
111835
+ (20190109192252);
111836
+
111837
+ 
111838
+  (3.3ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111839
+ ActiveRecord::InternalMetadata Load (1.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111840
+  (0.7ms) BEGIN
111841
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:47:04.539998"], ["updated_at", "2020-06-04 16:47:04.539998"]]
111842
+  (0.5ms) COMMIT
111843
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111844
+ ActiveRecord::InternalMetadata Load (1.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111845
+  (0.2ms) BEGIN
111846
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "6d88defc9e286449197e3c57b6342e1510b872dd"], ["created_at", "2020-06-04 16:47:04.552438"], ["updated_at", "2020-06-04 16:47:04.552438"]]
111847
+  (0.4ms) COMMIT
111848
+ SQL (15.3ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111849
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111850
+  (2.5ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111851
+ RETURNS text
111852
+ LANGUAGE plpgsql
111853
+ AS $function$
111854
+ DECLARE
111855
+ new_id_int bigint;
111856
+ new_id_str character varying := '';
111857
+ done bool;
111858
+ tries integer;
111859
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111860
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111861
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111862
+ alphabet_length integer := array_length(alphabet, 1);
111863
+
111864
+ BEGIN
111865
+ done := false;
111866
+ tries := 0;
111867
+ WHILE (NOT done) LOOP
111868
+ tries := tries + 1;
111869
+ IF (tries > 3) THEN
111870
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111871
+ END IF;
111872
+
111873
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111874
+
111875
+ -- convert bigint to a Base-36 alphanumeric string
111876
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111877
+ -- https://gist.github.com/btbytes/7159902
111878
+ WHILE new_id_int != 0 LOOP
111879
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111880
+ new_id_int := new_id_int / alphabet_length;
111881
+ END LOOP;
111882
+
111883
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111884
+ END LOOP;
111885
+ RETURN new_id_str;
111886
+ END;
111887
+ $function$
111888
+ 
111889
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111890
+  (11.5ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111891
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111892
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111893
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111894
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111895
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111896
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111897
+  (0.4ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111898
+  (3.8ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111899
+  (1.7ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111900
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111901
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111902
+  (1.1ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111903
+  (4.5ms) CREATE TABLE "plain_old_ars" ("id" bigserial primary key, "title" character varying, "description" text)
111904
+  (6.5ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111905
+ FOREIGN KEY ("asset_id")
111906
+ REFERENCES "kithe_models" ("id")
111907
+ 
111908
+  (2.1ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111909
+ FOREIGN KEY ("containee_id")
111910
+ REFERENCES "kithe_models" ("id")
111911
+ 
111912
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111913
+ FOREIGN KEY ("container_id")
111914
+ REFERENCES "kithe_models" ("id")
111915
+ 
111916
+  (3.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111917
+ FOREIGN KEY ("leaf_representative_id")
111918
+ REFERENCES "kithe_models" ("id")
111919
+ 
111920
+  (19.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111921
+ FOREIGN KEY ("parent_id")
111922
+ REFERENCES "kithe_models" ("id")
111923
+ 
111924
+  (7.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111925
+ FOREIGN KEY ("representative_id")
111926
+ REFERENCES "kithe_models" ("id")
111927
+ 
111928
+  (7.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111929
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111930
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111931
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES
111932
+ (20181015143259),
111933
+ (20181015143413),
111934
+ (20181015143737),
111935
+ (20181031190647),
111936
+ (20181128185658),
111937
+ (20190103144947),
111938
+ (20190109192252);
111939
+
111940
+ 
111941
+  (4.1ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111942
+ ActiveRecord::InternalMetadata Load (1.0ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111943
+  (0.2ms) BEGIN
111944
+ ActiveRecord::InternalMetadata Create (0.8ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:47:04.783078"], ["updated_at", "2020-06-04 16:47:04.783078"]]
111945
+  (0.4ms) COMMIT
111946
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111947
+  (0.1ms) BEGIN
111948
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-06-04 16:47:04.789820"], ["key", "environment"]]
111949
+  (0.4ms) COMMIT
111950
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111951
+  (0.1ms) BEGIN
111952
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "6d88defc9e286449197e3c57b6342e1510b872dd"], ["created_at", "2020-06-04 16:47:04.795239"], ["updated_at", "2020-06-04 16:47:04.795239"]]
111953
+  (0.4ms) COMMIT
111954
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111955
+ PlainOldAr Load (0.4ms) SELECT "plain_old_ars".* FROM "plain_old_ars" ORDER BY "plain_old_ars"."id" ASC LIMIT $1 [["LIMIT", 1]]
111956
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111957
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111958
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111959
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111960
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111961
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111962
+  (227.8ms) DROP DATABASE IF EXISTS "kithe_development"
111963
+  (217.1ms) DROP DATABASE IF EXISTS "kithe_test"
111964
+  (496.1ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
111965
+  (495.5ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
111966
+ SQL (25.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111967
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111968
+  (23.8ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111969
+ RETURNS text
111970
+ LANGUAGE plpgsql
111971
+ AS $function$
111972
+ DECLARE
111973
+ new_id_int bigint;
111974
+ new_id_str character varying := '';
111975
+ done bool;
111976
+ tries integer;
111977
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111978
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111979
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111980
+ alphabet_length integer := array_length(alphabet, 1);
111981
+
111982
+ BEGIN
111983
+ done := false;
111984
+ tries := 0;
111985
+ WHILE (NOT done) LOOP
111986
+ tries := tries + 1;
111987
+ IF (tries > 3) THEN
111988
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111989
+ END IF;
111990
+
111991
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111992
+
111993
+ -- convert bigint to a Base-36 alphanumeric string
111994
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111995
+ -- https://gist.github.com/btbytes/7159902
111996
+ WHILE new_id_int != 0 LOOP
111997
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111998
+ new_id_int := new_id_int / alphabet_length;
111999
+ END LOOP;
112000
+
112001
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
112002
+ END LOOP;
112003
+ RETURN new_id_str;
112004
+ END;
112005
+ $function$
112006
+ 
112007
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
112008
+  (20.8ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
112009
+  (2.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
112010
+  (1.1ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
112011
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
112012
+  (1.1ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
112013
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
112014
+  (1.1ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
112015
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
112016
+  (4.2ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
112017
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
112018
+  (1.8ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
112019
+  (6.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
112020
+  (1.8ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
112021
+  (3.6ms) CREATE TABLE "plain_active_records" ("id" bigserial primary key, "title" character varying, "description" text)
112022
+  (3.2ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
112023
+ FOREIGN KEY ("asset_id")
112024
+ REFERENCES "kithe_models" ("id")
112025
+ 
112026
+  (136.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
112027
+ FOREIGN KEY ("containee_id")
112028
+ REFERENCES "kithe_models" ("id")
112029
+ 
112030
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
112031
+ FOREIGN KEY ("container_id")
112032
+ REFERENCES "kithe_models" ("id")
112033
+ 
112034
+  (3.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
112035
+ FOREIGN KEY ("leaf_representative_id")
112036
+ REFERENCES "kithe_models" ("id")
112037
+ 
112038
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
112039
+ FOREIGN KEY ("parent_id")
112040
+ REFERENCES "kithe_models" ("id")
112041
+ 
112042
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
112043
+ FOREIGN KEY ("representative_id")
112044
+ REFERENCES "kithe_models" ("id")
112045
+ 
112046
+  (2.9ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
112047
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112048
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
112049
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES
112050
+ (20181015143259),
112051
+ (20181015143413),
112052
+ (20181015143737),
112053
+ (20181031190647),
112054
+ (20181128185658),
112055
+ (20190103144947),
112056
+ (20190109192252);
112057
+
112058
+ 
112059
+  (3.3ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
112060
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
112061
+  (0.2ms) BEGIN
112062
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:49:37.613161"], ["updated_at", "2020-06-04 16:49:37.613161"]]
112063
+  (0.4ms) COMMIT
112064
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
112065
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
112066
+  (0.1ms) BEGIN
112067
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "7ac4a20ed84fd4d14ae476bfa58fc376b3ce6739"], ["created_at", "2020-06-04 16:49:37.623813"], ["updated_at", "2020-06-04 16:49:37.623813"]]
112068
+  (0.3ms) COMMIT
112069
+ SQL (15.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
112070
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
112071
+  (2.2ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
112072
+ RETURNS text
112073
+ LANGUAGE plpgsql
112074
+ AS $function$
112075
+ DECLARE
112076
+ new_id_int bigint;
112077
+ new_id_str character varying := '';
112078
+ done bool;
112079
+ tries integer;
112080
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
112081
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
112082
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
112083
+ alphabet_length integer := array_length(alphabet, 1);
112084
+
112085
+ BEGIN
112086
+ done := false;
112087
+ tries := 0;
112088
+ WHILE (NOT done) LOOP
112089
+ tries := tries + 1;
112090
+ IF (tries > 3) THEN
112091
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
112092
+ END IF;
112093
+
112094
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
112095
+
112096
+ -- convert bigint to a Base-36 alphanumeric string
112097
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
112098
+ -- https://gist.github.com/btbytes/7159902
112099
+ WHILE new_id_int != 0 LOOP
112100
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
112101
+ new_id_int := new_id_int / alphabet_length;
112102
+ END LOOP;
112103
+
112104
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
112105
+ END LOOP;
112106
+ RETURN new_id_str;
112107
+ END;
112108
+ $function$
112109
+ 
112110
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
112111
+  (31.4ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
112112
+  (4.3ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
112113
+  (1.1ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
112114
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
112115
+  (2.4ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
112116
+  (1.8ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
112117
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
112118
+  (3.8ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
112119
+  (4.8ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
112120
+  (1.1ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
112121
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
112122
+  (3.1ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
112123
+  (1.4ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
112124
+  (10.2ms) CREATE TABLE "plain_active_records" ("id" bigserial primary key, "title" character varying, "description" text)
112125
+  (4.9ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
112126
+ FOREIGN KEY ("asset_id")
112127
+ REFERENCES "kithe_models" ("id")
112128
+ 
112129
+  (3.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
112130
+ FOREIGN KEY ("containee_id")
112131
+ REFERENCES "kithe_models" ("id")
112132
+ 
112133
+  (5.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
112134
+ FOREIGN KEY ("container_id")
112135
+ REFERENCES "kithe_models" ("id")
112136
+ 
112137
+  (14.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
112138
+ FOREIGN KEY ("leaf_representative_id")
112139
+ REFERENCES "kithe_models" ("id")
112140
+ 
112141
+  (6.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
112142
+ FOREIGN KEY ("parent_id")
112143
+ REFERENCES "kithe_models" ("id")
112144
+ 
112145
+  (8.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
112146
+ FOREIGN KEY ("representative_id")
112147
+ REFERENCES "kithe_models" ("id")
112148
+ 
112149
+  (14.5ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
112150
+  (0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112151
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
112152
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
112153
+ (20181015143259),
112154
+ (20181015143413),
112155
+ (20181015143737),
112156
+ (20181031190647),
112157
+ (20181128185658),
112158
+ (20190103144947),
112159
+ (20190109192252);
112160
+
112161
+ 
112162
+  (3.8ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
112163
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
112164
+  (0.2ms) BEGIN
112165
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:49:37.900916"], ["updated_at", "2020-06-04 16:49:37.900916"]]
112166
+  (0.6ms) COMMIT
112167
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
112168
+  (0.2ms) BEGIN
112169
+ ActiveRecord::InternalMetadata Update (0.6ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-06-04 16:49:37.909774"], ["key", "environment"]]
112170
+  (0.7ms) COMMIT
112171
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
112172
+  (0.2ms) BEGIN
112173
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "7ac4a20ed84fd4d14ae476bfa58fc376b3ce6739"], ["created_at", "2020-06-04 16:49:37.920363"], ["updated_at", "2020-06-04 16:49:37.920363"]]
112174
+  (0.4ms) COMMIT
112175
+  (1.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112176
+  (3.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112177
+  (22.8ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
112178
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112179
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
112180
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112181
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
112182
+  (364.2ms) DROP DATABASE IF EXISTS "kithe_test"
112183
+  (864.3ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
112184
+ SQL (64.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
112185
+ SQL (1.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
112186
+  (10.4ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
112187
+ RETURNS text
112188
+ LANGUAGE plpgsql
112189
+ AS $function$
112190
+ DECLARE
112191
+ new_id_int bigint;
112192
+ new_id_str character varying := '';
112193
+ done bool;
112194
+ tries integer;
112195
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
112196
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
112197
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
112198
+ alphabet_length integer := array_length(alphabet, 1);
112199
+
112200
+ BEGIN
112201
+ done := false;
112202
+ tries := 0;
112203
+ WHILE (NOT done) LOOP
112204
+ tries := tries + 1;
112205
+ IF (tries > 3) THEN
112206
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
112207
+ END IF;
112208
+
112209
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
112210
+
112211
+ -- convert bigint to a Base-36 alphanumeric string
112212
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
112213
+ -- https://gist.github.com/btbytes/7159902
112214
+ WHILE new_id_int != 0 LOOP
112215
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
112216
+ new_id_int := new_id_int / alphabet_length;
112217
+ END LOOP;
112218
+
112219
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
112220
+ END LOOP;
112221
+ RETURN new_id_str;
112222
+ END;
112223
+ $function$
112224
+ 
112225
+  (0.5ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
112226
+  (34.0ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
112227
+  (2.0ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
112228
+  (2.0ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
112229
+  (0.5ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
112230
+  (2.1ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
112231
+  (5.0ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
112232
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
112233
+  (0.3ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
112234
+  (29.4ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
112235
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
112236
+  (3.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
112237
+  (1.4ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
112238
+  (6.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
112239
+  (4.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
112240
+ FOREIGN KEY ("asset_id")
112241
+ REFERENCES "kithe_models" ("id")
112242
+ 
112243
+  (3.4ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
112244
+ FOREIGN KEY ("containee_id")
112245
+ REFERENCES "kithe_models" ("id")
112246
+ 
112247
+  (3.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
112248
+ FOREIGN KEY ("container_id")
112249
+ REFERENCES "kithe_models" ("id")
112250
+ 
112251
+  (4.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
112252
+ FOREIGN KEY ("leaf_representative_id")
112253
+ REFERENCES "kithe_models" ("id")
112254
+ 
112255
+  (3.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
112256
+ FOREIGN KEY ("parent_id")
112257
+ REFERENCES "kithe_models" ("id")
112258
+ 
112259
+  (3.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
112260
+ FOREIGN KEY ("representative_id")
112261
+ REFERENCES "kithe_models" ("id")
112262
+ 
112263
+  (5.8ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
112264
+  (1.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
112265
+  (8.9ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
112266
+  (11.8ms) INSERT INTO "schema_migrations" (version) VALUES
112267
+ (20181015143259),
112268
+ (20181015143413),
112269
+ (20181015143737),
112270
+ (20181031190647),
112271
+ (20181128185658),
112272
+ (20190103144947),
112273
+ (20190109192252);
112274
+
112275
+ 
112276
+  (5.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
112277
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
112278
+  (0.4ms) BEGIN
112279
+ ActiveRecord::InternalMetadata Create (0.9ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-11-11 21:42:07.161354"], ["updated_at", "2020-11-11 21:42:07.161354"]]
112280
+  (0.4ms) COMMIT
112281
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
112282
+  (0.4ms) BEGIN
112283
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-11-11 21:42:07.170009"], ["key", "environment"]]
112284
+  (0.5ms) COMMIT
112285
+ ActiveRecord::InternalMetadata Load (1.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
112286
+  (0.2ms) BEGIN
112287
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-11-11 21:42:07.182090"], ["updated_at", "2020-11-11 21:42:07.182090"]]
112288
+  (0.4ms) COMMIT