kithe 2.0.0.pre.beta1 → 2.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfaa6ce3c41abdc0779014cb028d3ae7acbbfee6124eb24abca06f52e6f60c30
4
- data.tar.gz: 4f3951e52b4175c86933870933fd38c0c84dfcf11a5ad8cd18f1eb8c479305b0
3
+ metadata.gz: d13f653a81cc8db86b8dfb6539c9d2fc1148996467c3298ff60b6c89babb37a5
4
+ data.tar.gz: 937fec71314c5449f3c0c6a541089a21edad1113bccc29425e449f86d68c3347
5
5
  SHA512:
6
- metadata.gz: 6fe1836bde7b33a29d95324afe745ceeecb59ca95c8952775cce39dd8233c8daf171da971cc4a7bb2691e8dad2b91d50766c9232e3dce5b333da6f14d2f8d6bd
7
- data.tar.gz: de9bcd5fc0c22c18d9dde7ea9ec1bdc708e08035ee0f5d208131628d6d37bbc61574ae213b0ef69e6161c1fbdf334aad545c734614e10cee8f63f96666ed86dc
6
+ metadata.gz: 51e979ddd89d045300ecb1306403f9a42b096d3689321806c2d4101256c46f95340e02b03b97f8fd50233d25e59d60723dc31e21d7349fcc771b0b7476f6e666
7
+ data.tar.gz: 89126c403d797e24d9679a4206c4c09dab0f76d0642f01511bb7f07c501a27ee6d43da7c5e50c15b06bba47f3ec53b53657ee713c06d57f7ad28f2beee5ce8d0
@@ -1,5 +1,16 @@
1
1
  require 'shrine'
2
2
 
3
+ # Gem "F(x)" or `fx` gem will get schema.rb to include locally-defined custom postgres functions
4
+ # and triggers, like we use. So apps can keep using schema.rb instead of structure.sql,
5
+ # and still have our custom functions preserved. We need to require it explicitly
6
+ # since it'll be an indirect dependency of the end app.
7
+ #
8
+ # But we need to patch it to create functions first so we can use them as default values
9
+ # https://github.com/teoljungberg/fx/issues/33
10
+ # https://github.com/teoljungberg/fx/pull/53
11
+ require 'fx'
12
+ require 'kithe/patch_fx'
13
+
3
14
  module Kithe
4
15
  class Engine < ::Rails::Engine
5
16
  config.generators do |g|
@@ -8,8 +19,5 @@ module Kithe
8
19
  g.assets false
9
20
  g.helper false
10
21
  end
11
-
12
- # should only affect kithe development
13
- config.active_record.schema_format = :sql
14
22
  end
15
23
  end
@@ -0,0 +1,39 @@
1
+ # fx is a gem that lets Rails schema.rb capture postgres functions and triggers
2
+ #
3
+ # For it to work for our use case, we need it to define functions BEFORE tables when
4
+ # doing a `rake db:schema:load`, so we can refer to functions as default values in our
5
+ # tables.
6
+ #
7
+ # This is a known issue in fx, with a PR, but isn't yet merged/released, so we hack
8
+ # in a patch to force it. Better than forking.
9
+ #
10
+ # Based on: https://github.com/teoljungberg/fx/pull/53/
11
+ #
12
+ # We try to write future-compat code assuming that will be merged eventually....
13
+
14
+ require 'fx'
15
+
16
+ if Fx.configuration.respond_to?(:dump_functions_at_beginning_of_schema)
17
+ # we have the feature!
18
+
19
+ Fx.configure do |config|
20
+ config.dump_functions_at_beginning_of_schema = true
21
+ end
22
+
23
+ else
24
+ # Fx does not have the feature, we have to patch it in
25
+
26
+ require 'fx/schema_dumper/function'
27
+
28
+ module Fx
29
+ module SchemaDumper
30
+ module Function
31
+ def tables(stream)
32
+ functions(stream)
33
+ super
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -2,5 +2,5 @@ module Kithe
2
2
  # not sure why rubygems turned our alphas into 2.0.0.pre.alpha1, inserting
3
3
  # "pre". We need to do same thing with betas to get version orderings
4
4
  # appropriate.
5
- VERSION = '2.0.0.pre.beta1'
5
+ VERSION = '2.0.0.pre.rc1'
6
6
  end
@@ -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
@@ -109537,3 +109537,2006 @@ FOREIGN KEY ("representative_id")
109537
109537
   (0.1ms) BEGIN
109538
109538
  ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-20 21:22:55.854305"], ["updated_at", "2020-05-20 21:22:55.854305"]]
109539
109539
   (0.4ms) COMMIT
