kithe 2.0.0.pre.alpha2 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/app/indexing/kithe/indexable/record_index_updater.rb +1 -1
- data/app/jobs/kithe/create_derivatives_job.rb +2 -2
- data/app/models/kithe/asset.rb +82 -154
- data/app/models/kithe/asset/derivative_creator.rb +32 -62
- data/app/models/kithe/asset/derivative_definition.rb +12 -13
- data/app/models/kithe/asset/set_shrine_uploader.rb +64 -0
- data/app/models/kithe/collection.rb +0 -6
- data/app/models/kithe/model.rb +0 -21
- data/app/models/kithe/work.rb +0 -5
- data/app/uploaders/kithe/asset_uploader.rb +15 -78
- data/lib/kithe.rb +22 -20
- data/{app/models → lib}/kithe/config_base.rb +6 -1
- data/lib/kithe/engine.rb +14 -3
- data/lib/kithe/indexable_settings.rb +1 -1
- data/lib/kithe/patch_fx.rb +39 -0
- data/lib/kithe/version.rb +4 -1
- data/lib/shrine/plugins/kithe_checksum_signatures.rb +41 -0
- data/lib/shrine/plugins/kithe_controllable_backgrounding.rb +53 -0
- data/lib/shrine/plugins/kithe_derivative_definitions.rb +101 -0
- data/lib/shrine/plugins/kithe_derivatives.rb +54 -0
- data/lib/shrine/plugins/kithe_determine_mime_type.rb +39 -0
- data/lib/shrine/plugins/kithe_persisted_derivatives.rb +161 -0
- data/lib/shrine/plugins/kithe_promotion_callbacks.rb +4 -0
- data/lib/shrine/plugins/kithe_promotion_directives.rb +33 -3
- data/lib/shrine/plugins/kithe_storage_location.rb +53 -4
- data/lib/tasks/kithe_tasks.rake +22 -15
- data/spec/dummy/app/models/plain_active_record.rb +3 -0
- data/spec/dummy/config/database.yml +6 -0
- data/spec/dummy/db/schema.rb +102 -0
- data/spec/dummy/log/development.log +3616 -0
- data/spec/dummy/log/test.log +86464 -0
- data/spec/dummy/tmp/development_secret.txt +1 -1
- data/spec/indexing/indexable_spec.rb +1 -1
- data/spec/models/kithe/asset/asset_derivatives_spec.rb +137 -0
- data/spec/models/kithe/asset/asset_promotion_hooks_spec.rb +26 -5
- data/spec/models/kithe/asset/set_shrine_uploader_spec.rb +39 -0
- data/spec/models/kithe/asset_spec.rb +9 -59
- data/spec/models/kithe/model_spec.rb +0 -32
- data/spec/models/kithe_spec.rb +10 -0
- data/spec/shrine/kithe_accept_remote_url_spec.rb +49 -0
- data/spec/shrine/kithe_checksum_signatures_spec.rb +63 -0
- data/spec/shrine/kithe_derivative_definitions_spec.rb +303 -0
- data/spec/shrine/kithe_persisted_derivatives_spec.rb +424 -0
- data/spec/shrine/kithe_storage_location_spec.rb +43 -15
- data/spec/spec_helper.rb +0 -19
- data/spec/test_support/images/3x3_pixel.jpg +0 -0
- data/spec/test_support/shrine_spec_support.rb +2 -1
- metadata +60 -36
- data/app/models/kithe/asset/derivative_updater.rb +0 -119
- data/app/models/kithe/derivative.rb +0 -15
- data/app/uploaders/kithe/derivative_uploader.rb +0 -48
- data/spec/dummy/db/structure.sql +0 -309
- data/spec/models/kithe/asset/asset_create_derivatives_spec.rb +0 -320
- 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
|
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
|
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
|
6
|
-
#
|
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 =
|
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)
|
data/lib/tasks/kithe_tasks.rake
CHANGED
@@ -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
|
12
|
-
opts.on("--lazy","Lazy create") { options[:lazy] = true }
|
13
|
-
opts.on("--asset-id
|
14
|
-
opts.on("--work-id
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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.
|
47
|
-
|
48
|
-
|
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
|
@@ -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
|
[1m[36mKithe::Asset Update (3.3ms)[0m [1m[33mUPDATE "kithe_models" SET "updated_at" = $1, "file_data" = $2 WHERE "kithe_models"."id" = $3[0m [["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
|
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
108672
108672
|
[1m[36mKithe::Asset Load (0.5ms)[0m [1m[34mSELECT "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[0m [["type", "Kithe::Asset"], ["id", "e7e4d65b-b65f-43f4-a31a-9e6721a2116e"], ["LIMIT", 1]]
|
108673
|
+
[1m[35m (2.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108674
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108675
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108676
|
+
[1m[35m (23.7ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108677
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108678
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108679
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108680
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108681
|
+
[1m[35m (233.0ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
108682
|
+
[1m[35m (316.2ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
108683
|
+
[1m[35m (480.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
108684
|
+
[1m[35m (446.4ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
108685
|
+
[1m[35m (6.9ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
108686
|
+
[1m[35m (22.7ms)[0m [1m[35mCREATE 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)[0m
|
108687
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
108688
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108689
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
108690
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
108691
|
+
[1m[35mSQL (33.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
108692
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
108693
|
+
[1m[35m (6.5ms)[0m [1m[35mCOMMIT[0m
|
108694
|
+
Migrating to CreateKitheModels (20181015143413)
|
108695
|
+
[1m[35m (0.7ms)[0m [1m[35mBEGIN[0m
|
108696
|
+
[1m[35m (28.7ms)[0m [1m[35mCREATE 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)[0m
|
108697
|
+
[1m[35m (1.2ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
108698
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
108699
|
+
[1m[35m (2.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
108700
|
+
FOREIGN KEY ("parent_id")
|
108701
|
+
REFERENCES "kithe_models" ("id")
|
108702
|
+
[0m
|
108703
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
108704
|
+
[1m[35m (0.8ms)[0m [1m[35mCOMMIT[0m
|
108705
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
108706
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108707
|
+
[1m[35m (21.5ms)[0m [1m[35mCREATE 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
|
+
[0m
|
108743
|
+
[1m[35m (28.2ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
108744
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
108745
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
108746
|
+
[1m[35m (1.2ms)[0m [1m[35mCOMMIT[0m
|
108747
|
+
Migrating to AddFileDataToModel (20181031190647)
|
108748
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108749
|
+
[1m[35m (1.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
108750
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
108751
|
+
[1m[35m (13.7ms)[0m [1m[35mCOMMIT[0m
|
108752
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
108753
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108754
|
+
[1m[35m (17.8ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
108758
|
+
[1m[35m (6.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
108759
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
108760
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
108761
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
108762
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
108763
|
+
[1m[35m (12.1ms)[0m [1m[35mBEGIN[0m
|
108764
|
+
[1m[35m (0.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
108765
|
+
[1m[35m (6.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
108766
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
108767
|
+
FOREIGN KEY ("representative_id")
|
108768
|
+
REFERENCES "kithe_models" ("id")
|
108769
|
+
[0m
|
108770
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
108771
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
108772
|
+
[1m[35m (1.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
108773
|
+
FOREIGN KEY ("leaf_representative_id")
|
108774
|
+
REFERENCES "kithe_models" ("id")
|
108775
|
+
[0m
|
108776
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
108777
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
108778
|
+
Migrating to ContainsAssociation (20190109192252)
|
108779
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108780
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
108787
|
+
[1m[35m (7.4ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
108788
|
+
[1m[35m (5.9ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
108789
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
108790
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
108791
|
+
Migrating to KitheModelType (20190404144551)
|
108792
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108793
|
+
[1m[35m (0.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
108794
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
108795
|
+
[1m[35m (13.1ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
108796
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
108797
|
+
[1m[35m (5.9ms)[0m [1m[35mCOMMIT[0m
|
108798
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
108799
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
108800
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.7ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 19:49:53.472252"], ["updated_at", "2020-05-20 19:49:53.472252"]]
|
108801
|
+
[1m[35m (6.1ms)[0m [1m[35mCOMMIT[0m
|
108802
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
108803
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108804
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108805
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108806
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108807
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108808
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108809
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108810
|
+
[1m[35m (206.8ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
108811
|
+
[1m[35m (203.9ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
108812
|
+
[1m[35m (539.9ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
108813
|
+
[1m[35m (419.2ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
108814
|
+
[1m[35m (5.1ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
108815
|
+
[1m[35m (4.4ms)[0m [1m[35mCREATE 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)[0m
|
108816
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
108817
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108818
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
108819
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
108820
|
+
[1m[35mSQL (18.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
108821
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
108822
|
+
[1m[35m (6.1ms)[0m [1m[35mCOMMIT[0m
|
108823
|
+
Migrating to CreateKitheModels (20181015143413)
|
108824
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108825
|
+
[1m[35m (18.8ms)[0m [1m[35mCREATE 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)[0m
|
108826
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
108827
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
108828
|
+
[1m[35m (3.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
108829
|
+
FOREIGN KEY ("parent_id")
|
108830
|
+
REFERENCES "kithe_models" ("id")
|
108831
|
+
[0m
|
108832
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
108833
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
108834
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
108835
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
108836
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE 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
|
+
[0m
|
108872
|
+
[1m[35m (24.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
108873
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
108874
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
108875
|
+
[1m[35m (1.2ms)[0m [1m[35mCOMMIT[0m
|
108876
|
+
Migrating to AddFileDataToModel (20181031190647)
|
108877
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
108878
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
108879
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
108880
|
+
[1m[35m (11.3ms)[0m [1m[35mCOMMIT[0m
|
108881
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
108882
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
108883
|
+
[1m[35m (27.7ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
108887
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
108888
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
108889
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
108890
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
108891
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
108892
|
+
[1m[35m (43.7ms)[0m [1m[35mBEGIN[0m
|
108893
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
108894
|
+
[1m[35m (2.8ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
108895
|
+
[1m[35m (2.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
108896
|
+
FOREIGN KEY ("representative_id")
|
108897
|
+
REFERENCES "kithe_models" ("id")
|
108898
|
+
[0m
|
108899
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
108900
|
+
[1m[35m (25.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
108901
|
+
[1m[35m (12.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
108902
|
+
FOREIGN KEY ("leaf_representative_id")
|
108903
|
+
REFERENCES "kithe_models" ("id")
|
108904
|
+
[0m
|
108905
|
+
[1m[36mprimary::SchemaMigration Create (5.1ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
108906
|
+
[1m[35m (2.0ms)[0m [1m[35mCOMMIT[0m
|
108907
|
+
Migrating to ContainsAssociation (20190109192252)
|
108908
|
+
[1m[35m (0.9ms)[0m [1m[35mBEGIN[0m
|
108909
|
+
[1m[35m (23.6ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
108916
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
108917
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
108918
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
108919
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
108920
|
+
Migrating to KitheModelType (20190404144551)
|
108921
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
108922
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
108923
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
108924
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
108925
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
108926
|
+
[1m[35m (6.4ms)[0m [1m[35mCOMMIT[0m
|
108927
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.8ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
108928
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
108929
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 19:50:47.121307"], ["updated_at", "2020-05-20 19:50:47.121307"]]
|
108930
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
108931
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
108932
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108933
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108934
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108935
|
+
[1m[35m (5.5ms)[0m [1m[34m 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
|
+
[0m
|
108946
|
+
[1m[35m (1.5ms)[0m [1m[34m 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
|
+
[0m
|
108958
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
108959
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108960
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
108961
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
108962
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108963
|
+
[1m[35m (4.1ms)[0m [1m[34m 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
|
+
[0m
|
108974
|
+
[1m[35m (1.3ms)[0m [1m[34m 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
|
+
[0m
|
108986
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108987
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108988
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108989
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108990
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
108991
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
108992
|
+
[1m[35m (285.0ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
108993
|
+
[1m[35m (211.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
108994
|
+
[1m[35m (491.7ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
108995
|
+
[1m[35m (411.0ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
108996
|
+
[1m[35mSQL (36.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
108997
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
108998
|
+
[1m[35m (10.5ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109037
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
109038
|
+
[1m[35m (20.0ms)[0m [1m[35mCREATE 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)[0m
|
109039
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109040
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109041
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
109042
|
+
[1m[35m (8.4ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
109043
|
+
[1m[35m (11.8ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109044
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109045
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
109046
|
+
[1m[35m (4.1ms)[0m [1m[35mCREATE 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)[0m
|
109047
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109048
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109049
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109050
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109051
|
+
[1m[35m (4.3ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
109052
|
+
FOREIGN KEY ("asset_id")
|
109053
|
+
REFERENCES "kithe_models" ("id")
|
109054
|
+
[0m
|
109055
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
109056
|
+
FOREIGN KEY ("containee_id")
|
109057
|
+
REFERENCES "kithe_models" ("id")
|
109058
|
+
[0m
|
109059
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
109060
|
+
FOREIGN KEY ("container_id")
|
109061
|
+
REFERENCES "kithe_models" ("id")
|
109062
|
+
[0m
|
109063
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109064
|
+
FOREIGN KEY ("leaf_representative_id")
|
109065
|
+
REFERENCES "kithe_models" ("id")
|
109066
|
+
[0m
|
109067
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109068
|
+
FOREIGN KEY ("parent_id")
|
109069
|
+
REFERENCES "kithe_models" ("id")
|
109070
|
+
[0m
|
109071
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109072
|
+
FOREIGN KEY ("representative_id")
|
109073
|
+
REFERENCES "kithe_models" ("id")
|
109074
|
+
[0m
|
109075
|
+
[1m[35m (3.4ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109076
|
+
[1m[35m (1.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109077
|
+
[1m[35m (0.9ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
109078
|
+
[1m[35m (0.8ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
109079
|
+
(20181015143259),
|
109080
|
+
(20181015143413),
|
109081
|
+
(20181015143737),
|
109082
|
+
(20181031190647),
|
109083
|
+
(20181128185658),
|
109084
|
+
(20190103144947),
|
109085
|
+
(20190109192252);
|
109086
|
+
|
109087
|
+
[0m
|
109088
|
+
[1m[35m (21.8ms)[0m [1m[35mCREATE 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)[0m
|
109089
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109090
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109091
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 20:49:47.747085"], ["updated_at", "2020-05-20 20:49:47.747085"]]
|
109092
|
+
[1m[35m (0.3ms)[0m [1m[35mCOMMIT[0m
|
109093
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109094
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
109095
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109096
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "658d6ce4e52abaa31072af6cc4edca545468d72b"], ["created_at", "2020-05-20 20:49:47.755335"], ["updated_at", "2020-05-20 20:49:47.755335"]]
|
109097
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
109098
|
+
[1m[35mSQL (11.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109099
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
109100
|
+
[1m[35m (2.1ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109139
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
109140
|
+
[1m[35m (6.0ms)[0m [1m[35mCREATE 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)[0m
|
109141
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109142
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109143
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
109144
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
109145
|
+
[1m[35m (2.5ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109146
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109147
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
109148
|
+
[1m[35m (5.5ms)[0m [1m[35mCREATE 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)[0m
|
109149
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109150
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109151
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109152
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109153
|
+
[1m[35m (2.9ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
109154
|
+
FOREIGN KEY ("asset_id")
|
109155
|
+
REFERENCES "kithe_models" ("id")
|
109156
|
+
[0m
|
109157
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
109158
|
+
FOREIGN KEY ("containee_id")
|
109159
|
+
REFERENCES "kithe_models" ("id")
|
109160
|
+
[0m
|
109161
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
109162
|
+
FOREIGN KEY ("container_id")
|
109163
|
+
REFERENCES "kithe_models" ("id")
|
109164
|
+
[0m
|
109165
|
+
[1m[35m (2.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109166
|
+
FOREIGN KEY ("leaf_representative_id")
|
109167
|
+
REFERENCES "kithe_models" ("id")
|
109168
|
+
[0m
|
109169
|
+
[1m[35m (2.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109170
|
+
FOREIGN KEY ("parent_id")
|
109171
|
+
REFERENCES "kithe_models" ("id")
|
109172
|
+
[0m
|
109173
|
+
[1m[35m (2.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109174
|
+
FOREIGN KEY ("representative_id")
|
109175
|
+
REFERENCES "kithe_models" ("id")
|
109176
|
+
[0m
|
109177
|
+
[1m[35m (3.7ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109178
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109179
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
109180
|
+
[1m[35m (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
109181
|
+
(20181015143259),
|
109182
|
+
(20181015143413),
|
109183
|
+
(20181015143737),
|
109184
|
+
(20181031190647),
|
109185
|
+
(20181128185658),
|
109186
|
+
(20190103144947),
|
109187
|
+
(20190109192252);
|
109188
|
+
|
109189
|
+
[0m
|
109190
|
+
[1m[35m (3.0ms)[0m [1m[35mCREATE 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)[0m
|
109191
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109192
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
109193
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 20:49:47.932037"], ["updated_at", "2020-05-20 20:49:47.932037"]]
|
109194
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
109195
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109196
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109197
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.7ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-20 20:49:47.940151"], ["key", "environment"]]
|
109198
|
+
[1m[35m (5.7ms)[0m [1m[35mCOMMIT[0m
|
109199
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
109200
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109201
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "658d6ce4e52abaa31072af6cc4edca545468d72b"], ["created_at", "2020-05-20 20:49:47.953802"], ["updated_at", "2020-05-20 20:49:47.953802"]]
|
109202
|
+
[1m[35m (6.4ms)[0m [1m[35mCOMMIT[0m
|
109203
|
+
[1m[35m (7.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109204
|
+
[1m[35m (30.7ms)[0m [1m[34m 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
|
+
[0m
|
109215
|
+
[1m[35m (1.8ms)[0m [1m[34m 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
|
+
[0m
|
109227
|
+
[1m[35m (1.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109228
|
+
[1m[35m (4.5ms)[0m [1m[34m 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
|
+
[0m
|
109239
|
+
[1m[35m (2.0ms)[0m [1m[34m 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
|
+
[0m
|
109251
|
+
[1m[35m (1.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109252
|
+
[1m[35m (4.2ms)[0m [1m[34m 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
|
+
[0m
|
109263
|
+
[1m[35m (1.4ms)[0m [1m[34m 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
|
+
[0m
|
109275
|
+
[1m[35m (1.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109276
|
+
[1m[35m (4.4ms)[0m [1m[34m 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
|
+
[0m
|
109287
|
+
[1m[35m (1.4ms)[0m [1m[34m 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
|
+
[0m
|
109299
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109300
|
+
[1m[35m (4.2ms)[0m [1m[34m 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
|
+
[0m
|
109311
|
+
[1m[35m (1.3ms)[0m [1m[34m 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
|
+
[0m
|
109323
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109324
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109325
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109326
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109327
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109328
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109329
|
+
[1m[35m (216.4ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
109330
|
+
[1m[35m (228.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
109331
|
+
[1m[35m (494.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
109332
|
+
[1m[35m (422.6ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
109333
|
+
[1m[35mSQL (63.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109334
|
+
[1m[35mSQL (50.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
109335
|
+
[1m[35m (34.8ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109374
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
109375
|
+
[1m[35m (12.8ms)[0m [1m[35mCREATE 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)[0m
|
109376
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109377
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109378
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
109379
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
109380
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109381
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109382
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
109383
|
+
[1m[35m (4.4ms)[0m [1m[35mCREATE 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)[0m
|
109384
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109385
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109386
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109387
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109388
|
+
[1m[35m (3.2ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
109389
|
+
FOREIGN KEY ("asset_id")
|
109390
|
+
REFERENCES "kithe_models" ("id")
|
109391
|
+
[0m
|
109392
|
+
[1m[35m (2.3ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
109393
|
+
FOREIGN KEY ("containee_id")
|
109394
|
+
REFERENCES "kithe_models" ("id")
|
109395
|
+
[0m
|
109396
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
109397
|
+
FOREIGN KEY ("container_id")
|
109398
|
+
REFERENCES "kithe_models" ("id")
|
109399
|
+
[0m
|
109400
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109401
|
+
FOREIGN KEY ("leaf_representative_id")
|
109402
|
+
REFERENCES "kithe_models" ("id")
|
109403
|
+
[0m
|
109404
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109405
|
+
FOREIGN KEY ("parent_id")
|
109406
|
+
REFERENCES "kithe_models" ("id")
|
109407
|
+
[0m
|
109408
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109409
|
+
FOREIGN KEY ("representative_id")
|
109410
|
+
REFERENCES "kithe_models" ("id")
|
109411
|
+
[0m
|
109412
|
+
[1m[35m (7.6ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109413
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109414
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
109415
|
+
[1m[35m (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
109416
|
+
(20181015143259),
|
109417
|
+
(20181015143413),
|
109418
|
+
(20181015143737),
|
109419
|
+
(20181031190647),
|
109420
|
+
(20181128185658),
|
109421
|
+
(20190103144947),
|
109422
|
+
(20190109192252);
|
109423
|
+
|
109424
|
+
[0m
|
109425
|
+
[1m[35m (3.8ms)[0m [1m[35mCREATE 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)[0m
|
109426
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109427
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109428
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 21:22:55.681291"], ["updated_at", "2020-05-20 21:22:55.681291"]]
|
109429
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
109430
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109431
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
109432
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
109433
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-20 21:22:55.690278"], ["updated_at", "2020-05-20 21:22:55.690278"]]
|
109434
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
109435
|
+
[1m[35mSQL (10.7ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109436
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
109437
|
+
[1m[35m (2.1ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109476
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
109477
|
+
[1m[35m (6.5ms)[0m [1m[35mCREATE 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)[0m
|
109478
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109479
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109480
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
109481
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
109482
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109483
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109484
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
109485
|
+
[1m[35m (3.4ms)[0m [1m[35mCREATE 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)[0m
|
109486
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109487
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109488
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109489
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109490
|
+
[1m[35m (2.8ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
109491
|
+
FOREIGN KEY ("asset_id")
|
109492
|
+
REFERENCES "kithe_models" ("id")
|
109493
|
+
[0m
|
109494
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
109495
|
+
FOREIGN KEY ("containee_id")
|
109496
|
+
REFERENCES "kithe_models" ("id")
|
109497
|
+
[0m
|
109498
|
+
[1m[35m (1.5ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
109499
|
+
FOREIGN KEY ("container_id")
|
109500
|
+
REFERENCES "kithe_models" ("id")
|
109501
|
+
[0m
|
109502
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109503
|
+
FOREIGN KEY ("leaf_representative_id")
|
109504
|
+
REFERENCES "kithe_models" ("id")
|
109505
|
+
[0m
|
109506
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109507
|
+
FOREIGN KEY ("parent_id")
|
109508
|
+
REFERENCES "kithe_models" ("id")
|
109509
|
+
[0m
|
109510
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109511
|
+
FOREIGN KEY ("representative_id")
|
109512
|
+
REFERENCES "kithe_models" ("id")
|
109513
|
+
[0m
|
109514
|
+
[1m[35m (3.0ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109515
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109516
|
+
[1m[35m (1.1ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
109517
|
+
[1m[35m (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
109518
|
+
(20181015143259),
|
109519
|
+
(20181015143413),
|
109520
|
+
(20181015143737),
|
109521
|
+
(20181031190647),
|
109522
|
+
(20181128185658),
|
109523
|
+
(20190103144947),
|
109524
|
+
(20190109192252);
|
109525
|
+
|
109526
|
+
[0m
|
109527
|
+
[1m[35m (2.9ms)[0m [1m[35mCREATE 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)[0m
|
109528
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109529
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
109530
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-20 21:22:55.842211"], ["updated_at", "2020-05-20 21:22:55.842211"]]
|
109531
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
109532
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109533
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
109534
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.4ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-20 21:22:55.848684"], ["key", "environment"]]
|
109535
|
+
[1m[35m (0.3ms)[0m [1m[35mCOMMIT[0m
|
109536
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
109537
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
109538
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-20 21:22:55.854305"], ["updated_at", "2020-05-20 21:22:55.854305"]]
|
109539
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
109540
|
+
[1m[35m (4.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109541
|
+
[1m[35m (6.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109542
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109543
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109544
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109545
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109546
|
+
[1m[35m (415.7ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
109547
|
+
[1m[35m (199.9ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
109548
|
+
[1m[35m (849.8ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
109549
|
+
[1m[35m (615.6ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
109550
|
+
[1m[35m (27.8ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109551
|
+
[1m[35m (5.0ms)[0m [1m[35mCREATE 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)[0m
|
109552
|
+
[1m[35m (11.6ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
109553
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109554
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
109555
|
+
[1m[35m (0.6ms)[0m [1m[35mBEGIN[0m
|
109556
|
+
[1m[35mSQL (188.1ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109557
|
+
[1m[36mprimary::SchemaMigration Create (4.2ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
109558
|
+
[1m[35m (24.5ms)[0m [1m[35mCOMMIT[0m
|
109559
|
+
Migrating to CreateKitheModels (20181015143413)
|
109560
|
+
[1m[35m (0.8ms)[0m [1m[35mBEGIN[0m
|
109561
|
+
[1m[35m (24.7ms)[0m [1m[35mCREATE 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)[0m
|
109562
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
109563
|
+
[1m[35m (8.0ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109564
|
+
[1m[35m (17.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109565
|
+
FOREIGN KEY ("parent_id")
|
109566
|
+
REFERENCES "kithe_models" ("id")
|
109567
|
+
[0m
|
109568
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
109569
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
109570
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
109571
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109572
|
+
[1m[35m (42.9ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109608
|
+
[1m[35m (43.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
109609
|
+
[1m[35m (14.4ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109610
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
109611
|
+
[1m[35m (30.0ms)[0m [1m[35mCOMMIT[0m
|
109612
|
+
Migrating to AddFileDataToModel (20181031190647)
|
109613
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109614
|
+
[1m[35m (0.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
109615
|
+
[1m[36mprimary::SchemaMigration Create (1.0ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
109616
|
+
[1m[35m (12.2ms)[0m [1m[35mCOMMIT[0m
|
109617
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
109618
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109619
|
+
[1m[35m (91.1ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
109623
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109624
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109625
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
109626
|
+
[1m[35m (2.1ms)[0m [1m[35mCOMMIT[0m
|
109627
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
109628
|
+
[1m[35m (12.0ms)[0m [1m[35mBEGIN[0m
|
109629
|
+
[1m[35m (1.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
109630
|
+
[1m[35m (7.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109631
|
+
[1m[35m (96.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109632
|
+
FOREIGN KEY ("representative_id")
|
109633
|
+
REFERENCES "kithe_models" ("id")
|
109634
|
+
[0m
|
109635
|
+
[1m[35m (0.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
109636
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109637
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109638
|
+
FOREIGN KEY ("leaf_representative_id")
|
109639
|
+
REFERENCES "kithe_models" ("id")
|
109640
|
+
[0m
|
109641
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
109642
|
+
[1m[35m (6.3ms)[0m [1m[35mCOMMIT[0m
|
109643
|
+
Migrating to ContainsAssociation (20190109192252)
|
109644
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109645
|
+
[1m[35m (7.3ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
109652
|
+
[1m[35m (13.6ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109653
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109654
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
109655
|
+
[1m[35m (6.4ms)[0m [1m[35mCOMMIT[0m
|
109656
|
+
Migrating to KitheModelType (20190404144551)
|
109657
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109658
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
109659
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
109660
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
109661
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
109662
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
109663
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109664
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109665
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.8ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 15:56:52.813959"], ["updated_at", "2020-05-27 15:56:52.813959"]]
|
109666
|
+
[1m[35m (6.0ms)[0m [1m[35mCOMMIT[0m
|
109667
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
109668
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109669
|
+
[1m[35m (4.7ms)[0m [1m[34m 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
|
+
[0m
|
109680
|
+
[1m[35m (1.5ms)[0m [1m[34m 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
|
+
[0m
|
109692
|
+
[1m[35m (1.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109693
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109694
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109695
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109696
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109697
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109698
|
+
[1m[35m (209.2ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
109699
|
+
[1m[35m (238.3ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
109700
|
+
[1m[35m (743.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
109701
|
+
[1m[35m (452.5ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
109702
|
+
[1m[35mSQL (22.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109703
|
+
[1m[35mSQL (0.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
109704
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
109705
|
+
[1m[35m (76.0ms)[0m [1m[35mCREATE 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)[0m
|
109706
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109707
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109708
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
109709
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
109710
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109711
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109712
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
109713
|
+
[1m[35m (3.5ms)[0m [1m[35mCREATE 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)[0m
|
109714
|
+
[1m[35m (222.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
109715
|
+
[1m[35m (216.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
109716
|
+
[1m[35m (1076.2ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
109717
|
+
[1m[35m (619.8ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
109718
|
+
[1m[35m (6.6ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109719
|
+
[1m[35m (27.0ms)[0m [1m[35mCREATE 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)[0m
|
109720
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
109721
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109722
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
109723
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
109724
|
+
[1m[35mSQL (28.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109725
|
+
[1m[36mprimary::SchemaMigration Create (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
109726
|
+
[1m[35m (5.5ms)[0m [1m[35mCOMMIT[0m
|
109727
|
+
Migrating to CreateKitheModels (20181015143413)
|
109728
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109729
|
+
[1m[35m (17.4ms)[0m [1m[35mCREATE 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)[0m
|
109730
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
109731
|
+
[1m[35m (7.0ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109732
|
+
[1m[35m (3.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109733
|
+
FOREIGN KEY ("parent_id")
|
109734
|
+
REFERENCES "kithe_models" ("id")
|
109735
|
+
[0m
|
109736
|
+
[1m[36mprimary::SchemaMigration Create (2.0ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
109737
|
+
[1m[35m (1.9ms)[0m [1m[35mCOMMIT[0m
|
109738
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
109739
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109740
|
+
[1m[35m (4.5ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109776
|
+
[1m[35m (41.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
109777
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109778
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
109779
|
+
[1m[35m (1.2ms)[0m [1m[35mCOMMIT[0m
|
109780
|
+
Migrating to AddFileDataToModel (20181031190647)
|
109781
|
+
[1m[35m (0.9ms)[0m [1m[35mBEGIN[0m
|
109782
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
109783
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
109784
|
+
[1m[35m (5.4ms)[0m [1m[35mCOMMIT[0m
|
109785
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
109786
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109787
|
+
[1m[35m (26.1ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
109791
|
+
[1m[35m (9.1ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109792
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109793
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
109794
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
109795
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
109796
|
+
[1m[35m (6.4ms)[0m [1m[35mBEGIN[0m
|
109797
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
109798
|
+
[1m[35m (7.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109799
|
+
[1m[35m (4.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109800
|
+
FOREIGN KEY ("representative_id")
|
109801
|
+
REFERENCES "kithe_models" ("id")
|
109802
|
+
[0m
|
109803
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
109804
|
+
[1m[35m (7.0ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109805
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109806
|
+
FOREIGN KEY ("leaf_representative_id")
|
109807
|
+
REFERENCES "kithe_models" ("id")
|
109808
|
+
[0m
|
109809
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
109810
|
+
[1m[35m (13.6ms)[0m [1m[35mCOMMIT[0m
|
109811
|
+
Migrating to ContainsAssociation (20190109192252)
|
109812
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
109813
|
+
[1m[35m (3.2ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
109820
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109821
|
+
[1m[35m (137.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109822
|
+
[1m[36mprimary::SchemaMigration Create (0.8ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
109823
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
109824
|
+
Migrating to KitheModelType (20190404144551)
|
109825
|
+
[1m[35m (0.7ms)[0m [1m[35mBEGIN[0m
|
109826
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
109827
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
109828
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
109829
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
109830
|
+
[1m[35m (15.6ms)[0m [1m[35mCOMMIT[0m
|
109831
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109832
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109833
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:23.911025"], ["updated_at", "2020-05-27 16:05:23.911025"]]
|
109834
|
+
[1m[35m (18.0ms)[0m [1m[35mCOMMIT[0m
|
109835
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
109836
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109837
|
+
[1m[35m (5.4ms)[0m [1m[34m 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
|
+
[0m
|
109848
|
+
[1m[35m (1.5ms)[0m [1m[34m 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
|
+
[0m
|
109860
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109861
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109862
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109863
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109864
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109865
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
109866
|
+
[1m[35m (281.6ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
109867
|
+
[1m[35m (206.0ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
109868
|
+
[1m[35m (430.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
109869
|
+
[1m[35m (507.9ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
109870
|
+
[1m[35mSQL (44.1ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109871
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
109872
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE 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
|
+
[0m
|
109911
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
109912
|
+
[1m[35m (8.6ms)[0m [1m[35mCREATE 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)[0m
|
109913
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
109914
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
109915
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
109916
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
109917
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
109918
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
109919
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
109920
|
+
[1m[35m (3.5ms)[0m [1m[35mCREATE 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)[0m
|
109921
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
109922
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
109923
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
109924
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
109925
|
+
[1m[35m (4.7ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
109926
|
+
FOREIGN KEY ("asset_id")
|
109927
|
+
REFERENCES "kithe_models" ("id")
|
109928
|
+
[0m
|
109929
|
+
[1m[35m (4.2ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
109930
|
+
FOREIGN KEY ("containee_id")
|
109931
|
+
REFERENCES "kithe_models" ("id")
|
109932
|
+
[0m
|
109933
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
109934
|
+
FOREIGN KEY ("container_id")
|
109935
|
+
REFERENCES "kithe_models" ("id")
|
109936
|
+
[0m
|
109937
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
109938
|
+
FOREIGN KEY ("leaf_representative_id")
|
109939
|
+
REFERENCES "kithe_models" ("id")
|
109940
|
+
[0m
|
109941
|
+
[1m[35m (2.2ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
109942
|
+
FOREIGN KEY ("parent_id")
|
109943
|
+
REFERENCES "kithe_models" ("id")
|
109944
|
+
[0m
|
109945
|
+
[1m[35m (2.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
109946
|
+
FOREIGN KEY ("representative_id")
|
109947
|
+
REFERENCES "kithe_models" ("id")
|
109948
|
+
[0m
|
109949
|
+
[1m[35m (3.1ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
109950
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
109951
|
+
[1m[35m (0.8ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
109952
|
+
[1m[35m (1.1ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
109953
|
+
(20181015143259),
|
109954
|
+
(20181015143413),
|
109955
|
+
(20181015143737),
|
109956
|
+
(20181031190647),
|
109957
|
+
(20181128185658),
|
109958
|
+
(20190103144947),
|
109959
|
+
(20190109192252);
|
109960
|
+
|
109961
|
+
[0m
|
109962
|
+
[1m[35m (3.0ms)[0m [1m[35mCREATE 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)[0m
|
109963
|
+
[1m[36mActiveRecord::InternalMetadata Load (2.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109964
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
109965
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:36.100092"], ["updated_at", "2020-05-27 16:05:36.100092"]]
|
109966
|
+
[1m[35m (6.3ms)[0m [1m[35mCOMMIT[0m
|
109967
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
109968
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
109969
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
109970
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:05:36.114811"], ["updated_at", "2020-05-27 16:05:36.114811"]]
|
109971
|
+
[1m[35m (5.0ms)[0m [1m[35mCOMMIT[0m
|
109972
|
+
[1m[35mSQL (43.0ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
109973
|
+
[1m[35mSQL (0.9ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
109974
|
+
[1m[35m (2.4ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110013
|
+
[1m[35m (1.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
110014
|
+
[1m[35m (27.4ms)[0m [1m[35mCREATE 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)[0m
|
110015
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110016
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110017
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
110018
|
+
[1m[35m (3.5ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
110019
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110020
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110021
|
+
[1m[35m (0.5ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
110022
|
+
[1m[35m (8.2ms)[0m [1m[35mCREATE 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)[0m
|
110023
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110024
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110025
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110026
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110027
|
+
[1m[35m (15.7ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
110028
|
+
FOREIGN KEY ("asset_id")
|
110029
|
+
REFERENCES "kithe_models" ("id")
|
110030
|
+
[0m
|
110031
|
+
[1m[35m (2.2ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
110032
|
+
FOREIGN KEY ("containee_id")
|
110033
|
+
REFERENCES "kithe_models" ("id")
|
110034
|
+
[0m
|
110035
|
+
[1m[35m (3.1ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
110036
|
+
FOREIGN KEY ("container_id")
|
110037
|
+
REFERENCES "kithe_models" ("id")
|
110038
|
+
[0m
|
110039
|
+
[1m[35m (3.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110040
|
+
FOREIGN KEY ("leaf_representative_id")
|
110041
|
+
REFERENCES "kithe_models" ("id")
|
110042
|
+
[0m
|
110043
|
+
[1m[35m (3.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110044
|
+
FOREIGN KEY ("parent_id")
|
110045
|
+
REFERENCES "kithe_models" ("id")
|
110046
|
+
[0m
|
110047
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110048
|
+
FOREIGN KEY ("representative_id")
|
110049
|
+
REFERENCES "kithe_models" ("id")
|
110050
|
+
[0m
|
110051
|
+
[1m[35m (3.2ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110052
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110053
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
110054
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
110055
|
+
(20181015143259),
|
110056
|
+
(20181015143413),
|
110057
|
+
(20181015143737),
|
110058
|
+
(20181031190647),
|
110059
|
+
(20181128185658),
|
110060
|
+
(20190103144947),
|
110061
|
+
(20190109192252);
|
110062
|
+
|
110063
|
+
[0m
|
110064
|
+
[1m[35m (3.5ms)[0m [1m[35mCREATE 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)[0m
|
110065
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110066
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110067
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:36.379857"], ["updated_at", "2020-05-27 16:05:36.379857"]]
|
110068
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110069
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.7ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110070
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110071
|
+
[1m[36mActiveRecord::InternalMetadata Update (1.3ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-27 16:05:36.388452"], ["key", "environment"]]
|
110072
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
110073
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.7ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
110074
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110075
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:05:36.399100"], ["updated_at", "2020-05-27 16:05:36.399100"]]
|
110076
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110077
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110078
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110079
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110080
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110081
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110082
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110083
|
+
[1m[35mSQL (0.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110084
|
+
[1m[35mSQL (0.8ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
110085
|
+
[1m[35m (3.0ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110124
|
+
[1m[35m (6.9ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
110125
|
+
[1m[35m (6.6ms)[0m [1m[35mCREATE 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)[0m
|
110126
|
+
[1m[35m (2.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110127
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110128
|
+
[1m[35m (2.9ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
110129
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
110130
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110131
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110132
|
+
[1m[35m (4.0ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
110133
|
+
[1m[35m (4.1ms)[0m [1m[35mCREATE 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)[0m
|
110134
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110135
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110136
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110137
|
+
[1m[35m (3.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110138
|
+
[1m[35m (15.9ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
110139
|
+
FOREIGN KEY ("asset_id")
|
110140
|
+
REFERENCES "kithe_models" ("id")
|
110141
|
+
[0m
|
110142
|
+
[1m[35m (4.6ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
110143
|
+
FOREIGN KEY ("containee_id")
|
110144
|
+
REFERENCES "kithe_models" ("id")
|
110145
|
+
[0m
|
110146
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
110147
|
+
FOREIGN KEY ("container_id")
|
110148
|
+
REFERENCES "kithe_models" ("id")
|
110149
|
+
[0m
|
110150
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110151
|
+
FOREIGN KEY ("leaf_representative_id")
|
110152
|
+
REFERENCES "kithe_models" ("id")
|
110153
|
+
[0m
|
110154
|
+
[1m[35m (3.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110155
|
+
FOREIGN KEY ("parent_id")
|
110156
|
+
REFERENCES "kithe_models" ("id")
|
110157
|
+
[0m
|
110158
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110159
|
+
FOREIGN KEY ("representative_id")
|
110160
|
+
REFERENCES "kithe_models" ("id")
|
110161
|
+
[0m
|
110162
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110163
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.0ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110164
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110165
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
110166
|
+
[1m[35mSQL (0.6ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110167
|
+
[1m[35mSQL (0.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
110168
|
+
[1m[35m (9.8ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110207
|
+
[1m[35m (23.1ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
110208
|
+
[1m[35m (43.6ms)[0m [1m[35mCREATE 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)[0m
|
110209
|
+
[1m[35m (16.1ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110210
|
+
[1m[35m (21.5ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110211
|
+
[1m[35m (3.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
110212
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
110213
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110214
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110215
|
+
[1m[35m (6.6ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
110216
|
+
[1m[35m (6.7ms)[0m [1m[35mCREATE 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)[0m
|
110217
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110218
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110219
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110220
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110221
|
+
[1m[35m (4.3ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
110222
|
+
FOREIGN KEY ("asset_id")
|
110223
|
+
REFERENCES "kithe_models" ("id")
|
110224
|
+
[0m
|
110225
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
110226
|
+
FOREIGN KEY ("containee_id")
|
110227
|
+
REFERENCES "kithe_models" ("id")
|
110228
|
+
[0m
|
110229
|
+
[1m[35m (2.3ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
110230
|
+
FOREIGN KEY ("container_id")
|
110231
|
+
REFERENCES "kithe_models" ("id")
|
110232
|
+
[0m
|
110233
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110234
|
+
FOREIGN KEY ("leaf_representative_id")
|
110235
|
+
REFERENCES "kithe_models" ("id")
|
110236
|
+
[0m
|
110237
|
+
[1m[35m (4.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110238
|
+
FOREIGN KEY ("parent_id")
|
110239
|
+
REFERENCES "kithe_models" ("id")
|
110240
|
+
[0m
|
110241
|
+
[1m[35m (3.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110242
|
+
FOREIGN KEY ("representative_id")
|
110243
|
+
REFERENCES "kithe_models" ("id")
|
110244
|
+
[0m
|
110245
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110246
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110247
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110248
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.4ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "development"], ["updated_at", "2020-05-27 16:05:50.059067"], ["key", "environment"]]
|
110249
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110250
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110251
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110252
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.5ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-27 16:05:50.071778"], ["key", "environment"]]
|
110253
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110254
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
110255
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110256
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110257
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110258
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110259
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110260
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110261
|
+
[1m[35m (215.0ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
110262
|
+
[1m[35m (247.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
110263
|
+
[1m[35m (572.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
110264
|
+
[1m[35m (498.2ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
110265
|
+
[1m[35m (15.1ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110266
|
+
[1m[35m (26.0ms)[0m [1m[35mCREATE 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)[0m
|
110267
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
110268
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110269
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
110270
|
+
[1m[35m (0.7ms)[0m [1m[35mBEGIN[0m
|
110271
|
+
[1m[35mSQL (29.6ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110272
|
+
[1m[36mprimary::SchemaMigration Create (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
110273
|
+
[1m[35m (1.1ms)[0m [1m[35mCOMMIT[0m
|
110274
|
+
Migrating to CreateKitheModels (20181015143413)
|
110275
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110276
|
+
[1m[35m (21.5ms)[0m [1m[35mCREATE 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)[0m
|
110277
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
110278
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110279
|
+
[1m[35m (2.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110280
|
+
FOREIGN KEY ("parent_id")
|
110281
|
+
REFERENCES "kithe_models" ("id")
|
110282
|
+
[0m
|
110283
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
110284
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110285
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
110286
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110287
|
+
[1m[35m (6.8ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110323
|
+
[1m[35m (25.2ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
110324
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110325
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
110326
|
+
[1m[35m (1.3ms)[0m [1m[35mCOMMIT[0m
|
110327
|
+
Migrating to AddFileDataToModel (20181031190647)
|
110328
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110329
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
110330
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
110331
|
+
[1m[35m (6.1ms)[0m [1m[35mCOMMIT[0m
|
110332
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
110333
|
+
[1m[35m (0.7ms)[0m [1m[35mBEGIN[0m
|
110334
|
+
[1m[35m (17.2ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
110338
|
+
[1m[35m (5.4ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110339
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110340
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
110341
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110342
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
110343
|
+
[1m[35m (6.0ms)[0m [1m[35mBEGIN[0m
|
110344
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
110345
|
+
[1m[35m (13.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110346
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110347
|
+
FOREIGN KEY ("representative_id")
|
110348
|
+
REFERENCES "kithe_models" ("id")
|
110349
|
+
[0m
|
110350
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
110351
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110352
|
+
[1m[35m (1.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110353
|
+
FOREIGN KEY ("leaf_representative_id")
|
110354
|
+
REFERENCES "kithe_models" ("id")
|
110355
|
+
[0m
|
110356
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
110357
|
+
[1m[35m (0.9ms)[0m [1m[35mCOMMIT[0m
|
110358
|
+
Migrating to ContainsAssociation (20190109192252)
|
110359
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110360
|
+
[1m[35m (2.1ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
110367
|
+
[1m[35m (7.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110368
|
+
[1m[35m (7.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110369
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
110370
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110371
|
+
Migrating to KitheModelType (20190404144551)
|
110372
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110373
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
110374
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
110375
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
110376
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
110377
|
+
[1m[35m (6.4ms)[0m [1m[35mCOMMIT[0m
|
110378
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110379
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110380
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:23.265055"], ["updated_at", "2020-05-27 16:15:23.265055"]]
|
110381
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110382
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
110383
|
+
[1m[35m (1.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110384
|
+
[1m[35m (4.8ms)[0m [1m[34m 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
|
+
[0m
|
110395
|
+
[1m[35m (1.5ms)[0m [1m[34m 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
|
+
[0m
|
110407
|
+
[1m[35m (1.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110408
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110409
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110410
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110411
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110412
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110413
|
+
[1m[35m (207.6ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
110414
|
+
[1m[35m (204.7ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
110415
|
+
[1m[35m (434.7ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
110416
|
+
[1m[35m (556.2ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
110417
|
+
[1m[35mSQL (13.4ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110418
|
+
[1m[35mSQL (0.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
110419
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110458
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
110459
|
+
[1m[35m (7.5ms)[0m [1m[35mCREATE 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)[0m
|
110460
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110461
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110462
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
110463
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
110464
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110465
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110466
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
110467
|
+
[1m[35m (7.7ms)[0m [1m[35mCREATE 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)[0m
|
110468
|
+
[1m[35m (2.5ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110469
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110470
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110471
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110472
|
+
[1m[35m (3.3ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
110473
|
+
FOREIGN KEY ("asset_id")
|
110474
|
+
REFERENCES "kithe_models" ("id")
|
110475
|
+
[0m
|
110476
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
110477
|
+
FOREIGN KEY ("containee_id")
|
110478
|
+
REFERENCES "kithe_models" ("id")
|
110479
|
+
[0m
|
110480
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
110481
|
+
FOREIGN KEY ("container_id")
|
110482
|
+
REFERENCES "kithe_models" ("id")
|
110483
|
+
[0m
|
110484
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110485
|
+
FOREIGN KEY ("leaf_representative_id")
|
110486
|
+
REFERENCES "kithe_models" ("id")
|
110487
|
+
[0m
|
110488
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110489
|
+
FOREIGN KEY ("parent_id")
|
110490
|
+
REFERENCES "kithe_models" ("id")
|
110491
|
+
[0m
|
110492
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110493
|
+
FOREIGN KEY ("representative_id")
|
110494
|
+
REFERENCES "kithe_models" ("id")
|
110495
|
+
[0m
|
110496
|
+
[1m[35m (6.4ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110497
|
+
[1m[35m (1.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110498
|
+
[1m[35m (1.0ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
110499
|
+
[1m[35m (0.9ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
110500
|
+
(20181015143259),
|
110501
|
+
(20181015143413),
|
110502
|
+
(20181015143737),
|
110503
|
+
(20181031190647),
|
110504
|
+
(20181128185658),
|
110505
|
+
(20190103144947),
|
110506
|
+
(20190109192252);
|
110507
|
+
|
110508
|
+
[0m
|
110509
|
+
[1m[35m (3.7ms)[0m [1m[35mCREATE 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)[0m
|
110510
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110511
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110512
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:41.046597"], ["updated_at", "2020-05-27 16:15:41.046597"]]
|
110513
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110514
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110515
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
110516
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110517
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:15:41.055003"], ["updated_at", "2020-05-27 16:15:41.055003"]]
|
110518
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110519
|
+
[1m[35mSQL (17.0ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110520
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
110521
|
+
[1m[35m (9.5ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110560
|
+
[1m[35m (0.5ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
110561
|
+
[1m[35m (8.3ms)[0m [1m[35mCREATE 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)[0m
|
110562
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110563
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110564
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
110565
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
110566
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110567
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110568
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
110569
|
+
[1m[35m (6.3ms)[0m [1m[35mCREATE 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)[0m
|
110570
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110571
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110572
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110573
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110574
|
+
[1m[35m (3.6ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
110575
|
+
FOREIGN KEY ("asset_id")
|
110576
|
+
REFERENCES "kithe_models" ("id")
|
110577
|
+
[0m
|
110578
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
110579
|
+
FOREIGN KEY ("containee_id")
|
110580
|
+
REFERENCES "kithe_models" ("id")
|
110581
|
+
[0m
|
110582
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
110583
|
+
FOREIGN KEY ("container_id")
|
110584
|
+
REFERENCES "kithe_models" ("id")
|
110585
|
+
[0m
|
110586
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110587
|
+
FOREIGN KEY ("leaf_representative_id")
|
110588
|
+
REFERENCES "kithe_models" ("id")
|
110589
|
+
[0m
|
110590
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110591
|
+
FOREIGN KEY ("parent_id")
|
110592
|
+
REFERENCES "kithe_models" ("id")
|
110593
|
+
[0m
|
110594
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110595
|
+
FOREIGN KEY ("representative_id")
|
110596
|
+
REFERENCES "kithe_models" ("id")
|
110597
|
+
[0m
|
110598
|
+
[1m[35m (3.1ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110599
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110600
|
+
[1m[35m (0.8ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
110601
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
110602
|
+
(20181015143259),
|
110603
|
+
(20181015143413),
|
110604
|
+
(20181015143737),
|
110605
|
+
(20181031190647),
|
110606
|
+
(20181128185658),
|
110607
|
+
(20190103144947),
|
110608
|
+
(20190109192252);
|
110609
|
+
|
110610
|
+
[0m
|
110611
|
+
[1m[35m (4.7ms)[0m [1m[35mCREATE 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)[0m
|
110612
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110613
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110614
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:41.295599"], ["updated_at", "2020-05-27 16:15:41.295599"]]
|
110615
|
+
[1m[35m (0.9ms)[0m [1m[35mCOMMIT[0m
|
110616
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110617
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110618
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.4ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-27 16:15:41.302574"], ["key", "environment"]]
|
110619
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110620
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
110621
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110622
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.4ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:15:41.308393"], ["updated_at", "2020-05-27 16:15:41.308393"]]
|
110623
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110624
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110625
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110626
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110627
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110628
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110629
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110630
|
+
[1m[35m (217.9ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
110631
|
+
[1m[35m (219.9ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
110632
|
+
[1m[35m (498.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
110633
|
+
[1m[35m (549.0ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
110634
|
+
[1m[35m (16.4ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110635
|
+
[1m[35m (111.0ms)[0m [1m[35mCREATE 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)[0m
|
110636
|
+
[1m[35m (1.1ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
110637
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110638
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
110639
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110640
|
+
[1m[35mSQL (13.7ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110641
|
+
[1m[36mprimary::SchemaMigration Create (20.8ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
110642
|
+
[1m[35m (2.0ms)[0m [1m[35mCOMMIT[0m
|
110643
|
+
Migrating to CreateKitheModels (20181015143413)
|
110644
|
+
[1m[35m (0.5ms)[0m [1m[35mBEGIN[0m
|
110645
|
+
[1m[35m (5.5ms)[0m [1m[35mCREATE 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)[0m
|
110646
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
110647
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110648
|
+
[1m[35m (4.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110649
|
+
FOREIGN KEY ("parent_id")
|
110650
|
+
REFERENCES "kithe_models" ("id")
|
110651
|
+
[0m
|
110652
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
110653
|
+
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
110654
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
110655
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110656
|
+
[1m[35m (8.1ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110692
|
+
[1m[35m (5.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
110693
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110694
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
110695
|
+
[1m[35m (1.1ms)[0m [1m[35mCOMMIT[0m
|
110696
|
+
Migrating to AddFileDataToModel (20181031190647)
|
110697
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110698
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
110699
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
110700
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110701
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
110702
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110703
|
+
[1m[35m (7.2ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
110707
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110708
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110709
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
110710
|
+
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
110711
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
110712
|
+
[1m[35m (3.1ms)[0m [1m[35mBEGIN[0m
|
110713
|
+
[1m[35m (1.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
110714
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110715
|
+
[1m[35m (2.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110716
|
+
FOREIGN KEY ("representative_id")
|
110717
|
+
REFERENCES "kithe_models" ("id")
|
110718
|
+
[0m
|
110719
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
110720
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110721
|
+
[1m[35m (3.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110722
|
+
FOREIGN KEY ("leaf_representative_id")
|
110723
|
+
REFERENCES "kithe_models" ("id")
|
110724
|
+
[0m
|
110725
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
110726
|
+
[1m[35m (5.4ms)[0m [1m[35mCOMMIT[0m
|
110727
|
+
Migrating to ContainsAssociation (20190109192252)
|
110728
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110729
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
110736
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110737
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110738
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
110739
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110740
|
+
Migrating to KitheModelType (20190404144551)
|
110741
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110742
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
110743
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
110744
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
110745
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
110746
|
+
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
110747
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.0ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110748
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
110749
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:16:55.002081"], ["updated_at", "2020-05-27 16:16:55.002081"]]
|
110750
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110751
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
110752
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110753
|
+
[1m[35m (5.2ms)[0m [1m[34m 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
|
+
[0m
|
110764
|
+
[1m[35m (2.2ms)[0m [1m[34m 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
|
+
[0m
|
110776
|
+
[1m[35m (1.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110777
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110778
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110779
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110780
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110781
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110782
|
+
[1m[35m (205.7ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
110783
|
+
[1m[35m (212.8ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
110784
|
+
[1m[35m (538.0ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
110785
|
+
[1m[35m (495.1ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
110786
|
+
[1m[35m (54.0ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110787
|
+
[1m[35m (5.6ms)[0m [1m[35mCREATE 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)[0m
|
110788
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
110789
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110790
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
110791
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110792
|
+
[1m[35mSQL (21.7ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110793
|
+
[1m[36mprimary::SchemaMigration Create (1.7ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
110794
|
+
[1m[35m (2.1ms)[0m [1m[35mCOMMIT[0m
|
110795
|
+
Migrating to CreateKitheModels (20181015143413)
|
110796
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110797
|
+
[1m[35m (4.0ms)[0m [1m[35mCREATE 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)[0m
|
110798
|
+
[1m[35m (0.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
110799
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110800
|
+
[1m[35m (2.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110801
|
+
FOREIGN KEY ("parent_id")
|
110802
|
+
REFERENCES "kithe_models" ("id")
|
110803
|
+
[0m
|
110804
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
110805
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110806
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
110807
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
110808
|
+
[1m[35m (7.4ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110844
|
+
[1m[35m (20.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
110845
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110846
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
110847
|
+
[1m[35m (1.4ms)[0m [1m[35mCOMMIT[0m
|
110848
|
+
Migrating to AddFileDataToModel (20181031190647)
|
110849
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110850
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
110851
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
110852
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110853
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
110854
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110855
|
+
[1m[35m (8.1ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
110859
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
110860
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
110861
|
+
[1m[36mprimary::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
110862
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
110863
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
110864
|
+
[1m[35m (6.4ms)[0m [1m[35mBEGIN[0m
|
110865
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
110866
|
+
[1m[35m (7.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
110867
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
110868
|
+
FOREIGN KEY ("representative_id")
|
110869
|
+
REFERENCES "kithe_models" ("id")
|
110870
|
+
[0m
|
110871
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
110872
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
110873
|
+
[1m[35m (1.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
110874
|
+
FOREIGN KEY ("leaf_representative_id")
|
110875
|
+
REFERENCES "kithe_models" ("id")
|
110876
|
+
[0m
|
110877
|
+
[1m[36mprimary::SchemaMigration Create (0.5ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
110878
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110879
|
+
Migrating to ContainsAssociation (20190109192252)
|
110880
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110881
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
110888
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
110889
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
110890
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
110891
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110892
|
+
Migrating to KitheModelType (20190404144551)
|
110893
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110894
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
110895
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
110896
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
110897
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
110898
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
110899
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
110900
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110901
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:01.957849"], ["updated_at", "2020-05-27 16:19:01.957849"]]
|
110902
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
110903
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
110904
|
+
[1m[35m (2.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110905
|
+
[1m[35m (5.0ms)[0m [1m[34m 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
|
+
[0m
|
110916
|
+
[1m[35m (1.8ms)[0m [1m[34m 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
|
+
[0m
|
110928
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110929
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110930
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110931
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110932
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110933
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
110934
|
+
[1m[35m (209.2ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
110935
|
+
[1m[35m (206.0ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
110936
|
+
[1m[35m (512.2ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
110937
|
+
[1m[35m (434.6ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
110938
|
+
[1m[35m (7.1ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
110939
|
+
[1m[35m (6.4ms)[0m [1m[35mCREATE 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)[0m
|
110940
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
110941
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
110942
|
+
Migrating to EnablePgcryptoExtension (20181015143259)
|
110943
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110944
|
+
[1m[35mSQL (17.0ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
110945
|
+
[1m[36mprimary::SchemaMigration Create (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143259"]]
|
110946
|
+
[1m[35m (1.4ms)[0m [1m[35mCOMMIT[0m
|
110947
|
+
Migrating to CreateKitheModels (20181015143413)
|
110948
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
110949
|
+
[1m[35m (4.7ms)[0m [1m[35mCREATE 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)[0m
|
110950
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "parent_id" uuid[0m
|
110951
|
+
[1m[35m (16.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
110952
|
+
[1m[35m (7.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
110953
|
+
FOREIGN KEY ("parent_id")
|
110954
|
+
REFERENCES "kithe_models" ("id")
|
110955
|
+
[0m
|
110956
|
+
[1m[36mprimary::SchemaMigration Create (82.0ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143413"]]
|
110957
|
+
[1m[35m (6.1ms)[0m [1m[35mCOMMIT[0m
|
110958
|
+
Migrating to KitheModelsFriendlierId (20181015143737)
|
110959
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
110960
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE 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
|
+
[0m
|
110996
|
+
[1m[35m (16.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL[0m
|
110997
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
110998
|
+
[1m[36mprimary::SchemaMigration Create (1.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181015143737"]]
|
110999
|
+
[1m[35m (2.0ms)[0m [1m[35mCOMMIT[0m
|
111000
|
+
Migrating to AddFileDataToModel (20181031190647)
|
111001
|
+
[1m[35m (1.1ms)[0m [1m[35mBEGIN[0m
|
111002
|
+
[1m[35m (1.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "file_data" jsonb[0m
|
111003
|
+
[1m[36mprimary::SchemaMigration Create (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181031190647"]]
|
111004
|
+
[1m[35m (0.8ms)[0m [1m[35mCOMMIT[0m
|
111005
|
+
Migrating to CreateKitheDerivatives (20181128185658)
|
111006
|
+
[1m[35m (1.9ms)[0m [1m[35mBEGIN[0m
|
111007
|
+
[1m[35m (7.2ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
111011
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111012
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111013
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181128185658"]]
|
111014
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111015
|
+
Migrating to AddRepresentativeRelations (20190103144947)
|
111016
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
111017
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "representative_id" uuid[0m
|
111018
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111019
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111020
|
+
FOREIGN KEY ("representative_id")
|
111021
|
+
REFERENCES "kithe_models" ("id")
|
111022
|
+
[0m
|
111023
|
+
[1m[35m (0.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid[0m
|
111024
|
+
[1m[35m (3.9ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111025
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111026
|
+
FOREIGN KEY ("leaf_representative_id")
|
111027
|
+
REFERENCES "kithe_models" ("id")
|
111028
|
+
[0m
|
111029
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190103144947"]]
|
111030
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111031
|
+
Migrating to ContainsAssociation (20190109192252)
|
111032
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
111033
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE 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
|
+
)[0m
|
111040
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111041
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111042
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190109192252"]]
|
111043
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111044
|
+
Migrating to KitheModelType (20190404144551)
|
111045
|
+
[1m[35m (0.3ms)[0m [1m[35mBEGIN[0m
|
111046
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "kithe_models" ADD "kithe_model_type" integer[0m
|
111047
|
+
[1m[35m (1.3ms)[0m [1m[34mSELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1[0m [["LIMIT", 1000]]
|
111048
|
+
[1m[35m (0.9ms)[0m [1m[35mALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL[0m
|
111049
|
+
[1m[36mprimary::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190404144551"]]
|
111050
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111051
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111052
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111053
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.7ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:20.045824"], ["updated_at", "2020-05-27 16:19:20.045824"]]
|
111054
|
+
[1m[35m (0.8ms)[0m [1m[35mCOMMIT[0m
|
111055
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
111056
|
+
[1m[35m (1.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111057
|
+
[1m[35m (5.0ms)[0m [1m[34m 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
|
+
[0m
|
111068
|
+
[1m[35m (1.9ms)[0m [1m[34m 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
|
+
[0m
|
111080
|
+
[1m[35m (18.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111081
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111082
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111083
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111084
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111085
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111086
|
+
[1m[35m (215.3ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
111087
|
+
[1m[35m (375.5ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
111088
|
+
[1m[35m (458.1ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
111089
|
+
[1m[35m (933.1ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
111090
|
+
[1m[35mSQL (12.8ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111091
|
+
[1m[35mSQL (0.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111092
|
+
[1m[35m (2.4ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111131
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111132
|
+
[1m[35m (6.7ms)[0m [1m[35mCREATE 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)[0m
|
111133
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111134
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111135
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111136
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111137
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111138
|
+
[1m[35m (2.5ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111139
|
+
[1m[35m (0.5ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111140
|
+
[1m[35m (7.8ms)[0m [1m[35mCREATE 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)[0m
|
111141
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111142
|
+
[1m[35m (23.6ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111143
|
+
[1m[35m (8.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111144
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111145
|
+
[1m[35m (3.6ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111146
|
+
FOREIGN KEY ("asset_id")
|
111147
|
+
REFERENCES "kithe_models" ("id")
|
111148
|
+
[0m
|
111149
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111150
|
+
FOREIGN KEY ("containee_id")
|
111151
|
+
REFERENCES "kithe_models" ("id")
|
111152
|
+
[0m
|
111153
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111154
|
+
FOREIGN KEY ("container_id")
|
111155
|
+
REFERENCES "kithe_models" ("id")
|
111156
|
+
[0m
|
111157
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111158
|
+
FOREIGN KEY ("leaf_representative_id")
|
111159
|
+
REFERENCES "kithe_models" ("id")
|
111160
|
+
[0m
|
111161
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111162
|
+
FOREIGN KEY ("parent_id")
|
111163
|
+
REFERENCES "kithe_models" ("id")
|
111164
|
+
[0m
|
111165
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111166
|
+
FOREIGN KEY ("representative_id")
|
111167
|
+
REFERENCES "kithe_models" ("id")
|
111168
|
+
[0m
|
111169
|
+
[1m[35m (3.4ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
111170
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111171
|
+
[1m[35m (1.0ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
111172
|
+
[1m[35m (10.3ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
111173
|
+
(20181015143259),
|
111174
|
+
(20181015143413),
|
111175
|
+
(20181015143737),
|
111176
|
+
(20181031190647),
|
111177
|
+
(20181128185658),
|
111178
|
+
(20190103144947),
|
111179
|
+
(20190109192252);
|
111180
|
+
|
111181
|
+
[0m
|
111182
|
+
[1m[35m (13.4ms)[0m [1m[35mCREATE 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)[0m
|
111183
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111184
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111185
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:32.359365"], ["updated_at", "2020-05-27 16:19:32.359365"]]
|
111186
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111187
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111188
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111189
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111190
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.8ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "42c53de0cd440a8a7ed21435cee78257b6e0c991"], ["created_at", "2020-05-27 16:19:32.368638"], ["updated_at", "2020-05-27 16:19:32.368638"]]
|
111191
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
111192
|
+
[1m[35mSQL (19.4ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111193
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111194
|
+
[1m[35m (2.5ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111233
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111234
|
+
[1m[35m (15.3ms)[0m [1m[35mCREATE 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)[0m
|
111235
|
+
[1m[35m (4.1ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111236
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111237
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111238
|
+
[1m[35m (3.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111239
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111240
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111241
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111242
|
+
[1m[35m (3.7ms)[0m [1m[35mCREATE 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)[0m
|
111243
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111244
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111245
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111246
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111247
|
+
[1m[35m (5.0ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111248
|
+
FOREIGN KEY ("asset_id")
|
111249
|
+
REFERENCES "kithe_models" ("id")
|
111250
|
+
[0m
|
111251
|
+
[1m[35m (2.2ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111252
|
+
FOREIGN KEY ("containee_id")
|
111253
|
+
REFERENCES "kithe_models" ("id")
|
111254
|
+
[0m
|
111255
|
+
[1m[35m (45.4ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111256
|
+
FOREIGN KEY ("container_id")
|
111257
|
+
REFERENCES "kithe_models" ("id")
|
111258
|
+
[0m
|
111259
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111260
|
+
FOREIGN KEY ("leaf_representative_id")
|
111261
|
+
REFERENCES "kithe_models" ("id")
|
111262
|
+
[0m
|
111263
|
+
[1m[35m (2.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111264
|
+
FOREIGN KEY ("parent_id")
|
111265
|
+
REFERENCES "kithe_models" ("id")
|
111266
|
+
[0m
|
111267
|
+
[1m[35m (9.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111268
|
+
FOREIGN KEY ("representative_id")
|
111269
|
+
REFERENCES "kithe_models" ("id")
|
111270
|
+
[0m
|
111271
|
+
[1m[35m (5.2ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
111272
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111273
|
+
[1m[35m (3.2ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
111274
|
+
[1m[35m (4.5ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
111275
|
+
(20181015143259),
|
111276
|
+
(20181015143413),
|
111277
|
+
(20181015143737),
|
111278
|
+
(20181031190647),
|
111279
|
+
(20181128185658),
|
111280
|
+
(20190103144947),
|
111281
|
+
(20190109192252);
|
111282
|
+
|
111283
|
+
[0m
|
111284
|
+
[1m[35m (42.4ms)[0m [1m[35mCREATE 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)[0m
|
111285
|
+
[1m[36mActiveRecord::InternalMetadata Load (2.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111286
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111287
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.7ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:32.703724"], ["updated_at", "2020-05-27 16:19:32.703724"]]
|
111288
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111289
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111290
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111291
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.5ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-27 16:19:32.711074"], ["key", "environment"]]
|
111292
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111293
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111294
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111295
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "42c53de0cd440a8a7ed21435cee78257b6e0c991"], ["created_at", "2020-05-27 16:19:32.718252"], ["updated_at", "2020-05-27 16:19:32.718252"]]
|
111296
|
+
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
111297
|
+
[1m[35m (16.6ms)[0m [1m[34mSELECT pg_try_advisory_lock(1601470156486188030)[0m
|
111298
|
+
[1m[35m (2.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111299
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111300
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT pg_advisory_unlock(1601470156486188030)[0m
|
111301
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111302
|
+
[1m[35m (66.1ms)[0m [1m[34m 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
|
+
[0m
|
111313
|
+
[1m[35m (2.0ms)[0m [1m[34m 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
|
+
[0m
|
111325
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111326
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111327
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111328
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111329
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111330
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111331
|
+
[1m[35m (239.7ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
111332
|
+
[1m[35m (242.5ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
111333
|
+
[1m[35m (905.5ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
111334
|
+
[1m[35m (604.8ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
111335
|
+
[1m[35mSQL (73.8ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111336
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111337
|
+
[1m[35m (98.8ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111376
|
+
[1m[35m (5.8ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111377
|
+
[1m[35m (23.5ms)[0m [1m[35mCREATE 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)[0m
|
111378
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111379
|
+
[1m[35m (2.7ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111380
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111381
|
+
[1m[35m (2.9ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111382
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111383
|
+
[1m[35m (3.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111384
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111385
|
+
[1m[35m (5.1ms)[0m [1m[35mCREATE 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)[0m
|
111386
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111387
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111388
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111389
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111390
|
+
[1m[35m (7.8ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111391
|
+
FOREIGN KEY ("asset_id")
|
111392
|
+
REFERENCES "kithe_models" ("id")
|
111393
|
+
[0m
|
111394
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111395
|
+
FOREIGN KEY ("containee_id")
|
111396
|
+
REFERENCES "kithe_models" ("id")
|
111397
|
+
[0m
|
111398
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111399
|
+
FOREIGN KEY ("container_id")
|
111400
|
+
REFERENCES "kithe_models" ("id")
|
111401
|
+
[0m
|
111402
|
+
[1m[35m (2.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111403
|
+
FOREIGN KEY ("leaf_representative_id")
|
111404
|
+
REFERENCES "kithe_models" ("id")
|
111405
|
+
[0m
|
111406
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111407
|
+
FOREIGN KEY ("parent_id")
|
111408
|
+
REFERENCES "kithe_models" ("id")
|
111409
|
+
[0m
|
111410
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111411
|
+
FOREIGN KEY ("representative_id")
|
111412
|
+
REFERENCES "kithe_models" ("id")
|
111413
|
+
[0m
|
111414
|
+
[1m[35m (3.5ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
111415
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111416
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
111417
|
+
[1m[35m (0.8ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
111418
|
+
(20181015143259),
|
111419
|
+
(20181015143413),
|
111420
|
+
(20181015143737),
|
111421
|
+
(20181031190647),
|
111422
|
+
(20181128185658),
|
111423
|
+
(20190103144947),
|
111424
|
+
(20190109192252);
|
111425
|
+
|
111426
|
+
[0m
|
111427
|
+
[1m[35m (3.6ms)[0m [1m[35mCREATE 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)[0m
|
111428
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111429
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111430
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-28 13:26:55.432158"], ["updated_at", "2020-05-28 13:26:55.432158"]]
|
111431
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111432
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111433
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111434
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
111435
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.4ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-28 13:26:55.460004"], ["updated_at", "2020-05-28 13:26:55.460004"]]
|
111436
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111437
|
+
[1m[35mSQL (16.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111438
|
+
[1m[35mSQL (0.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111439
|
+
[1m[35m (2.3ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111478
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111479
|
+
[1m[35m (6.7ms)[0m [1m[35mCREATE 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)[0m
|
111480
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111481
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111482
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111483
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111484
|
+
[1m[35m (1.9ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111485
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111486
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111487
|
+
[1m[35m (3.9ms)[0m [1m[35mCREATE 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)[0m
|
111488
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111489
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111490
|
+
[1m[35m (12.7ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111491
|
+
[1m[35m (12.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111492
|
+
[1m[35m (5.1ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111493
|
+
FOREIGN KEY ("asset_id")
|
111494
|
+
REFERENCES "kithe_models" ("id")
|
111495
|
+
[0m
|
111496
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111497
|
+
FOREIGN KEY ("containee_id")
|
111498
|
+
REFERENCES "kithe_models" ("id")
|
111499
|
+
[0m
|
111500
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111501
|
+
FOREIGN KEY ("container_id")
|
111502
|
+
REFERENCES "kithe_models" ("id")
|
111503
|
+
[0m
|
111504
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111505
|
+
FOREIGN KEY ("leaf_representative_id")
|
111506
|
+
REFERENCES "kithe_models" ("id")
|
111507
|
+
[0m
|
111508
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111509
|
+
FOREIGN KEY ("parent_id")
|
111510
|
+
REFERENCES "kithe_models" ("id")
|
111511
|
+
[0m
|
111512
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111513
|
+
FOREIGN KEY ("representative_id")
|
111514
|
+
REFERENCES "kithe_models" ("id")
|
111515
|
+
[0m
|
111516
|
+
[1m[35m (3.7ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
111517
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111518
|
+
[1m[35m (0.9ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
111519
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
111520
|
+
(20181015143259),
|
111521
|
+
(20181015143413),
|
111522
|
+
(20181015143737),
|
111523
|
+
(20181031190647),
|
111524
|
+
(20181128185658),
|
111525
|
+
(20190103144947),
|
111526
|
+
(20190109192252);
|
111527
|
+
|
111528
|
+
[0m
|
111529
|
+
[1m[35m (3.3ms)[0m [1m[35mCREATE 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)[0m
|
111530
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111531
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111532
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.7ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-05-28 13:26:55.653588"], ["updated_at", "2020-05-28 13:26:55.653588"]]
|
111533
|
+
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
111534
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111535
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111536
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.6ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-05-28 13:26:55.661463"], ["key", "environment"]]
|
111537
|
+
[1m[35m (0.3ms)[0m [1m[35mCOMMIT[0m
|
111538
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111539
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111540
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-28 13:26:55.668516"], ["updated_at", "2020-05-28 13:26:55.668516"]]
|
111541
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111542
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111543
|
+
[1m[35m (2.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111544
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111545
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111546
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111547
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111548
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111549
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111550
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111551
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111552
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111553
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111554
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111555
|
+
[1m[35mSQL (38.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111556
|
+
[1m[35mSQL (0.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111557
|
+
[1m[35m (32.7ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111596
|
+
[1m[35m (45.1ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111597
|
+
[1m[35m (50.4ms)[0m [1m[35mCREATE 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)[0m
|
111598
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111599
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111600
|
+
[1m[35m (3.6ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111601
|
+
[1m[35m (4.5ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111602
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111603
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111604
|
+
[1m[35m (7.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111605
|
+
[1m[35m (12.2ms)[0m [1m[35mCREATE 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)[0m
|
111606
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111607
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111608
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111609
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111610
|
+
[1m[35m (8.9ms)[0m [1m[35mCREATE TABLE "plain_old_ar" ("id" bigserial primary key, "title" character varying, "description" text)[0m
|
111611
|
+
[1m[35m (6.3ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111612
|
+
FOREIGN KEY ("asset_id")
|
111613
|
+
REFERENCES "kithe_models" ("id")
|
111614
|
+
[0m
|
111615
|
+
[1m[35m (3.9ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111616
|
+
FOREIGN KEY ("containee_id")
|
111617
|
+
REFERENCES "kithe_models" ("id")
|
111618
|
+
[0m
|
111619
|
+
[1m[35m (2.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111620
|
+
FOREIGN KEY ("container_id")
|
111621
|
+
REFERENCES "kithe_models" ("id")
|
111622
|
+
[0m
|
111623
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111624
|
+
FOREIGN KEY ("leaf_representative_id")
|
111625
|
+
REFERENCES "kithe_models" ("id")
|
111626
|
+
[0m
|
111627
|
+
[1m[35m (3.4ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111628
|
+
FOREIGN KEY ("parent_id")
|
111629
|
+
REFERENCES "kithe_models" ("id")
|
111630
|
+
[0m
|
111631
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111632
|
+
FOREIGN KEY ("representative_id")
|
111633
|
+
REFERENCES "kithe_models" ("id")
|
111634
|
+
[0m
|
111635
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111636
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111637
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111638
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111639
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111640
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.5ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "03c1babae3d781ef770d42f3017561a4fadf7200"], ["updated_at", "2020-06-04 16:46:18.145376"], ["key", "schema_sha1"]]
|
111641
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111642
|
+
[1m[35mSQL (2.6ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111643
|
+
[1m[35mSQL (0.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111644
|
+
[1m[35m (28.9ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111683
|
+
[1m[35m (29.1ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111684
|
+
[1m[35m (24.3ms)[0m [1m[35mCREATE 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)[0m
|
111685
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111686
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111687
|
+
[1m[35m (2.7ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111688
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111689
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111690
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111691
|
+
[1m[35m (6.6ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111692
|
+
[1m[35m (5.2ms)[0m [1m[35mCREATE 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)[0m
|
111693
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111694
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111695
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111696
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111697
|
+
[1m[35m (4.5ms)[0m [1m[35mCREATE TABLE "plain_old_ar" ("id" bigserial primary key, "title" character varying, "description" text)[0m
|
111698
|
+
[1m[35m (6.6ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111699
|
+
FOREIGN KEY ("asset_id")
|
111700
|
+
REFERENCES "kithe_models" ("id")
|
111701
|
+
[0m
|
111702
|
+
[1m[35m (2.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111703
|
+
FOREIGN KEY ("containee_id")
|
111704
|
+
REFERENCES "kithe_models" ("id")
|
111705
|
+
[0m
|
111706
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111707
|
+
FOREIGN KEY ("container_id")
|
111708
|
+
REFERENCES "kithe_models" ("id")
|
111709
|
+
[0m
|
111710
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111711
|
+
FOREIGN KEY ("leaf_representative_id")
|
111712
|
+
REFERENCES "kithe_models" ("id")
|
111713
|
+
[0m
|
111714
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111715
|
+
FOREIGN KEY ("parent_id")
|
111716
|
+
REFERENCES "kithe_models" ("id")
|
111717
|
+
[0m
|
111718
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111719
|
+
FOREIGN KEY ("representative_id")
|
111720
|
+
REFERENCES "kithe_models" ("id")
|
111721
|
+
[0m
|
111722
|
+
[1m[35m (1.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111723
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111724
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111725
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.5ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "development"], ["updated_at", "2020-06-04 16:46:18.411648"], ["key", "environment"]]
|
111726
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111727
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111728
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111729
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.5ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-06-04 16:46:18.418618"], ["key", "environment"]]
|
111730
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111731
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111732
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111733
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.4ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "03c1babae3d781ef770d42f3017561a4fadf7200"], ["updated_at", "2020-06-04 16:46:18.423797"], ["key", "schema_sha1"]]
|
111734
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111735
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111736
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111737
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111738
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111739
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111740
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111741
|
+
[1m[35m (340.9ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
111742
|
+
[1m[35m (224.9ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
111743
|
+
[1m[35m (701.4ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
111744
|
+
[1m[35m (483.4ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
111745
|
+
[1m[35mSQL (182.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111746
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111747
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111786
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111787
|
+
[1m[35m (10.4ms)[0m [1m[35mCREATE 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)[0m
|
111788
|
+
[1m[35m (2.6ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111789
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111790
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111791
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111792
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111793
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111794
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111795
|
+
[1m[35m (4.2ms)[0m [1m[35mCREATE 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)[0m
|
111796
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111797
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111798
|
+
[1m[35m (1.5ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111799
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111800
|
+
[1m[35m (8.7ms)[0m [1m[35mCREATE TABLE "plain_old_ars" ("id" bigserial primary key, "title" character varying, "description" text)[0m
|
111801
|
+
[1m[35m (3.4ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111802
|
+
FOREIGN KEY ("asset_id")
|
111803
|
+
REFERENCES "kithe_models" ("id")
|
111804
|
+
[0m
|
111805
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111806
|
+
FOREIGN KEY ("containee_id")
|
111807
|
+
REFERENCES "kithe_models" ("id")
|
111808
|
+
[0m
|
111809
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111810
|
+
FOREIGN KEY ("container_id")
|
111811
|
+
REFERENCES "kithe_models" ("id")
|
111812
|
+
[0m
|
111813
|
+
[1m[35m (1.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111814
|
+
FOREIGN KEY ("leaf_representative_id")
|
111815
|
+
REFERENCES "kithe_models" ("id")
|
111816
|
+
[0m
|
111817
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111818
|
+
FOREIGN KEY ("parent_id")
|
111819
|
+
REFERENCES "kithe_models" ("id")
|
111820
|
+
[0m
|
111821
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111822
|
+
FOREIGN KEY ("representative_id")
|
111823
|
+
REFERENCES "kithe_models" ("id")
|
111824
|
+
[0m
|
111825
|
+
[1m[35m (3.8ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
111826
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111827
|
+
[1m[35m (5.9ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
111828
|
+
[1m[35m (21.1ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
111829
|
+
(20181015143259),
|
111830
|
+
(20181015143413),
|
111831
|
+
(20181015143737),
|
111832
|
+
(20181031190647),
|
111833
|
+
(20181128185658),
|
111834
|
+
(20190103144947),
|
111835
|
+
(20190109192252);
|
111836
|
+
|
111837
|
+
[0m
|
111838
|
+
[1m[35m (3.3ms)[0m [1m[35mCREATE 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)[0m
|
111839
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111840
|
+
[1m[35m (0.7ms)[0m [1m[35mBEGIN[0m
|
111841
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:47:04.539998"], ["updated_at", "2020-06-04 16:47:04.539998"]]
|
111842
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111843
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111844
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.2ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111845
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111846
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.4ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "6d88defc9e286449197e3c57b6342e1510b872dd"], ["created_at", "2020-06-04 16:47:04.552438"], ["updated_at", "2020-06-04 16:47:04.552438"]]
|
111847
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111848
|
+
[1m[35mSQL (15.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111849
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111850
|
+
[1m[35m (2.5ms)[0m [1m[35mCREATE 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
|
+
[0m
|
111889
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
111890
|
+
[1m[35m (11.5ms)[0m [1m[35mCREATE 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)[0m
|
111891
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
111892
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
111893
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
111894
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
111895
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
111896
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
111897
|
+
[1m[35m (0.4ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
111898
|
+
[1m[35m (3.8ms)[0m [1m[35mCREATE 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)[0m
|
111899
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
111900
|
+
[1m[35m (1.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
111901
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
111902
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
111903
|
+
[1m[35m (4.5ms)[0m [1m[35mCREATE TABLE "plain_old_ars" ("id" bigserial primary key, "title" character varying, "description" text)[0m
|
111904
|
+
[1m[35m (6.5ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
111905
|
+
FOREIGN KEY ("asset_id")
|
111906
|
+
REFERENCES "kithe_models" ("id")
|
111907
|
+
[0m
|
111908
|
+
[1m[35m (2.1ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
111909
|
+
FOREIGN KEY ("containee_id")
|
111910
|
+
REFERENCES "kithe_models" ("id")
|
111911
|
+
[0m
|
111912
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
111913
|
+
FOREIGN KEY ("container_id")
|
111914
|
+
REFERENCES "kithe_models" ("id")
|
111915
|
+
[0m
|
111916
|
+
[1m[35m (3.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
111917
|
+
FOREIGN KEY ("leaf_representative_id")
|
111918
|
+
REFERENCES "kithe_models" ("id")
|
111919
|
+
[0m
|
111920
|
+
[1m[35m (19.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
111921
|
+
FOREIGN KEY ("parent_id")
|
111922
|
+
REFERENCES "kithe_models" ("id")
|
111923
|
+
[0m
|
111924
|
+
[1m[35m (7.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
111925
|
+
FOREIGN KEY ("representative_id")
|
111926
|
+
REFERENCES "kithe_models" ("id")
|
111927
|
+
[0m
|
111928
|
+
[1m[35m (7.0ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
111929
|
+
[1m[35m (0.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111930
|
+
[1m[35m (0.8ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
111931
|
+
[1m[35m (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
111932
|
+
(20181015143259),
|
111933
|
+
(20181015143413),
|
111934
|
+
(20181015143737),
|
111935
|
+
(20181031190647),
|
111936
|
+
(20181128185658),
|
111937
|
+
(20190103144947),
|
111938
|
+
(20190109192252);
|
111939
|
+
|
111940
|
+
[0m
|
111941
|
+
[1m[35m (4.1ms)[0m [1m[35mCREATE 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)[0m
|
111942
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.0ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111943
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
111944
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.8ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:47:04.783078"], ["updated_at", "2020-06-04 16:47:04.783078"]]
|
111945
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111946
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
111947
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
111948
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.4ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-06-04 16:47:04.789820"], ["key", "environment"]]
|
111949
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111950
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
111951
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
111952
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.4ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "6d88defc9e286449197e3c57b6342e1510b872dd"], ["created_at", "2020-06-04 16:47:04.795239"], ["updated_at", "2020-06-04 16:47:04.795239"]]
|
111953
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
111954
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111955
|
+
[1m[36mPlainOldAr Load (0.4ms)[0m [1m[34mSELECT "plain_old_ars".* FROM "plain_old_ars" ORDER BY "plain_old_ars"."id" ASC LIMIT $1[0m [["LIMIT", 1]]
|
111956
|
+
[1m[35m (1.0ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111957
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111958
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111959
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111960
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
111961
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
111962
|
+
[1m[35m (227.8ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_development"[0m
|
111963
|
+
[1m[35m (217.1ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
111964
|
+
[1m[35m (496.1ms)[0m [1m[35mCREATE DATABASE "kithe_development" ENCODING = 'unicode'[0m
|
111965
|
+
[1m[35m (495.5ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
111966
|
+
[1m[35mSQL (25.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
111967
|
+
[1m[35mSQL (0.3ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
111968
|
+
[1m[35m (23.8ms)[0m [1m[35mCREATE 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
|
+
[0m
|
112007
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
112008
|
+
[1m[35m (20.8ms)[0m [1m[35mCREATE 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)[0m
|
112009
|
+
[1m[35m (2.1ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
112010
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
112011
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
112012
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
112013
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
112014
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
112015
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
112016
|
+
[1m[35m (4.2ms)[0m [1m[35mCREATE 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)[0m
|
112017
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
112018
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
112019
|
+
[1m[35m (6.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
112020
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
112021
|
+
[1m[35m (3.6ms)[0m [1m[35mCREATE TABLE "plain_active_records" ("id" bigserial primary key, "title" character varying, "description" text)[0m
|
112022
|
+
[1m[35m (3.2ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
112023
|
+
FOREIGN KEY ("asset_id")
|
112024
|
+
REFERENCES "kithe_models" ("id")
|
112025
|
+
[0m
|
112026
|
+
[1m[35m (136.8ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
112027
|
+
FOREIGN KEY ("containee_id")
|
112028
|
+
REFERENCES "kithe_models" ("id")
|
112029
|
+
[0m
|
112030
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
112031
|
+
FOREIGN KEY ("container_id")
|
112032
|
+
REFERENCES "kithe_models" ("id")
|
112033
|
+
[0m
|
112034
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
112035
|
+
FOREIGN KEY ("leaf_representative_id")
|
112036
|
+
REFERENCES "kithe_models" ("id")
|
112037
|
+
[0m
|
112038
|
+
[1m[35m (1.9ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
112039
|
+
FOREIGN KEY ("parent_id")
|
112040
|
+
REFERENCES "kithe_models" ("id")
|
112041
|
+
[0m
|
112042
|
+
[1m[35m (1.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
112043
|
+
FOREIGN KEY ("representative_id")
|
112044
|
+
REFERENCES "kithe_models" ("id")
|
112045
|
+
[0m
|
112046
|
+
[1m[35m (2.9ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
112047
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112048
|
+
[1m[35m (1.1ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
112049
|
+
[1m[35m (0.6ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
112050
|
+
(20181015143259),
|
112051
|
+
(20181015143413),
|
112052
|
+
(20181015143737),
|
112053
|
+
(20181031190647),
|
112054
|
+
(20181128185658),
|
112055
|
+
(20190103144947),
|
112056
|
+
(20190109192252);
|
112057
|
+
|
112058
|
+
[0m
|
112059
|
+
[1m[35m (3.3ms)[0m [1m[35mCREATE 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)[0m
|
112060
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
112061
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
112062
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.5ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:49:37.613161"], ["updated_at", "2020-06-04 16:49:37.613161"]]
|
112063
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
112064
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
112065
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
112066
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
112067
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "7ac4a20ed84fd4d14ae476bfa58fc376b3ce6739"], ["created_at", "2020-06-04 16:49:37.623813"], ["updated_at", "2020-06-04 16:49:37.623813"]]
|
112068
|
+
[1m[35m (0.3ms)[0m [1m[35mCOMMIT[0m
|
112069
|
+
[1m[35mSQL (15.0ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
112070
|
+
[1m[35mSQL (0.2ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
112071
|
+
[1m[35m (2.2ms)[0m [1m[35mCREATE 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
|
+
[0m
|
112110
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
112111
|
+
[1m[35m (31.4ms)[0m [1m[35mCREATE 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)[0m
|
112112
|
+
[1m[35m (4.3ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
112113
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
112114
|
+
[1m[35m (0.2ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
112115
|
+
[1m[35m (2.4ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
112116
|
+
[1m[35m (1.8ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
112117
|
+
[1m[35m (1.7ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
112118
|
+
[1m[35m (3.8ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
112119
|
+
[1m[35m (4.8ms)[0m [1m[35mCREATE 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)[0m
|
112120
|
+
[1m[35m (1.1ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
112121
|
+
[1m[35m (1.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
112122
|
+
[1m[35m (3.1ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
112123
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
112124
|
+
[1m[35m (10.2ms)[0m [1m[35mCREATE TABLE "plain_active_records" ("id" bigserial primary key, "title" character varying, "description" text)[0m
|
112125
|
+
[1m[35m (4.9ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
112126
|
+
FOREIGN KEY ("asset_id")
|
112127
|
+
REFERENCES "kithe_models" ("id")
|
112128
|
+
[0m
|
112129
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
112130
|
+
FOREIGN KEY ("containee_id")
|
112131
|
+
REFERENCES "kithe_models" ("id")
|
112132
|
+
[0m
|
112133
|
+
[1m[35m (5.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
112134
|
+
FOREIGN KEY ("container_id")
|
112135
|
+
REFERENCES "kithe_models" ("id")
|
112136
|
+
[0m
|
112137
|
+
[1m[35m (14.1ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
112138
|
+
FOREIGN KEY ("leaf_representative_id")
|
112139
|
+
REFERENCES "kithe_models" ("id")
|
112140
|
+
[0m
|
112141
|
+
[1m[35m (6.8ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
112142
|
+
FOREIGN KEY ("parent_id")
|
112143
|
+
REFERENCES "kithe_models" ("id")
|
112144
|
+
[0m
|
112145
|
+
[1m[35m (8.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
112146
|
+
FOREIGN KEY ("representative_id")
|
112147
|
+
REFERENCES "kithe_models" ("id")
|
112148
|
+
[0m
|
112149
|
+
[1m[35m (14.5ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
112150
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112151
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
112152
|
+
[1m[35m (0.7ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
112153
|
+
(20181015143259),
|
112154
|
+
(20181015143413),
|
112155
|
+
(20181015143737),
|
112156
|
+
(20181031190647),
|
112157
|
+
(20181128185658),
|
112158
|
+
(20190103144947),
|
112159
|
+
(20190109192252);
|
112160
|
+
|
112161
|
+
[0m
|
112162
|
+
[1m[35m (3.8ms)[0m [1m[35mCREATE 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)[0m
|
112163
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.5ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
112164
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
112165
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.6ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-06-04 16:49:37.900916"], ["updated_at", "2020-06-04 16:49:37.900916"]]
|
112166
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
112167
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
112168
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
112169
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.6ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-06-04 16:49:37.909774"], ["key", "environment"]]
|
112170
|
+
[1m[35m (0.7ms)[0m [1m[35mCOMMIT[0m
|
112171
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
112172
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
112173
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.3ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "7ac4a20ed84fd4d14ae476bfa58fc376b3ce6739"], ["created_at", "2020-06-04 16:49:37.920363"], ["updated_at", "2020-06-04 16:49:37.920363"]]
|
112174
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
112175
|
+
[1m[35m (1.4ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112176
|
+
[1m[35m (3.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112177
|
+
[1m[35m (22.8ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
112178
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112179
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
112180
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112181
|
+
[1m[35m (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1[0m [["key", "environment"]]
|
112182
|
+
[1m[35m (364.2ms)[0m [1m[35mDROP DATABASE IF EXISTS "kithe_test"[0m
|
112183
|
+
[1m[35m (864.3ms)[0m [1m[35mCREATE DATABASE "kithe_test" ENCODING = 'unicode'[0m
|
112184
|
+
[1m[35mSQL (64.0ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "pgcrypto"[0m
|
112185
|
+
[1m[35mSQL (1.5ms)[0m [1m[35mCREATE EXTENSION IF NOT EXISTS "plpgsql"[0m
|
112186
|
+
[1m[35m (10.4ms)[0m [1m[35mCREATE 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
|
+
[0m
|
112225
|
+
[1m[35m (0.5ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_derivatives" CASCADE[0m
|
112226
|
+
[1m[35m (34.0ms)[0m [1m[35mCREATE 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)[0m
|
112227
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")[0m
|
112228
|
+
[1m[35m (2.0ms)[0m [1m[35mCREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")[0m
|
112229
|
+
[1m[35m (0.5ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_model_contains" CASCADE[0m
|
112230
|
+
[1m[35m (2.1ms)[0m [1m[35mCREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)[0m
|
112231
|
+
[1m[35m (5.0ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")[0m
|
112232
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")[0m
|
112233
|
+
[1m[35m (0.3ms)[0m [1m[35mDROP TABLE IF EXISTS "kithe_models" CASCADE[0m
|
112234
|
+
[1m[35m (29.4ms)[0m [1m[35mCREATE 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)[0m
|
112235
|
+
[1m[35m (1.6ms)[0m [1m[35mCREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")[0m
|
112236
|
+
[1m[35m (3.2ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")[0m
|
112237
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")[0m
|
112238
|
+
[1m[35m (6.3ms)[0m [1m[35mCREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")[0m
|
112239
|
+
[1m[35m (4.3ms)[0m [1m[35mALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
|
112240
|
+
FOREIGN KEY ("asset_id")
|
112241
|
+
REFERENCES "kithe_models" ("id")
|
112242
|
+
[0m
|
112243
|
+
[1m[35m (3.4ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
|
112244
|
+
FOREIGN KEY ("containee_id")
|
112245
|
+
REFERENCES "kithe_models" ("id")
|
112246
|
+
[0m
|
112247
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
|
112248
|
+
FOREIGN KEY ("container_id")
|
112249
|
+
REFERENCES "kithe_models" ("id")
|
112250
|
+
[0m
|
112251
|
+
[1m[35m (4.3ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
|
112252
|
+
FOREIGN KEY ("leaf_representative_id")
|
112253
|
+
REFERENCES "kithe_models" ("id")
|
112254
|
+
[0m
|
112255
|
+
[1m[35m (3.0ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
|
112256
|
+
FOREIGN KEY ("parent_id")
|
112257
|
+
REFERENCES "kithe_models" ("id")
|
112258
|
+
[0m
|
112259
|
+
[1m[35m (3.7ms)[0m [1m[35mALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
|
112260
|
+
FOREIGN KEY ("representative_id")
|
112261
|
+
REFERENCES "kithe_models" ("id")
|
112262
|
+
[0m
|
112263
|
+
[1m[35m (5.8ms)[0m [1m[35mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)[0m
|
112264
|
+
[1m[35m (1.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
112265
|
+
[1m[35m (8.9ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES (20190404144551)[0m
|
112266
|
+
[1m[35m (11.8ms)[0m [1m[32mINSERT INTO "schema_migrations" (version) VALUES
|
112267
|
+
(20181015143259),
|
112268
|
+
(20181015143413),
|
112269
|
+
(20181015143737),
|
112270
|
+
(20181031190647),
|
112271
|
+
(20181128185658),
|
112272
|
+
(20190103144947),
|
112273
|
+
(20190109192252);
|
112274
|
+
|
112275
|
+
[0m
|
112276
|
+
[1m[35m (5.6ms)[0m [1m[35mCREATE 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)[0m
|
112277
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.6ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
112278
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
112279
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.9ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "environment"], ["value", "development"], ["created_at", "2020-11-11 21:42:07.161354"], ["updated_at", "2020-11-11 21:42:07.161354"]]
|
112280
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
112281
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
112282
|
+
[1m[35m (0.4ms)[0m [1m[35mBEGIN[0m
|
112283
|
+
[1m[36mActiveRecord::InternalMetadata Update (0.5ms)[0m [1m[33mUPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3[0m [["value", "test"], ["updated_at", "2020-11-11 21:42:07.170009"], ["key", "environment"]]
|
112284
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
112285
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.1ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "schema_sha1"], ["LIMIT", 1]]
|
112286
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
112287
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.4ms)[0m [1m[32mINSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key"[0m [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-11-11 21:42:07.182090"], ["updated_at", "2020-11-11 21:42:07.182090"]]
|
112288
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|