kithe 2.0.1 → 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/models → lib}/kithe/config_base.rb +6 -1
- data/lib/kithe/engine.rb +3 -0
- data/lib/kithe/indexable_settings.rb +1 -1
- data/lib/kithe/version.rb +1 -1
- data/spec/dummy/app/models/plain_active_record.rb +3 -0
- data/spec/dummy/config/database.yml +6 -0
- data/spec/dummy/log/development.log +746 -0
- data/spec/dummy/log/test.log +47311 -0
- data/spec/dummy/tmp/development_secret.txt +1 -1
- data/spec/indexing/indexable_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -20
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69743b96f34a0e3fcf7554d7c72e27dad32388a83db047911dba9ab8540e067
|
4
|
+
data.tar.gz: bf54b5bf9b74137ea06ca64dd67c18517423e85d8e83f785daca31919fb36111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9e2d903df8e7021a1ae6ae1f24e4e8c67d06e918feb6ff56e636b79775c269ec347786b0ba29e589d64f4c8d05c09a1d3302b18f018834649e523d099c592cc
|
7
|
+
data.tar.gz: 7b705aac817804994c1617871306a5d3f539a79ac8814e31d21651e0673a69ec2feae6052c59affa5009f3e07d9b4db0dae461f70ca86bf8adbd05528f6a5353
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Kithe
|
2
2
|
An experiment in shareable tools/components for building a digital collections app in Rails.
|
3
3
|
|
4
|
-
[![Build Status](https://
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/kithe.svg)](https://badge.fury.io/rb/kithe)
|
4
|
+
[![Build Status](https://github.com/sciencehistory/kithe/workflows/CI/badge.svg?branch=master)](https://github.com/sciencehistory/kithe/actions?query=workflow%3ACI+branch%3Amaster) [![Gem Version](https://badge.fury.io/rb/kithe.svg)](https://badge.fury.io/rb/kithe)
|
6
5
|
|
7
6
|
## What is kithe?
|
8
7
|
|
@@ -61,7 +60,7 @@ So you want to start an app that uses kithe. We should later provide better 'get
|
|
61
60
|
|
62
61
|
* Again re-iterate that kithe requires your Rails app use postgres, 9.5+.
|
63
62
|
|
64
|
-
* kithe
|
63
|
+
* kithe works with Rails 5.2 through 6.1.
|
65
64
|
|
66
65
|
* To install migrations from kithe to setup your database for it's models: `rake kithe_engine:install:migrations`
|
67
66
|
|
@@ -88,7 +87,8 @@ This is a Rails 'engine' whose template was created with: `rails plugin new kith
|
|
88
87
|
|
89
88
|
* Note we are currently using the standard rails-generated dummy app in spec/dummy for testing, rather than [engine_cart](https://github.com/cbeer/engine_cart) or [combustion](https://github.com/pat/combustion).
|
90
89
|
* Before you run the tests for the first time, create the database by running: `rails db:setup`. This will create two databases, kithe_development and kithe_test.
|
91
|
-
*
|
90
|
+
* Some of the rspec tests depend on [FFmpeg](https://ffmpeg.org/) for testing file derivative transformations. Mac users can install [ffmpeg via homebrew](https://formulae.brew.sh/formula/ffmpeg): `brew install ffmpeg`
|
91
|
+
* We do use [appraisal](https://github.com/thoughtbot/appraisal) to test under multiple rails versions, but still with the standard dummy app. It works for both Rails 5.2 and 6.0, because Rails structure changes have settled down.
|
92
92
|
* Locally you can run `bundle exec appraisal rspec` to run tests multiple times for each rails we have configured, or eg `bundle exec appraisal rails-60 rspec` for a particular one.
|
93
93
|
* If the project `Gemfile` _or_ `Appraisal` file changes, you may need to re-run `bundle exec appraisal install` and commit changes.
|
94
94
|
|
@@ -9,7 +9,7 @@ module Kithe
|
|
9
9
|
#
|
10
10
|
# You may also want to consider [railsconfig](https://github.com/railsconfig/config)
|
11
11
|
#
|
12
|
-
# Kithe::
|
12
|
+
# Kithe::ConfigBase:
|
13
13
|
#
|
14
14
|
# * uses an explicit declared list of allowable config keys, no silent typos
|
15
15
|
# * can read from a local YAML file or ENV, by default letting ENV override local YAML file values.
|
@@ -97,6 +97,11 @@ module Kithe
|
|
97
97
|
# This doesn't use any locking for concurrent initial loads, which is technically not
|
98
98
|
# great, but probably shouldn't be a problem in practice, especially in MRI. Trying to
|
99
99
|
# do proper locking with lazy load was too hard for me right now.
|
100
|
+
#
|
101
|
+
# ## Auto-loading
|
102
|
+
#
|
103
|
+
# This is intentionally NOT in an auto-loaded directory, so it can be used more
|
104
|
+
# easily in Rails initialization without problems. https://github.com/rails/rails/issues/40904
|
100
105
|
class ConfigBase
|
101
106
|
include Singleton
|
102
107
|
|
data/lib/kithe/engine.rb
CHANGED
@@ -8,7 +8,7 @@ module Kithe
|
|
8
8
|
@writer_class_name = writer_class_name
|
9
9
|
@writer_settings = writer_settings
|
10
10
|
@model_name_solr_field = model_name_solr_field
|
11
|
-
@solr_id_value_attribute = solr_id_value_attribute
|
11
|
+
@solr_id_value_attribute = solr_id_value_attribute || 'id'
|
12
12
|
end
|
13
13
|
|
14
14
|
# Use configured solr_url, and merge together with configured
|
data/lib/kithe/version.rb
CHANGED
@@ -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
|
@@ -111540,3 +111540,749 @@ FOREIGN KEY ("representative_id")
|
|
111540
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
111541
|
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
111542
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
|