109540
+  (4.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109541
+  (6.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109542
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109543
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109544
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109545
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109546
+  (415.7ms) DROP DATABASE IF EXISTS "kithe_development"
109547
+  (199.9ms) DROP DATABASE IF EXISTS "kithe_test"
109548
+  (849.8ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109549
+  (615.6ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109550
+  (27.8ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109551
+  (5.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109552
+  (11.6ms) SELECT pg_try_advisory_lock(1601470156486188030)
109553
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109554
+ Migrating to EnablePgcryptoExtension (20181015143259)
109555
+  (0.6ms) BEGIN
109556
+ SQL (188.1ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109557
+ primary::SchemaMigration Create (4.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
109558
+  (24.5ms) COMMIT
109559
+ Migrating to CreateKitheModels (20181015143413)
109560
+  (0.8ms) BEGIN
109561
+  (24.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109562
+  (0.5ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
109563
+  (8.0ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109564
+  (17.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109565
+ FOREIGN KEY ("parent_id")
109566
+ REFERENCES "kithe_models" ("id")
109567
+ 
109568
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
109569
+  (0.5ms) COMMIT
109570
+ Migrating to KitheModelsFriendlierId (20181015143737)
109571
+  (0.3ms) BEGIN
109572
+  (42.9ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
109573
+ DECLARE
109574
+ new_id_int bigint;
109575
+ new_id_str character varying := '';
109576
+ done bool;
109577
+ tries integer;
109578
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109579
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109580
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109581
+ alphabet_length integer := array_length(alphabet, 1);
109582
+
109583
+ BEGIN
109584
+ done := false;
109585
+ tries := 0;
109586
+ WHILE (NOT done) LOOP
109587
+ tries := tries + 1;
109588
+ IF (tries > 3) THEN
109589
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109590
+ END IF;
109591
+
109592
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109593
+
109594
+ -- convert bigint to a Base-36 alphanumeric string
109595
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109596
+ -- https://gist.github.com/btbytes/7159902
109597
+ WHILE new_id_int != 0 LOOP
109598
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109599
+ new_id_int := new_id_int / alphabet_length;
109600
+ END LOOP;
109601
+
109602
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109603
+ END LOOP;
109604
+ RETURN new_id_str;
109605
+ END;
109606
+ $$ LANGUAGE plpgsql;
109607
+ 
109608
+  (43.1ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
109609
+  (14.4ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109610
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
109611
+  (30.0ms) COMMIT
109612
+ Migrating to AddFileDataToModel (20181031190647)
109613
+  (0.3ms) BEGIN
109614
+  (0.7ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
109615
+ primary::SchemaMigration Create (1.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
109616
+  (12.2ms) COMMIT
109617
+ Migrating to CreateKitheDerivatives (20181128185658)
109618
+  (0.2ms) BEGIN
109619
+  (91.1ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
109620
+ FOREIGN KEY ("asset_id")
109621
+ REFERENCES "kithe_models" ("id")
109622
+ )
109623
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109624
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109625
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
109626
+  (2.1ms) COMMIT
109627
+ Migrating to AddRepresentativeRelations (20190103144947)
109628
+  (12.0ms) BEGIN
109629
+  (1.3ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
109630
+  (7.7ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109631
+  (96.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109632
+ FOREIGN KEY ("representative_id")
109633
+ REFERENCES "kithe_models" ("id")
109634
+ 
109635
+  (0.9ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
109636
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109637
+  (3.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109638
+ FOREIGN KEY ("leaf_representative_id")
109639
+ REFERENCES "kithe_models" ("id")
109640
+ 
109641
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
109642
+  (6.3ms) COMMIT
109643
+ Migrating to ContainsAssociation (20190109192252)
109644
+  (0.3ms) BEGIN
109645
+  (7.3ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
109646
+ FOREIGN KEY ("containee_id")
109647
+ REFERENCES "kithe_models" ("id")
109648
+ , CONSTRAINT "fk_rails_091010187b"
109649
+ FOREIGN KEY ("container_id")
109650
+ REFERENCES "kithe_models" ("id")
109651
+ )
109652
+  (13.6ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109653
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109654
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
109655
+  (6.4ms) COMMIT
109656
+ Migrating to KitheModelType (20190404144551)
109657
+  (0.3ms) BEGIN
109658
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
109659
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
109660
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
109661
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
109662
+  (0.5ms) COMMIT
109663
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109664
+  (0.2ms) BEGIN
109665
+ ActiveRecord::InternalMetadata Create (0.8ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 15:56:52.813959"], ["updated_at", "2020-05-27 15:56:52.813959"]]
109666
+  (6.0ms) COMMIT
109667
+  (0.7ms) SELECT pg_advisory_unlock(1601470156486188030)
109668
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109669
+  (4.7ms)  SELECT
109670
+ pp.proname AS name,
109671
+ pg_get_functiondef(pp.oid) AS definition
109672
+ FROM pg_proc pp
109673
+ JOIN pg_namespace pn
109674
+ ON pn.oid = pp.pronamespace
109675
+ LEFT JOIN pg_depend pd
109676
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109677
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109678
+ ORDER BY pp.oid;
109679
+ 
109680
+  (1.5ms)  SELECT
109681
+ pt.tgname AS name,
109682
+ pg_get_triggerdef(pt.oid) AS definition
109683
+ FROM pg_trigger pt
109684
+ JOIN pg_class pc
109685
+ ON (pc.oid = pt.tgrelid)
109686
+ JOIN pg_proc pp
109687
+ ON (pp.oid = pt.tgfoid)
109688
+ WHERE pt.tgname
109689
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109690
+ ORDER BY pc.oid;
109691
+ 
109692
+  (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109693
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109694
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109695
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109696
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109697
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109698
+  (209.2ms) DROP DATABASE IF EXISTS "kithe_development"
109699
+  (238.3ms) DROP DATABASE IF EXISTS "kithe_test"
109700
+  (743.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109701
+  (452.5ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109702
+ SQL (22.5ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109703
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109704
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109705
+  (76.0ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109706
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109707
+  (1.1ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109708
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109709
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109710
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109711
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109712
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109713
+  (3.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109714
+  (222.1ms) DROP DATABASE IF EXISTS "kithe_development"
109715
+  (216.1ms) DROP DATABASE IF EXISTS "kithe_test"
109716
+  (1076.2ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109717
+  (619.8ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109718
+  (6.6ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109719
+  (27.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109720
+  (0.4ms) SELECT pg_try_advisory_lock(1601470156486188030)
109721
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109722
+ Migrating to EnablePgcryptoExtension (20181015143259)
109723
+  (0.4ms) BEGIN
109724
+ SQL (28.3ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109725
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
109726
+  (5.5ms) COMMIT
109727
+ Migrating to CreateKitheModels (20181015143413)
109728
+  (0.3ms) BEGIN
109729
+  (17.4ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109730
+  (0.5ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
109731
+  (7.0ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109732
+  (3.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109733
+ FOREIGN KEY ("parent_id")
109734
+ REFERENCES "kithe_models" ("id")
109735
+ 
109736
+ primary::SchemaMigration Create (2.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
109737
+  (1.9ms) COMMIT
109738
+ Migrating to KitheModelsFriendlierId (20181015143737)
109739
+  (0.3ms) BEGIN
109740
+  (4.5ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
109741
+ DECLARE
109742
+ new_id_int bigint;
109743
+ new_id_str character varying := '';
109744
+ done bool;
109745
+ tries integer;
109746
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109747
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109748
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109749
+ alphabet_length integer := array_length(alphabet, 1);
109750
+
109751
+ BEGIN
109752
+ done := false;
109753
+ tries := 0;
109754
+ WHILE (NOT done) LOOP
109755
+ tries := tries + 1;
109756
+ IF (tries > 3) THEN
109757
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109758
+ END IF;
109759
+
109760
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109761
+
109762
+ -- convert bigint to a Base-36 alphanumeric string
109763
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109764
+ -- https://gist.github.com/btbytes/7159902
109765
+ WHILE new_id_int != 0 LOOP
109766
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109767
+ new_id_int := new_id_int / alphabet_length;
109768
+ END LOOP;
109769
+
109770
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109771
+ END LOOP;
109772
+ RETURN new_id_str;
109773
+ END;
109774
+ $$ LANGUAGE plpgsql;
109775
+ 
109776
+  (41.5ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
109777
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109778
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
109779
+  (1.2ms) COMMIT
109780
+ Migrating to AddFileDataToModel (20181031190647)
109781
+  (0.9ms) BEGIN
109782
+  (0.6ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
109783
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
109784
+  (5.4ms) COMMIT
109785
+ Migrating to CreateKitheDerivatives (20181128185658)
109786
+  (0.2ms) BEGIN
109787
+  (26.1ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
109788
+ FOREIGN KEY ("asset_id")
109789
+ REFERENCES "kithe_models" ("id")
109790
+ )
109791
+  (9.1ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109792
+  (1.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109793
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
109794
+  (0.6ms) COMMIT
109795
+ Migrating to AddRepresentativeRelations (20190103144947)
109796
+  (6.4ms) BEGIN
109797
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
109798
+  (7.1ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109799
+  (4.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109800
+ FOREIGN KEY ("representative_id")
109801
+ REFERENCES "kithe_models" ("id")
109802
+ 
109803
+  (0.6ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
109804
+  (7.0ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109805
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109806
+ FOREIGN KEY ("leaf_representative_id")
109807
+ REFERENCES "kithe_models" ("id")
109808
+ 
109809
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
109810
+  (13.6ms) COMMIT
109811
+ Migrating to ContainsAssociation (20190109192252)
109812
+  (0.3ms) BEGIN
109813
+  (3.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
109814
+ FOREIGN KEY ("containee_id")
109815
+ REFERENCES "kithe_models" ("id")
109816
+ , CONSTRAINT "fk_rails_091010187b"
109817
+ FOREIGN KEY ("container_id")
109818
+ REFERENCES "kithe_models" ("id")
109819
+ )
109820
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109821
+  (137.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109822
+ primary::SchemaMigration Create (0.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
109823
+  (0.6ms) COMMIT
109824
+ Migrating to KitheModelType (20190404144551)
109825
+  (0.7ms) BEGIN
109826
+  (1.6ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
109827
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
109828
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
109829
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
109830
+  (15.6ms) COMMIT
109831
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109832
+  (0.2ms) BEGIN
109833
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:23.911025"], ["updated_at", "2020-05-27 16:05:23.911025"]]
109834
+  (18.0ms) COMMIT
109835
+  (0.8ms) SELECT pg_advisory_unlock(1601470156486188030)
109836
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109837
+  (5.4ms)  SELECT
109838
+ pp.proname AS name,
109839
+ pg_get_functiondef(pp.oid) AS definition
109840
+ FROM pg_proc pp
109841
+ JOIN pg_namespace pn
109842
+ ON pn.oid = pp.pronamespace
109843
+ LEFT JOIN pg_depend pd
109844
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
109845
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
109846
+ ORDER BY pp.oid;
109847
+ 
109848
+  (1.5ms)  SELECT
109849
+ pt.tgname AS name,
109850
+ pg_get_triggerdef(pt.oid) AS definition
109851
+ FROM pg_trigger pt
109852
+ JOIN pg_class pc
109853
+ ON (pc.oid = pt.tgrelid)
109854
+ JOIN pg_proc pp
109855
+ ON (pp.oid = pt.tgfoid)
109856
+ WHERE pt.tgname
109857
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
109858
+ ORDER BY pc.oid;
109859
+ 
109860
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109861
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109862
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109863
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109864
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109865
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
109866
+  (281.6ms) DROP DATABASE IF EXISTS "kithe_development"
109867
+  (206.0ms) DROP DATABASE IF EXISTS "kithe_test"
109868
+  (430.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
109869
+  (507.9ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
109870
+ SQL (44.1ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109871
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109872
+  (2.2ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109873
+ RETURNS text
109874
+ LANGUAGE plpgsql
109875
+ AS $function$
109876
+ DECLARE
109877
+ new_id_int bigint;
109878
+ new_id_str character varying := '';
109879
+ done bool;
109880
+ tries integer;
109881
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109882
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109883
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109884
+ alphabet_length integer := array_length(alphabet, 1);
109885
+
109886
+ BEGIN
109887
+ done := false;
109888
+ tries := 0;
109889
+ WHILE (NOT done) LOOP
109890
+ tries := tries + 1;
109891
+ IF (tries > 3) THEN
109892
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109893
+ END IF;
109894
+
109895
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109896
+
109897
+ -- convert bigint to a Base-36 alphanumeric string
109898
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
109899
+ -- https://gist.github.com/btbytes/7159902
109900
+ WHILE new_id_int != 0 LOOP
109901
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
109902
+ new_id_int := new_id_int / alphabet_length;
109903
+ END LOOP;
109904
+
109905
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
109906
+ END LOOP;
109907
+ RETURN new_id_str;
109908
+ END;
109909
+ $function$
109910
+ 
109911
+  (0.4ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
109912
+  (8.6ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
109913
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
109914
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
109915
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
109916
+  (1.8ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
109917
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
109918
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
109919
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
109920
+  (3.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
109921
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
109922
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
109923
+  (1.5ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
109924
+  (1.7ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
109925
+  (4.7ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
109926
+ FOREIGN KEY ("asset_id")
109927
+ REFERENCES "kithe_models" ("id")
109928
+ 
109929
+  (4.2ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
109930
+ FOREIGN KEY ("containee_id")
109931
+ REFERENCES "kithe_models" ("id")
109932
+ 
109933
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
109934
+ FOREIGN KEY ("container_id")
109935
+ REFERENCES "kithe_models" ("id")
109936
+ 
109937
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
109938
+ FOREIGN KEY ("leaf_representative_id")
109939
+ REFERENCES "kithe_models" ("id")
109940
+ 
109941
+  (2.2ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
109942
+ FOREIGN KEY ("parent_id")
109943
+ REFERENCES "kithe_models" ("id")
109944
+ 
109945
+  (2.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
109946
+ FOREIGN KEY ("representative_id")
109947
+ REFERENCES "kithe_models" ("id")
109948
+ 
109949
+  (3.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
109950
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
109951
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
109952
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES
109953
+ (20181015143259),
109954
+ (20181015143413),
109955
+ (20181015143737),
109956
+ (20181031190647),
109957
+ (20181128185658),
109958
+ (20190103144947),
109959
+ (20190109192252);
109960
+
109961
+ 
109962
+  (3.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
109963
+ ActiveRecord::InternalMetadata Load (2.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109964
+  (0.2ms) BEGIN
109965
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:36.100092"], ["updated_at", "2020-05-27 16:05:36.100092"]]
109966
+  (6.3ms) COMMIT
109967
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
109968
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
109969
+  (0.1ms) BEGIN
109970
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:05:36.114811"], ["updated_at", "2020-05-27 16:05:36.114811"]]
109971
+  (5.0ms) COMMIT
109972
+ SQL (43.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
109973
+ SQL (0.9ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
109974
+  (2.4ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
109975
+ RETURNS text
109976
+ LANGUAGE plpgsql
109977
+ AS $function$
109978
+ DECLARE
109979
+ new_id_int bigint;
109980
+ new_id_str character varying := '';
109981
+ done bool;
109982
+ tries integer;
109983
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
109984
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
109985
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
109986
+ alphabet_length integer := array_length(alphabet, 1);
109987
+
109988
+ BEGIN
109989
+ done := false;
109990
+ tries := 0;
109991
+ WHILE (NOT done) LOOP
109992
+ tries := tries + 1;
109993
+ IF (tries > 3) THEN
109994
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
109995
+ END IF;
109996
+
109997
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
109998
+
109999
+ -- convert bigint to a Base-36 alphanumeric string
110000
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110001
+ -- https://gist.github.com/btbytes/7159902
110002
+ WHILE new_id_int != 0 LOOP
110003
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110004
+ new_id_int := new_id_int / alphabet_length;
110005
+ END LOOP;
110006
+
110007
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110008
+ END LOOP;
110009
+ RETURN new_id_str;
110010
+ END;
110011
+ $function$
110012
+ 
110013
+  (1.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110014
+  (27.4ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110015
+  (2.0ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110016
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110017
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110018
+  (3.5ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110019
+  (2.0ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110020
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110021
+  (0.5ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110022
+  (8.2ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110023
+  (1.4ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110024
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110025
+  (1.4ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110026
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110027
+  (15.7ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110028
+ FOREIGN KEY ("asset_id")
110029
+ REFERENCES "kithe_models" ("id")
110030
+ 
110031
+  (2.2ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110032
+ FOREIGN KEY ("containee_id")
110033
+ REFERENCES "kithe_models" ("id")
110034
+ 
110035
+  (3.1ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110036
+ FOREIGN KEY ("container_id")
110037
+ REFERENCES "kithe_models" ("id")
110038
+ 
110039
+  (3.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110040
+ FOREIGN KEY ("leaf_representative_id")
110041
+ REFERENCES "kithe_models" ("id")
110042
+ 
110043
+  (3.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110044
+ FOREIGN KEY ("parent_id")
110045
+ REFERENCES "kithe_models" ("id")
110046
+ 
110047
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110048
+ FOREIGN KEY ("representative_id")
110049
+ REFERENCES "kithe_models" ("id")
110050
+ 
110051
+  (3.2ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110052
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110053
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
110054
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
110055
+ (20181015143259),
110056
+ (20181015143413),
110057
+ (20181015143737),
110058
+ (20181031190647),
110059
+ (20181128185658),
110060
+ (20190103144947),
110061
+ (20190109192252);
110062
+
110063
+ 
110064
+  (3.5ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110065
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110066
+  (0.2ms) BEGIN
110067
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:05:36.379857"], ["updated_at", "2020-05-27 16:05:36.379857"]]
110068
+  (0.4ms) COMMIT
110069
+ ActiveRecord::InternalMetadata Load (0.7ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110070
+  (0.3ms) BEGIN
110071
+ ActiveRecord::InternalMetadata Update (1.3ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:05:36.388452"], ["key", "environment"]]
110072
+  (0.6ms) COMMIT
110073
+ ActiveRecord::InternalMetadata Load (0.7ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110074
+  (0.2ms) BEGIN
110075
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:05:36.399100"], ["updated_at", "2020-05-27 16:05:36.399100"]]
110076
+  (0.4ms) COMMIT
110077
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110078
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110079
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110080
+  (0.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110081
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110082
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110083
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110084
+ SQL (0.8ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110085
+  (3.0ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110086
+ RETURNS text
110087
+ LANGUAGE plpgsql
110088
+ AS $function$
110089
+ DECLARE
110090
+ new_id_int bigint;
110091
+ new_id_str character varying := '';
110092
+ done bool;
110093
+ tries integer;
110094
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110095
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110096
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110097
+ alphabet_length integer := array_length(alphabet, 1);
110098
+
110099
+ BEGIN
110100
+ done := false;
110101
+ tries := 0;
110102
+ WHILE (NOT done) LOOP
110103
+ tries := tries + 1;
110104
+ IF (tries > 3) THEN
110105
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110106
+ END IF;
110107
+
110108
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110109
+
110110
+ -- convert bigint to a Base-36 alphanumeric string
110111
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110112
+ -- https://gist.github.com/btbytes/7159902
110113
+ WHILE new_id_int != 0 LOOP
110114
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110115
+ new_id_int := new_id_int / alphabet_length;
110116
+ END LOOP;
110117
+
110118
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110119
+ END LOOP;
110120
+ RETURN new_id_str;
110121
+ END;
110122
+ $function$
110123
+ 
110124
+  (6.9ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110125
+  (6.6ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110126
+  (2.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110127
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110128
+  (2.9ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110129
+  (1.5ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110130
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110131
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110132
+  (4.0ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110133
+  (4.1ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110134
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110135
+  (1.7ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110136
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110137
+  (3.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110138
+  (15.9ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110139
+ FOREIGN KEY ("asset_id")
110140
+ REFERENCES "kithe_models" ("id")
110141
+ 
110142
+  (4.6ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110143
+ FOREIGN KEY ("containee_id")
110144
+ REFERENCES "kithe_models" ("id")
110145
+ 
110146
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110147
+ FOREIGN KEY ("container_id")
110148
+ REFERENCES "kithe_models" ("id")
110149
+ 
110150
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110151
+ FOREIGN KEY ("leaf_representative_id")
110152
+ REFERENCES "kithe_models" ("id")
110153
+ 
110154
+  (3.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110155
+ FOREIGN KEY ("parent_id")
110156
+ REFERENCES "kithe_models" ("id")
110157
+ 
110158
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110159
+ FOREIGN KEY ("representative_id")
110160
+ REFERENCES "kithe_models" ("id")
110161
+ 
110162
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110163
+ ActiveRecord::InternalMetadata Load (1.0ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110164
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110165
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110166
+ SQL (0.6ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110167
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110168
+  (9.8ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110169
+ RETURNS text
110170
+ LANGUAGE plpgsql
110171
+ AS $function$
110172
+ DECLARE
110173
+ new_id_int bigint;
110174
+ new_id_str character varying := '';
110175
+ done bool;
110176
+ tries integer;
110177
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110178
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110179
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110180
+ alphabet_length integer := array_length(alphabet, 1);
110181
+
110182
+ BEGIN
110183
+ done := false;
110184
+ tries := 0;
110185
+ WHILE (NOT done) LOOP
110186
+ tries := tries + 1;
110187
+ IF (tries > 3) THEN
110188
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110189
+ END IF;
110190
+
110191
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110192
+
110193
+ -- convert bigint to a Base-36 alphanumeric string
110194
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110195
+ -- https://gist.github.com/btbytes/7159902
110196
+ WHILE new_id_int != 0 LOOP
110197
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110198
+ new_id_int := new_id_int / alphabet_length;
110199
+ END LOOP;
110200
+
110201
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110202
+ END LOOP;
110203
+ RETURN new_id_str;
110204
+ END;
110205
+ $function$
110206
+ 
110207
+  (23.1ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110208
+  (43.6ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110209
+  (16.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110210
+  (21.5ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110211
+  (3.4ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110212
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110213
+  (1.4ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110214
+  (2.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110215
+  (6.6ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110216
+  (6.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110217
+  (1.4ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110218
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110219
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110220
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110221
+  (4.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110222
+ FOREIGN KEY ("asset_id")
110223
+ REFERENCES "kithe_models" ("id")
110224
+ 
110225
+  (3.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110226
+ FOREIGN KEY ("containee_id")
110227
+ REFERENCES "kithe_models" ("id")
110228
+ 
110229
+  (2.3ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110230
+ FOREIGN KEY ("container_id")
110231
+ REFERENCES "kithe_models" ("id")
110232
+ 
110233
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110234
+ FOREIGN KEY ("leaf_representative_id")
110235
+ REFERENCES "kithe_models" ("id")
110236
+ 
110237
+  (4.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110238
+ FOREIGN KEY ("parent_id")
110239
+ REFERENCES "kithe_models" ("id")
110240
+ 
110241
+  (3.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110242
+ FOREIGN KEY ("representative_id")
110243
+ REFERENCES "kithe_models" ("id")
110244
+ 
110245
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110246
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110247
+  (0.2ms) BEGIN
110248
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "development"], ["updated_at", "2020-05-27 16:05:50.059067"], ["key", "environment"]]
110249
+  (0.4ms) COMMIT
110250
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110251
+  (0.2ms) BEGIN
110252
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:05:50.071778"], ["key", "environment"]]
110253
+  (0.4ms) COMMIT
110254
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110255
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110256
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110257
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110258
+  (0.8ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110259
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110260
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110261
+  (215.0ms) DROP DATABASE IF EXISTS "kithe_development"
110262
+  (247.1ms) DROP DATABASE IF EXISTS "kithe_test"
110263
+  (572.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110264
+  (498.2ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110265
+  (15.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110266
+  (26.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110267
+  (0.8ms) SELECT pg_try_advisory_lock(1601470156486188030)
110268
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110269
+ Migrating to EnablePgcryptoExtension (20181015143259)
110270
+  (0.7ms) BEGIN
110271
+ SQL (29.6ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110272
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110273
+  (1.1ms) COMMIT
110274
+ Migrating to CreateKitheModels (20181015143413)
110275
+  (0.2ms) BEGIN
110276
+  (21.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110277
+  (0.4ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110278
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110279
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110280
+ FOREIGN KEY ("parent_id")
110281
+ REFERENCES "kithe_models" ("id")
110282
+ 
110283
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110284
+  (0.4ms) COMMIT
110285
+ Migrating to KitheModelsFriendlierId (20181015143737)
110286
+  (0.3ms) BEGIN
110287
+  (6.8ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110288
+ DECLARE
110289
+ new_id_int bigint;
110290
+ new_id_str character varying := '';
110291
+ done bool;
110292
+ tries integer;
110293
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110294
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110295
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110296
+ alphabet_length integer := array_length(alphabet, 1);
110297
+
110298
+ BEGIN
110299
+ done := false;
110300
+ tries := 0;
110301
+ WHILE (NOT done) LOOP
110302
+ tries := tries + 1;
110303
+ IF (tries > 3) THEN
110304
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110305
+ END IF;
110306
+
110307
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110308
+
110309
+ -- convert bigint to a Base-36 alphanumeric string
110310
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110311
+ -- https://gist.github.com/btbytes/7159902
110312
+ WHILE new_id_int != 0 LOOP
110313
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110314
+ new_id_int := new_id_int / alphabet_length;
110315
+ END LOOP;
110316
+
110317
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110318
+ END LOOP;
110319
+ RETURN new_id_str;
110320
+ END;
110321
+ $$ LANGUAGE plpgsql;
110322
+ 
110323
+  (25.2ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110324
+  (2.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110325
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110326
+  (1.3ms) COMMIT
110327
+ Migrating to AddFileDataToModel (20181031190647)
110328
+  (0.3ms) BEGIN
110329
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
110330
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
110331
+  (6.1ms) COMMIT
110332
+ Migrating to CreateKitheDerivatives (20181128185658)
110333
+  (0.7ms) BEGIN
110334
+  (17.2ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
110335
+ FOREIGN KEY ("asset_id")
110336
+ REFERENCES "kithe_models" ("id")
110337
+ )
110338
+  (5.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110339
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110340
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
110341
+  (0.4ms) COMMIT
110342
+ Migrating to AddRepresentativeRelations (20190103144947)
110343
+  (6.0ms) BEGIN
110344
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
110345
+  (13.1ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110346
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110347
+ FOREIGN KEY ("representative_id")
110348
+ REFERENCES "kithe_models" ("id")
110349
+ 
110350
+  (0.5ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
110351
+  (1.1ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110352
+  (1.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110353
+ FOREIGN KEY ("leaf_representative_id")
110354
+ REFERENCES "kithe_models" ("id")
110355
+ 
110356
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
110357
+  (0.9ms) COMMIT
110358
+ Migrating to ContainsAssociation (20190109192252)
110359
+  (0.3ms) BEGIN
110360
+  (2.1ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
110361
+ FOREIGN KEY ("containee_id")
110362
+ REFERENCES "kithe_models" ("id")
110363
+ , CONSTRAINT "fk_rails_091010187b"
110364
+ FOREIGN KEY ("container_id")
110365
+ REFERENCES "kithe_models" ("id")
110366
+ )
110367
+  (7.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110368
+  (7.7ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110369
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
110370
+  (0.4ms) COMMIT
110371
+ Migrating to KitheModelType (20190404144551)
110372
+  (0.2ms) BEGIN
110373
+  (0.5ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
110374
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
110375
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
110376
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
110377
+  (6.4ms) COMMIT
110378
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110379
+  (0.2ms) BEGIN
110380
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:23.265055"], ["updated_at", "2020-05-27 16:15:23.265055"]]
110381
+  (0.4ms) COMMIT
110382
+  (0.5ms) SELECT pg_advisory_unlock(1601470156486188030)
110383
+  (1.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110384
+  (4.8ms)  SELECT
110385
+ pp.proname AS name,
110386
+ pg_get_functiondef(pp.oid) AS definition
110387
+ FROM pg_proc pp
110388
+ JOIN pg_namespace pn
110389
+ ON pn.oid = pp.pronamespace
110390
+ LEFT JOIN pg_depend pd
110391
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
110392
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
110393
+ ORDER BY pp.oid;
110394
+ 
110395
+  (1.5ms)  SELECT
110396
+ pt.tgname AS name,
110397
+ pg_get_triggerdef(pt.oid) AS definition
110398
+ FROM pg_trigger pt
110399
+ JOIN pg_class pc
110400
+ ON (pc.oid = pt.tgrelid)
110401
+ JOIN pg_proc pp
110402
+ ON (pp.oid = pt.tgfoid)
110403
+ WHERE pt.tgname
110404
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
110405
+ ORDER BY pc.oid;
110406
+ 
110407
+  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110408
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110409
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110410
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110411
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110412
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110413
+  (207.6ms) DROP DATABASE IF EXISTS "kithe_development"
110414
+  (204.7ms) DROP DATABASE IF EXISTS "kithe_test"
110415
+  (434.7ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110416
+  (556.2ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110417
+ SQL (13.4ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110418
+ SQL (0.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110419
+  (2.7ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110420
+ RETURNS text
110421
+ LANGUAGE plpgsql
110422
+ AS $function$
110423
+ DECLARE
110424
+ new_id_int bigint;
110425
+ new_id_str character varying := '';
110426
+ done bool;
110427
+ tries integer;
110428
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110429
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110430
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110431
+ alphabet_length integer := array_length(alphabet, 1);
110432
+
110433
+ BEGIN
110434
+ done := false;
110435
+ tries := 0;
110436
+ WHILE (NOT done) LOOP
110437
+ tries := tries + 1;
110438
+ IF (tries > 3) THEN
110439
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110440
+ END IF;
110441
+
110442
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110443
+
110444
+ -- convert bigint to a Base-36 alphanumeric string
110445
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110446
+ -- https://gist.github.com/btbytes/7159902
110447
+ WHILE new_id_int != 0 LOOP
110448
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110449
+ new_id_int := new_id_int / alphabet_length;
110450
+ END LOOP;
110451
+
110452
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110453
+ END LOOP;
110454
+ RETURN new_id_str;
110455
+ END;
110456
+ $function$
110457
+ 
110458
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110459
+  (7.5ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110460
+  (1.8ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110461
+  (1.2ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110462
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110463
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110464
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110465
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110466
+  (0.4ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110467
+  (7.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110468
+  (2.5ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110469
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110470
+  (1.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110471
+  (1.9ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110472
+  (3.3ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110473
+ FOREIGN KEY ("asset_id")
110474
+ REFERENCES "kithe_models" ("id")
110475
+ 
110476
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110477
+ FOREIGN KEY ("containee_id")
110478
+ REFERENCES "kithe_models" ("id")
110479
+ 
110480
+  (2.1ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110481
+ FOREIGN KEY ("container_id")
110482
+ REFERENCES "kithe_models" ("id")
110483
+ 
110484
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110485
+ FOREIGN KEY ("leaf_representative_id")
110486
+ REFERENCES "kithe_models" ("id")
110487
+ 
110488
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110489
+ FOREIGN KEY ("parent_id")
110490
+ REFERENCES "kithe_models" ("id")
110491
+ 
110492
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110493
+ FOREIGN KEY ("representative_id")
110494
+ REFERENCES "kithe_models" ("id")
110495
+ 
110496
+  (6.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110497
+  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110498
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
110499
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES
110500
+ (20181015143259),
110501
+ (20181015143413),
110502
+ (20181015143737),
110503
+ (20181031190647),
110504
+ (20181128185658),
110505
+ (20190103144947),
110506
+ (20190109192252);
110507
+
110508
+ 
110509
+  (3.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110510
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110511
+  (0.2ms) BEGIN
110512
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:41.046597"], ["updated_at", "2020-05-27 16:15:41.046597"]]
110513
+  (0.4ms) COMMIT
110514
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110515
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110516
+  (0.2ms) BEGIN
110517
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:15:41.055003"], ["updated_at", "2020-05-27 16:15:41.055003"]]
110518
+  (0.4ms) COMMIT
110519
+ SQL (17.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110520
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
110521
+  (9.5ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
110522
+ RETURNS text
110523
+ LANGUAGE plpgsql
110524
+ AS $function$
110525
+ DECLARE
110526
+ new_id_int bigint;
110527
+ new_id_str character varying := '';
110528
+ done bool;
110529
+ tries integer;
110530
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110531
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110532
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110533
+ alphabet_length integer := array_length(alphabet, 1);
110534
+
110535
+ BEGIN
110536
+ done := false;
110537
+ tries := 0;
110538
+ WHILE (NOT done) LOOP
110539
+ tries := tries + 1;
110540
+ IF (tries > 3) THEN
110541
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110542
+ END IF;
110543
+
110544
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110545
+
110546
+ -- convert bigint to a Base-36 alphanumeric string
110547
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110548
+ -- https://gist.github.com/btbytes/7159902
110549
+ WHILE new_id_int != 0 LOOP
110550
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110551
+ new_id_int := new_id_int / alphabet_length;
110552
+ END LOOP;
110553
+
110554
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110555
+ END LOOP;
110556
+ RETURN new_id_str;
110557
+ END;
110558
+ $function$
110559
+ 
110560
+  (0.5ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
110561
+  (8.3ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110562
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110563
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110564
+  (0.3ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
110565
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
110566
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110567
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110568
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
110569
+  (6.3ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
110570
+  (2.7ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110571
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110572
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110573
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110574
+  (3.6ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
110575
+ FOREIGN KEY ("asset_id")
110576
+ REFERENCES "kithe_models" ("id")
110577
+ 
110578
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
110579
+ FOREIGN KEY ("containee_id")
110580
+ REFERENCES "kithe_models" ("id")
110581
+ 
110582
+  (1.7ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
110583
+ FOREIGN KEY ("container_id")
110584
+ REFERENCES "kithe_models" ("id")
110585
+ 
110586
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110587
+ FOREIGN KEY ("leaf_representative_id")
110588
+ REFERENCES "kithe_models" ("id")
110589
+ 
110590
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110591
+ FOREIGN KEY ("parent_id")
110592
+ REFERENCES "kithe_models" ("id")
110593
+ 
110594
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110595
+ FOREIGN KEY ("representative_id")
110596
+ REFERENCES "kithe_models" ("id")
110597
+ 
110598
+  (3.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110599
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110600
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
110601
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
110602
+ (20181015143259),
110603
+ (20181015143413),
110604
+ (20181015143737),
110605
+ (20181031190647),
110606
+ (20181128185658),
110607
+ (20190103144947),
110608
+ (20190109192252);
110609
+
110610
+ 
110611
+  (4.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110612
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110613
+  (0.2ms) BEGIN
110614
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:15:41.295599"], ["updated_at", "2020-05-27 16:15:41.295599"]]
110615
+  (0.9ms) COMMIT
110616
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110617
+  (0.2ms) BEGIN
110618
+ ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:15:41.302574"], ["key", "environment"]]
110619
+  (0.4ms) COMMIT
110620
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
110621
+  (0.2ms) BEGIN
110622
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-27 16:15:41.308393"], ["updated_at", "2020-05-27 16:15:41.308393"]]
110623
+  (0.4ms) COMMIT
110624
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110625
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110626
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110627
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110628
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110629
+  (0.7ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110630
+  (217.9ms) DROP DATABASE IF EXISTS "kithe_development"
110631
+  (219.9ms) DROP DATABASE IF EXISTS "kithe_test"
110632
+  (498.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110633
+  (549.0ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110634
+  (16.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110635
+  (111.0ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110636
+  (1.1ms) SELECT pg_try_advisory_lock(1601470156486188030)
110637
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110638
+ Migrating to EnablePgcryptoExtension (20181015143259)
110639
+  (0.2ms) BEGIN
110640
+ SQL (13.7ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110641
+ primary::SchemaMigration Create (20.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110642
+  (2.0ms) COMMIT
110643
+ Migrating to CreateKitheModels (20181015143413)
110644
+  (0.5ms) BEGIN
110645
+  (5.5ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110646
+  (0.6ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110647
+  (1.7ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110648
+  (4.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110649
+ FOREIGN KEY ("parent_id")
110650
+ REFERENCES "kithe_models" ("id")
110651
+ 
110652
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110653
+  (0.7ms) COMMIT
110654
+ Migrating to KitheModelsFriendlierId (20181015143737)
110655
+  (0.3ms) BEGIN
110656
+  (8.1ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110657
+ DECLARE
110658
+ new_id_int bigint;
110659
+ new_id_str character varying := '';
110660
+ done bool;
110661
+ tries integer;
110662
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110663
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110664
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110665
+ alphabet_length integer := array_length(alphabet, 1);
110666
+
110667
+ BEGIN
110668
+ done := false;
110669
+ tries := 0;
110670
+ WHILE (NOT done) LOOP
110671
+ tries := tries + 1;
110672
+ IF (tries > 3) THEN
110673
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110674
+ END IF;
110675
+
110676
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110677
+
110678
+ -- convert bigint to a Base-36 alphanumeric string
110679
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110680
+ -- https://gist.github.com/btbytes/7159902
110681
+ WHILE new_id_int != 0 LOOP
110682
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110683
+ new_id_int := new_id_int / alphabet_length;
110684
+ END LOOP;
110685
+
110686
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110687
+ END LOOP;
110688
+ RETURN new_id_str;
110689
+ END;
110690
+ $$ LANGUAGE plpgsql;
110691
+ 
110692
+  (5.6ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110693
+  (1.0ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110694
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110695
+  (1.1ms) COMMIT
110696
+ Migrating to AddFileDataToModel (20181031190647)
110697
+  (0.3ms) BEGIN
110698
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
110699
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
110700
+  (0.4ms) COMMIT
110701
+ Migrating to CreateKitheDerivatives (20181128185658)
110702
+  (0.3ms) BEGIN
110703
+  (7.2ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
110704
+ FOREIGN KEY ("asset_id")
110705
+ REFERENCES "kithe_models" ("id")
110706
+ )
110707
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110708
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110709
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
110710
+  (0.7ms) COMMIT
110711
+ Migrating to AddRepresentativeRelations (20190103144947)
110712
+  (3.1ms) BEGIN
110713
+  (1.3ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
110714
+  (1.4ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110715
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110716
+ FOREIGN KEY ("representative_id")
110717
+ REFERENCES "kithe_models" ("id")
110718
+ 
110719
+  (0.5ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
110720
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110721
+  (3.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110722
+ FOREIGN KEY ("leaf_representative_id")
110723
+ REFERENCES "kithe_models" ("id")
110724
+ 
110725
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
110726
+  (5.4ms) COMMIT
110727
+ Migrating to ContainsAssociation (20190109192252)
110728
+  (0.2ms) BEGIN
110729
+  (2.3ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
110730
+ FOREIGN KEY ("containee_id")
110731
+ REFERENCES "kithe_models" ("id")
110732
+ , CONSTRAINT "fk_rails_091010187b"
110733
+ FOREIGN KEY ("container_id")
110734
+ REFERENCES "kithe_models" ("id")
110735
+ )
110736
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110737
+  (1.2ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110738
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
110739
+  (0.4ms) COMMIT
110740
+ Migrating to KitheModelType (20190404144551)
110741
+  (0.2ms) BEGIN
110742
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
110743
+  (0.6ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
110744
+  (0.5ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
110745
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
110746
+  (0.7ms) COMMIT
110747
+ ActiveRecord::InternalMetadata Load (1.0ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110748
+  (0.1ms) BEGIN
110749
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:16:55.002081"], ["updated_at", "2020-05-27 16:16:55.002081"]]
110750
+  (0.4ms) COMMIT
110751
+  (0.5ms) SELECT pg_advisory_unlock(1601470156486188030)
110752
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110753
+  (5.2ms)  SELECT
110754
+ pp.proname AS name,
110755
+ pg_get_functiondef(pp.oid) AS definition
110756
+ FROM pg_proc pp
110757
+ JOIN pg_namespace pn
110758
+ ON pn.oid = pp.pronamespace
110759
+ LEFT JOIN pg_depend pd
110760
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
110761
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
110762
+ ORDER BY pp.oid;
110763
+ 
110764
+  (2.2ms)  SELECT
110765
+ pt.tgname AS name,
110766
+ pg_get_triggerdef(pt.oid) AS definition
110767
+ FROM pg_trigger pt
110768
+ JOIN pg_class pc
110769
+ ON (pc.oid = pt.tgrelid)
110770
+ JOIN pg_proc pp
110771
+ ON (pp.oid = pt.tgfoid)
110772
+ WHERE pt.tgname
110773
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
110774
+ ORDER BY pc.oid;
110775
+ 
110776
+  (1.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110777
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110778
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110779
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110780
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110781
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110782
+  (205.7ms) DROP DATABASE IF EXISTS "kithe_development"
110783
+  (212.8ms) DROP DATABASE IF EXISTS "kithe_test"
110784
+  (538.0ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110785
+  (495.1ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110786
+  (54.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110787
+  (5.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110788
+  (0.4ms) SELECT pg_try_advisory_lock(1601470156486188030)
110789
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110790
+ Migrating to EnablePgcryptoExtension (20181015143259)
110791
+  (0.3ms) BEGIN
110792
+ SQL (21.7ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110793
+ primary::SchemaMigration Create (1.7ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110794
+  (2.1ms) COMMIT
110795
+ Migrating to CreateKitheModels (20181015143413)
110796
+  (0.2ms) BEGIN
110797
+  (4.0ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110798
+  (0.8ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110799
+  (1.4ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110800
+  (2.5ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110801
+ FOREIGN KEY ("parent_id")
110802
+ REFERENCES "kithe_models" ("id")
110803
+ 
110804
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110805
+  (0.4ms) COMMIT
110806
+ Migrating to KitheModelsFriendlierId (20181015143737)
110807
+  (0.4ms) BEGIN
110808
+  (7.4ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110809
+ DECLARE
110810
+ new_id_int bigint;
110811
+ new_id_str character varying := '';
110812
+ done bool;
110813
+ tries integer;
110814
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110815
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110816
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110817
+ alphabet_length integer := array_length(alphabet, 1);
110818
+
110819
+ BEGIN
110820
+ done := false;
110821
+ tries := 0;
110822
+ WHILE (NOT done) LOOP
110823
+ tries := tries + 1;
110824
+ IF (tries > 3) THEN
110825
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110826
+ END IF;
110827
+
110828
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110829
+
110830
+ -- convert bigint to a Base-36 alphanumeric string
110831
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110832
+ -- https://gist.github.com/btbytes/7159902
110833
+ WHILE new_id_int != 0 LOOP
110834
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110835
+ new_id_int := new_id_int / alphabet_length;
110836
+ END LOOP;
110837
+
110838
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110839
+ END LOOP;
110840
+ RETURN new_id_str;
110841
+ END;
110842
+ $$ LANGUAGE plpgsql;
110843
+ 
110844
+  (20.1ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110845
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110846
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110847
+  (1.4ms) COMMIT
110848
+ Migrating to AddFileDataToModel (20181031190647)
110849
+  (0.3ms) BEGIN
110850
+  (0.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
110851
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
110852
+  (0.4ms) COMMIT
110853
+ Migrating to CreateKitheDerivatives (20181128185658)
110854
+  (0.2ms) BEGIN
110855
+  (8.1ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
110856
+ FOREIGN KEY ("asset_id")
110857
+ REFERENCES "kithe_models" ("id")
110858
+ )
110859
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
110860
+  (1.4ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
110861
+ primary::SchemaMigration Create (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
110862
+  (0.5ms) COMMIT
110863
+ Migrating to AddRepresentativeRelations (20190103144947)
110864
+  (6.4ms) BEGIN
110865
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
110866
+  (7.5ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
110867
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
110868
+ FOREIGN KEY ("representative_id")
110869
+ REFERENCES "kithe_models" ("id")
110870
+ 
110871
+  (0.4ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
110872
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
110873
+  (1.6ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
110874
+ FOREIGN KEY ("leaf_representative_id")
110875
+ REFERENCES "kithe_models" ("id")
110876
+ 
110877
+ primary::SchemaMigration Create (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
110878
+  (0.4ms) COMMIT
110879
+ Migrating to ContainsAssociation (20190109192252)
110880
+  (0.3ms) BEGIN
110881
+  (2.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
110882
+ FOREIGN KEY ("containee_id")
110883
+ REFERENCES "kithe_models" ("id")
110884
+ , CONSTRAINT "fk_rails_091010187b"
110885
+ FOREIGN KEY ("container_id")
110886
+ REFERENCES "kithe_models" ("id")
110887
+ )
110888
+  (1.7ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
110889
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
110890
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
110891
+  (0.4ms) COMMIT
110892
+ Migrating to KitheModelType (20190404144551)
110893
+  (0.2ms) BEGIN
110894
+  (0.4ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
110895
+  (0.5ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
110896
+  (0.6ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
110897
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
110898
+  (0.5ms) COMMIT
110899
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
110900
+  (0.2ms) BEGIN
110901
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:01.957849"], ["updated_at", "2020-05-27 16:19:01.957849"]]
110902
+  (0.4ms) COMMIT
110903
+  (0.7ms) SELECT pg_advisory_unlock(1601470156486188030)
110904
+  (2.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110905
+  (5.0ms)  SELECT
110906
+ pp.proname AS name,
110907
+ pg_get_functiondef(pp.oid) AS definition
110908
+ FROM pg_proc pp
110909
+ JOIN pg_namespace pn
110910
+ ON pn.oid = pp.pronamespace
110911
+ LEFT JOIN pg_depend pd
110912
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
110913
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
110914
+ ORDER BY pp.oid;
110915
+ 
110916
+  (1.8ms)  SELECT
110917
+ pt.tgname AS name,
110918
+ pg_get_triggerdef(pt.oid) AS definition
110919
+ FROM pg_trigger pt
110920
+ JOIN pg_class pc
110921
+ ON (pc.oid = pt.tgrelid)
110922
+ JOIN pg_proc pp
110923
+ ON (pp.oid = pt.tgfoid)
110924
+ WHERE pt.tgname
110925
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
110926
+ ORDER BY pc.oid;
110927
+ 
110928
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110929
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110930
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110931
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110932
+  (0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110933
+  (0.4ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
110934
+  (209.2ms) DROP DATABASE IF EXISTS "kithe_development"
110935
+  (206.0ms) DROP DATABASE IF EXISTS "kithe_test"
110936
+  (512.2ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
110937
+  (434.6ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
110938
+  (7.1ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
110939
+  (6.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
110940
+  (0.3ms) SELECT pg_try_advisory_lock(1601470156486188030)
110941
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
110942
+ Migrating to EnablePgcryptoExtension (20181015143259)
110943
+  (0.2ms) BEGIN
110944
+ SQL (17.0ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
110945
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143259"]]
110946
+  (1.4ms) COMMIT
110947
+ Migrating to CreateKitheModels (20181015143413)
110948
+  (0.2ms) BEGIN
110949
+  (4.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
110950
+  (0.6ms) ALTER TABLE "kithe_models" ADD "parent_id" uuid
110951
+  (16.7ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
110952
+  (7.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
110953
+ FOREIGN KEY ("parent_id")
110954
+ REFERENCES "kithe_models" ("id")
110955
+ 
110956
+ primary::SchemaMigration Create (82.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143413"]]
110957
+  (6.1ms) COMMIT
110958
+ Migrating to KitheModelsFriendlierId (20181015143737)
110959
+  (0.3ms) BEGIN
110960
+  (2.7ms) CREATE OR REPLACE FUNCTION kithe_models_friendlier_id_gen(min_value bigint, max_value bigint) RETURNS text AS $$
110961
+ DECLARE
110962
+ new_id_int bigint;
110963
+ new_id_str character varying := '';
110964
+ done bool;
110965
+ tries integer;
110966
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
110967
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
110968
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
110969
+ alphabet_length integer := array_length(alphabet, 1);
110970
+
110971
+ BEGIN
110972
+ done := false;
110973
+ tries := 0;
110974
+ WHILE (NOT done) LOOP
110975
+ tries := tries + 1;
110976
+ IF (tries > 3) THEN
110977
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
110978
+ END IF;
110979
+
110980
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
110981
+
110982
+ -- convert bigint to a Base-36 alphanumeric string
110983
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
110984
+ -- https://gist.github.com/btbytes/7159902
110985
+ WHILE new_id_int != 0 LOOP
110986
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
110987
+ new_id_int := new_id_int / alphabet_length;
110988
+ END LOOP;
110989
+
110990
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
110991
+ END LOOP;
110992
+ RETURN new_id_str;
110993
+ END;
110994
+ $$ LANGUAGE plpgsql;
110995
+ 
110996
+  (16.0ms) ALTER TABLE "kithe_models" ADD "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen(2821109907456, 101559956668415) NOT NULL
110997
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
110998
+ primary::SchemaMigration Create (1.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181015143737"]]
110999
+  (2.0ms) COMMIT
111000
+ Migrating to AddFileDataToModel (20181031190647)
111001
+  (1.1ms) BEGIN
111002
+  (1.4ms) ALTER TABLE "kithe_models" ADD "file_data" jsonb
111003
+ primary::SchemaMigration Create (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181031190647"]]
111004
+  (0.8ms) COMMIT
111005
+ Migrating to CreateKitheDerivatives (20181128185658)
111006
+  (1.9ms) BEGIN
111007
+  (7.2ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_3dac8b4201"
111008
+ FOREIGN KEY ("asset_id")
111009
+ REFERENCES "kithe_models" ("id")
111010
+ )
111011
+  (1.3ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111012
+  (1.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111013
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20181128185658"]]
111014
+  (0.5ms) COMMIT
111015
+ Migrating to AddRepresentativeRelations (20190103144947)
111016
+  (0.4ms) BEGIN
111017
+  (0.5ms) ALTER TABLE "kithe_models" ADD "representative_id" uuid
111018
+  (1.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111019
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111020
+ FOREIGN KEY ("representative_id")
111021
+ REFERENCES "kithe_models" ("id")
111022
+ 
111023
+  (0.7ms) ALTER TABLE "kithe_models" ADD "leaf_representative_id" uuid
111024
+  (3.9ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111025
+  (3.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111026
+ FOREIGN KEY ("leaf_representative_id")
111027
+ REFERENCES "kithe_models" ("id")
111028
+ 
111029
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190103144947"]]
111030
+  (0.5ms) COMMIT
111031
+ Migrating to ContainsAssociation (20190109192252)
111032
+  (0.3ms) BEGIN
111033
+  (2.0ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid, CONSTRAINT "fk_rails_490c1158f7"
111034
+ FOREIGN KEY ("containee_id")
111035
+ REFERENCES "kithe_models" ("id")
111036
+ , CONSTRAINT "fk_rails_091010187b"
111037
+ FOREIGN KEY ("container_id")
111038
+ REFERENCES "kithe_models" ("id")
111039
+ )
111040
+  (2.0ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111041
+  (1.0ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111042
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190109192252"]]
111043
+  (0.4ms) COMMIT
111044
+ Migrating to KitheModelType (20190404144551)
111045
+  (0.3ms) BEGIN
111046
+  (0.5ms) ALTER TABLE "kithe_models" ADD "kithe_model_type" integer
111047
+  (1.3ms) SELECT "kithe_models"."id" FROM "kithe_models" ORDER BY "kithe_models"."id" ASC LIMIT $1 [["LIMIT", 1000]]
111048
+  (0.9ms) ALTER TABLE "kithe_models" ALTER COLUMN "kithe_model_type" TYPE integer, ALTER COLUMN "kithe_model_type" SET NOT NULL
111049
+ primary::SchemaMigration Create (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190404144551"]]
111050
+  (0.4ms) COMMIT
111051
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111052
+  (0.2ms) BEGIN
111053
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:20.045824"], ["updated_at", "2020-05-27 16:19:20.045824"]]
111054
+  (0.8ms) COMMIT
111055
+  (0.5ms) SELECT pg_advisory_unlock(1601470156486188030)
111056
+  (1.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111057
+  (5.0ms)  SELECT
111058
+ pp.proname AS name,
111059
+ pg_get_functiondef(pp.oid) AS definition
111060
+ FROM pg_proc pp
111061
+ JOIN pg_namespace pn
111062
+ ON pn.oid = pp.pronamespace
111063
+ LEFT JOIN pg_depend pd
111064
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
111065
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
111066
+ ORDER BY pp.oid;
111067
+ 
111068
+  (1.9ms)  SELECT
111069
+ pt.tgname AS name,
111070
+ pg_get_triggerdef(pt.oid) AS definition
111071
+ FROM pg_trigger pt
111072
+ JOIN pg_class pc
111073
+ ON (pc.oid = pt.tgrelid)
111074
+ JOIN pg_proc pp
111075
+ ON (pp.oid = pt.tgfoid)
111076
+ WHERE pt.tgname
111077
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
111078
+ ORDER BY pc.oid;
111079
+ 
111080
+  (18.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111081
+  (0.5ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111082
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111083
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111084
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111085
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111086
+  (215.3ms) DROP DATABASE IF EXISTS "kithe_development"
111087
+  (375.5ms) DROP DATABASE IF EXISTS "kithe_test"
111088
+  (458.1ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
111089
+  (933.1ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
111090
+ SQL (12.8ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111091
+ SQL (0.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111092
+  (2.4ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111093
+ RETURNS text
111094
+ LANGUAGE plpgsql
111095
+ AS $function$
111096
+ DECLARE
111097
+ new_id_int bigint;
111098
+ new_id_str character varying := '';
111099
+ done bool;
111100
+ tries integer;
111101
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111102
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111103
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111104
+ alphabet_length integer := array_length(alphabet, 1);
111105
+
111106
+ BEGIN
111107
+ done := false;
111108
+ tries := 0;
111109
+ WHILE (NOT done) LOOP
111110
+ tries := tries + 1;
111111
+ IF (tries > 3) THEN
111112
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111113
+ END IF;
111114
+
111115
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111116
+
111117
+ -- convert bigint to a Base-36 alphanumeric string
111118
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111119
+ -- https://gist.github.com/btbytes/7159902
111120
+ WHILE new_id_int != 0 LOOP
111121
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111122
+ new_id_int := new_id_int / alphabet_length;
111123
+ END LOOP;
111124
+
111125
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111126
+ END LOOP;
111127
+ RETURN new_id_str;
111128
+ END;
111129
+ $function$
111130
+ 
111131
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111132
+  (6.7ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111133
+  (1.9ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111134
+  (1.4ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111135
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111136
+  (1.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111137
+  (1.5ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111138
+  (2.5ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111139
+  (0.5ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111140
+  (7.8ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111141
+  (1.2ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111142
+  (23.6ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111143
+  (8.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111144
+  (1.6ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111145
+  (3.6ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111146
+ FOREIGN KEY ("asset_id")
111147
+ REFERENCES "kithe_models" ("id")
111148
+ 
111149
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111150
+ FOREIGN KEY ("containee_id")
111151
+ REFERENCES "kithe_models" ("id")
111152
+ 
111153
+  (2.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111154
+ FOREIGN KEY ("container_id")
111155
+ REFERENCES "kithe_models" ("id")
111156
+ 
111157
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111158
+ FOREIGN KEY ("leaf_representative_id")
111159
+ REFERENCES "kithe_models" ("id")
111160
+ 
111161
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111162
+ FOREIGN KEY ("parent_id")
111163
+ REFERENCES "kithe_models" ("id")
111164
+ 
111165
+  (2.1ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111166
+ FOREIGN KEY ("representative_id")
111167
+ REFERENCES "kithe_models" ("id")
111168
+ 
111169
+  (3.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111170
+  (0.8ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111171
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111172
+  (10.3ms) INSERT INTO "schema_migrations" (version) VALUES
111173
+ (20181015143259),
111174
+ (20181015143413),
111175
+ (20181015143737),
111176
+ (20181031190647),
111177
+ (20181128185658),
111178
+ (20190103144947),
111179
+ (20190109192252);
111180
+
111181
+ 
111182
+  (13.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111183
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111184
+  (0.2ms) BEGIN
111185
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:32.359365"], ["updated_at", "2020-05-27 16:19:32.359365"]]
111186
+  (0.4ms) COMMIT
111187
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111188
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111189
+  (0.2ms) BEGIN
111190
+ ActiveRecord::InternalMetadata Create (0.8ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "42c53de0cd440a8a7ed21435cee78257b6e0c991"], ["created_at", "2020-05-27 16:19:32.368638"], ["updated_at", "2020-05-27 16:19:32.368638"]]
111191
+  (0.6ms) COMMIT
111192
+ SQL (19.4ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111193
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111194
+  (2.5ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111195
+ RETURNS text
111196
+ LANGUAGE plpgsql
111197
+ AS $function$
111198
+ DECLARE
111199
+ new_id_int bigint;
111200
+ new_id_str character varying := '';
111201
+ done bool;
111202
+ tries integer;
111203
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111204
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111205
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111206
+ alphabet_length integer := array_length(alphabet, 1);
111207
+
111208
+ BEGIN
111209
+ done := false;
111210
+ tries := 0;
111211
+ WHILE (NOT done) LOOP
111212
+ tries := tries + 1;
111213
+ IF (tries > 3) THEN
111214
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111215
+ END IF;
111216
+
111217
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111218
+
111219
+ -- convert bigint to a Base-36 alphanumeric string
111220
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111221
+ -- https://gist.github.com/btbytes/7159902
111222
+ WHILE new_id_int != 0 LOOP
111223
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111224
+ new_id_int := new_id_int / alphabet_length;
111225
+ END LOOP;
111226
+
111227
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111228
+ END LOOP;
111229
+ RETURN new_id_str;
111230
+ END;
111231
+ $function$
111232
+ 
111233
+  (0.3ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111234
+  (15.3ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111235
+  (4.1ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111236
+  (2.7ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111237
+  (0.4ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111238
+  (3.2ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111239
+  (2.3ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111240
+  (1.3ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111241
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111242
+  (3.7ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111243
+  (1.6ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111244
+  (1.2ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111245
+  (2.2ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111246
+  (2.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111247
+  (5.0ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111248
+ FOREIGN KEY ("asset_id")
111249
+ REFERENCES "kithe_models" ("id")
111250
+ 
111251
+  (2.2ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111252
+ FOREIGN KEY ("containee_id")
111253
+ REFERENCES "kithe_models" ("id")
111254
+ 
111255
+  (45.4ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111256
+ FOREIGN KEY ("container_id")
111257
+ REFERENCES "kithe_models" ("id")
111258
+ 
111259
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111260
+ FOREIGN KEY ("leaf_representative_id")
111261
+ REFERENCES "kithe_models" ("id")
111262
+ 
111263
+  (2.3ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111264
+ FOREIGN KEY ("parent_id")
111265
+ REFERENCES "kithe_models" ("id")
111266
+ 
111267
+  (9.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111268
+ FOREIGN KEY ("representative_id")
111269
+ REFERENCES "kithe_models" ("id")
111270
+ 
111271
+  (5.2ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111272
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111273
+  (3.2ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111274
+  (4.5ms) INSERT INTO "schema_migrations" (version) VALUES
111275
+ (20181015143259),
111276
+ (20181015143413),
111277
+ (20181015143737),
111278
+ (20181031190647),
111279
+ (20181128185658),
111280
+ (20190103144947),
111281
+ (20190109192252);
111282
+
111283
+ 
111284
+  (42.4ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111285
+ ActiveRecord::InternalMetadata Load (2.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111286
+  (0.2ms) BEGIN
111287
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-27 16:19:32.703724"], ["updated_at", "2020-05-27 16:19:32.703724"]]
111288
+  (0.4ms) COMMIT
111289
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111290
+  (0.2ms) BEGIN
111291
+ ActiveRecord::InternalMetadata Update (0.5ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-27 16:19:32.711074"], ["key", "environment"]]
111292
+  (0.4ms) COMMIT
111293
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111294
+  (0.2ms) BEGIN
111295
+ ActiveRecord::InternalMetadata Create (0.6ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "42c53de0cd440a8a7ed21435cee78257b6e0c991"], ["created_at", "2020-05-27 16:19:32.718252"], ["updated_at", "2020-05-27 16:19:32.718252"]]
111296
+  (0.7ms) COMMIT
111297
+  (16.6ms) SELECT pg_try_advisory_lock(1601470156486188030)
111298
+  (2.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111299
+ ActiveRecord::InternalMetadata Load (0.6ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111300
+  (0.3ms) SELECT pg_advisory_unlock(1601470156486188030)
111301
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111302
+  (66.1ms)  SELECT
111303
+ pp.proname AS name,
111304
+ pg_get_functiondef(pp.oid) AS definition
111305
+ FROM pg_proc pp
111306
+ JOIN pg_namespace pn
111307
+ ON pn.oid = pp.pronamespace
111308
+ LEFT JOIN pg_depend pd
111309
+ ON pd.objid = pp.oid AND pd.deptype = 'e'
111310
+ WHERE pn.nspname = 'public' AND pd.objid IS NULL
111311
+ ORDER BY pp.oid;
111312
+ 
111313
+  (2.0ms)  SELECT
111314
+ pt.tgname AS name,
111315
+ pg_get_triggerdef(pt.oid) AS definition
111316
+ FROM pg_trigger pt
111317
+ JOIN pg_class pc
111318
+ ON (pc.oid = pt.tgrelid)
111319
+ JOIN pg_proc pp
111320
+ ON (pp.oid = pt.tgfoid)
111321
+ WHERE pt.tgname
111322
+ NOT ILIKE '%constraint%' AND pt.tgname NOT ILIKE 'pg%'
111323
+ ORDER BY pc.oid;
111324
+ 
111325
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111326
+  (0.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111327
+  (0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111328
+  (0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111329
+  (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111330
+  (0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", "environment"]]
111331
+  (239.7ms) DROP DATABASE IF EXISTS "kithe_development"
111332
+  (242.5ms) DROP DATABASE IF EXISTS "kithe_test"
111333
+  (905.5ms) CREATE DATABASE "kithe_development" ENCODING = 'unicode'
111334
+  (604.8ms) CREATE DATABASE "kithe_test" ENCODING = 'unicode'
111335
+ SQL (73.8ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111336
+ SQL (0.2ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111337
+  (98.8ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111338
+ RETURNS text
111339
+ LANGUAGE plpgsql
111340
+ AS $function$
111341
+ DECLARE
111342
+ new_id_int bigint;
111343
+ new_id_str character varying := '';
111344
+ done bool;
111345
+ tries integer;
111346
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111347
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111348
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111349
+ alphabet_length integer := array_length(alphabet, 1);
111350
+
111351
+ BEGIN
111352
+ done := false;
111353
+ tries := 0;
111354
+ WHILE (NOT done) LOOP
111355
+ tries := tries + 1;
111356
+ IF (tries > 3) THEN
111357
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111358
+ END IF;
111359
+
111360
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111361
+
111362
+ -- convert bigint to a Base-36 alphanumeric string
111363
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111364
+ -- https://gist.github.com/btbytes/7159902
111365
+ WHILE new_id_int != 0 LOOP
111366
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111367
+ new_id_int := new_id_int / alphabet_length;
111368
+ END LOOP;
111369
+
111370
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111371
+ END LOOP;
111372
+ RETURN new_id_str;
111373
+ END;
111374
+ $function$
111375
+ 
111376
+  (5.8ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111377
+  (23.5ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111378
+  (2.7ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111379
+  (2.7ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111380
+  (0.4ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111381
+  (2.9ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111382
+  (1.6ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111383
+  (3.0ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111384
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111385
+  (5.1ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111386
+  (1.5ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111387
+  (1.5ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111388
+  (1.3ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111389
+  (1.2ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111390
+  (7.8ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111391
+ FOREIGN KEY ("asset_id")
111392
+ REFERENCES "kithe_models" ("id")
111393
+ 
111394
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111395
+ FOREIGN KEY ("containee_id")
111396
+ REFERENCES "kithe_models" ("id")
111397
+ 
111398
+  (1.8ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111399
+ FOREIGN KEY ("container_id")
111400
+ REFERENCES "kithe_models" ("id")
111401
+ 
111402
+  (2.4ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111403
+ FOREIGN KEY ("leaf_representative_id")
111404
+ REFERENCES "kithe_models" ("id")
111405
+ 
111406
+  (1.7ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111407
+ FOREIGN KEY ("parent_id")
111408
+ REFERENCES "kithe_models" ("id")
111409
+ 
111410
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111411
+ FOREIGN KEY ("representative_id")
111412
+ REFERENCES "kithe_models" ("id")
111413
+ 
111414
+  (3.5ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111415
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111416
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111417
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES
111418
+ (20181015143259),
111419
+ (20181015143413),
111420
+ (20181015143737),
111421
+ (20181031190647),
111422
+ (20181128185658),
111423
+ (20190103144947),
111424
+ (20190109192252);
111425
+
111426
+ 
111427
+  (3.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111428
+ ActiveRecord::InternalMetadata Load (0.5ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111429
+  (0.2ms) BEGIN
111430
+ ActiveRecord::InternalMetadata Create (0.5ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-28 13:26:55.432158"], ["updated_at", "2020-05-28 13:26:55.432158"]]
111431
+  (0.5ms) COMMIT
111432
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111433
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111434
+  (0.1ms) BEGIN
111435
+ ActiveRecord::InternalMetadata Create (0.4ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-28 13:26:55.460004"], ["updated_at", "2020-05-28 13:26:55.460004"]]
111436
+  (0.4ms) COMMIT
111437
+ SQL (16.2ms) CREATE EXTENSION IF NOT EXISTS "pgcrypto"
111438
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
111439
+  (2.3ms) CREATE OR REPLACE FUNCTION public.kithe_models_friendlier_id_gen(min_value bigint, max_value bigint)
111440
+ RETURNS text
111441
+ LANGUAGE plpgsql
111442
+ AS $function$
111443
+ DECLARE
111444
+ new_id_int bigint;
111445
+ new_id_str character varying := '';
111446
+ done bool;
111447
+ tries integer;
111448
+ alphabet char[] := ARRAY['0','1','2','3','4','5','6','7','8','9',
111449
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
111450
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
111451
+ alphabet_length integer := array_length(alphabet, 1);
111452
+
111453
+ BEGIN
111454
+ done := false;
111455
+ tries := 0;
111456
+ WHILE (NOT done) LOOP
111457
+ tries := tries + 1;
111458
+ IF (tries > 3) THEN
111459
+ RAISE 'Could not find non-conflicting friendlier_id in 3 tries';
111460
+ END IF;
111461
+
111462
+ new_id_int := trunc(random() * (max_value - min_value) + min_value);
111463
+
111464
+ -- convert bigint to a Base-36 alphanumeric string
111465
+ -- see https://web.archive.org/web/20130420084605/http://www.jamiebegin.com/base36-conversion-in-postgresql/
111466
+ -- https://gist.github.com/btbytes/7159902
111467
+ WHILE new_id_int != 0 LOOP
111468
+ new_id_str := alphabet[(new_id_int % alphabet_length)+1] || new_id_str;
111469
+ new_id_int := new_id_int / alphabet_length;
111470
+ END LOOP;
111471
+
111472
+ done := NOT exists(SELECT 1 FROM kithe_models WHERE friendlier_id=new_id_str);
111473
+ END LOOP;
111474
+ RETURN new_id_str;
111475
+ END;
111476
+ $function$
111477
+ 
111478
+  (0.2ms) DROP TABLE IF EXISTS "kithe_derivatives" CASCADE
111479
+  (6.7ms) CREATE TABLE "kithe_derivatives" ("id" bigserial primary key, "key" character varying NOT NULL, "file_data" jsonb, "asset_id" uuid NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
111480
+  (2.2ms) CREATE UNIQUE INDEX "index_kithe_derivatives_on_asset_id_and_key" ON "kithe_derivatives" ("asset_id", "key")
111481
+  (1.8ms) CREATE INDEX "index_kithe_derivatives_on_asset_id" ON "kithe_derivatives" ("asset_id")
111482
+  (0.2ms) DROP TABLE IF EXISTS "kithe_model_contains" CASCADE
111483
+  (1.6ms) CREATE TABLE "kithe_model_contains" ("containee_id" uuid, "container_id" uuid)
111484
+  (1.9ms) CREATE INDEX "index_kithe_model_contains_on_containee_id" ON "kithe_model_contains" ("containee_id")
111485
+  (1.5ms) CREATE INDEX "index_kithe_model_contains_on_container_id" ON "kithe_model_contains" ("container_id")
111486
+  (0.2ms) DROP TABLE IF EXISTS "kithe_models" CASCADE
111487
+  (3.9ms) CREATE TABLE "kithe_models" ("id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY, "title" character varying NOT NULL, "type" character varying NOT NULL, "position" integer, "json_attributes" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "parent_id" uuid, "friendlier_id" character varying DEFAULT kithe_models_friendlier_id_gen('2821109907456'::bigint, '101559956668415'::bigint) NOT NULL, "file_data" jsonb, "representative_id" uuid, "leaf_representative_id" uuid, "kithe_model_type" integer NOT NULL)
111488
+  (1.3ms) CREATE UNIQUE INDEX "index_kithe_models_on_friendlier_id" ON "kithe_models" ("friendlier_id")
111489
+  (1.3ms) CREATE INDEX "index_kithe_models_on_leaf_representative_id" ON "kithe_models" ("leaf_representative_id")
111490
+  (12.7ms) CREATE INDEX "index_kithe_models_on_parent_id" ON "kithe_models" ("parent_id")
111491
+  (12.3ms) CREATE INDEX "index_kithe_models_on_representative_id" ON "kithe_models" ("representative_id")
111492
+  (5.1ms) ALTER TABLE "kithe_derivatives" ADD CONSTRAINT "fk_rails_3dac8b4201"
111493
+ FOREIGN KEY ("asset_id")
111494
+ REFERENCES "kithe_models" ("id")
111495
+ 
111496
+  (2.0ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_490c1158f7"
111497
+ FOREIGN KEY ("containee_id")
111498
+ REFERENCES "kithe_models" ("id")
111499
+ 
111500
+  (1.9ms) ALTER TABLE "kithe_model_contains" ADD CONSTRAINT "fk_rails_091010187b"
111501
+ FOREIGN KEY ("container_id")
111502
+ REFERENCES "kithe_models" ("id")
111503
+ 
111504
+  (1.9ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_403cce5c0d"
111505
+ FOREIGN KEY ("leaf_representative_id")
111506
+ REFERENCES "kithe_models" ("id")
111507
+ 
111508
+  (1.8ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_90130a9780"
111509
+ FOREIGN KEY ("parent_id")
111510
+ REFERENCES "kithe_models" ("id")
111511
+ 
111512
+  (2.0ms) ALTER TABLE "kithe_models" ADD CONSTRAINT "fk_rails_afa93b7b5d"
111513
+ FOREIGN KEY ("representative_id")
111514
+ REFERENCES "kithe_models" ("id")
111515
+ 
111516
+  (3.7ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
111517
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
111518
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES (20190404144551)
111519
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
111520
+ (20181015143259),
111521
+ (20181015143413),
111522
+ (20181015143737),
111523
+ (20181031190647),
111524
+ (20181128185658),
111525
+ (20190103144947),
111526
+ (20190109192252);
111527
+
111528
+ 
111529
+  (3.3ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
111530
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111531
+  (0.2ms) BEGIN
111532
+ ActiveRecord::InternalMetadata Create (0.7ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", "2020-05-28 13:26:55.653588"], ["updated_at", "2020-05-28 13:26:55.653588"]]
111533
+  (0.7ms) COMMIT
111534
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
111535
+  (0.2ms) BEGIN
111536
+ ActiveRecord::InternalMetadata Update (0.6ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "test"], ["updated_at", "2020-05-28 13:26:55.661463"], ["key", "environment"]]
111537
+  (0.3ms) COMMIT
111538
+ ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "schema_sha1"], ["LIMIT", 1]]
111539
+  (0.2ms) BEGIN
111540
+ ActiveRecord::InternalMetadata Create (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "schema_sha1"], ["value", "0e24e2caa948e64f3be11233d707b8abffa0f356"], ["created_at", "2020-05-28 13:26:55.668516"], ["updated_at", "2020-05-28 13:26:55.668516"]]
111541
+  (0.5ms) COMMIT
111542
+  (1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC