Skip to content

Commit d82612c

Browse files
Add kind column to db
1 parent b9558fd commit d82612c

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE profile
2+
ADD COLUMN kind TEXT NOT NULL DEFAULT 'flamegraph';

src/flamebin/db.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
(defn insert-profile [profile]
5252
(m/assert Profile profile)
53-
(let [{:keys [id file_path profile_type sample_count owner upload_ts
53+
(let [{:keys [id file_path profile_type kind sample_count owner upload_ts
5454
edit_token config is_public]} profile]
5555
(log/infof "Inserting profile %s from %s" id owner)
5656
(with-locking (:lock @db)
@@ -59,6 +59,7 @@
5959
{:id id
6060
:file_path file_path
6161
:profile_type (name profile_type)
62+
:kind (name kind)
6263
:upload_ts (str upload_ts)
6364
:sample_count sample_count
6465
:is_public is_public
@@ -74,21 +75,21 @@
7475

7576
(defn list-profiles []
7677
(with-locking (:lock @db)
77-
(->> (jdbc/execute! @db ["SELECT id, file_path, profile_type, sample_count, owner, config, upload_ts, is_public FROM profile"])
78+
(->> (jdbc/execute! @db ["SELECT id, file_path, profile_type, kind, sample_count, owner, config, upload_ts, is_public FROM profile"])
7879
(mapv #(-> (unqualify-keys %)
7980
(assoc :edit_token nil)
8081
(coerce Profile))))))
8182

8283
(defn list-public-profiles [n]
8384
(with-locking (:lock @db)
84-
(->> (jdbc/execute! @db ["SELECT id, file_path, profile_type, sample_count, owner, config, upload_ts, is_public, edit_token FROM profile
85+
(->> (jdbc/execute! @db ["SELECT id, file_path, profile_type, kind, sample_count, owner, config, upload_ts, is_public, edit_token FROM profile
8586
WHERE is_public = 1 ORDER BY upload_ts DESC LIMIT ?" n])
8687
(mapv #(-> (unqualify-keys %)
8788
(coerce Profile))))))
8889

8990
(defn get-profile [profile-id]
9091
(with-locking (:lock @db)
91-
(let [q ["SELECT id, file_path, profile_type, sample_count, owner, config, upload_ts, edit_token, is_public FROM profile WHERE id = ?" profile-id]
92+
(let [q ["SELECT id, file_path, profile_type, kind, sample_count, owner, config, upload_ts, edit_token, is_public FROM profile WHERE id = ?" profile-id]
9293
row (some-> (jdbc/execute-one! @db q)
9394
unqualify-keys
9495
(coerce Profile))]

src/flamebin/dto.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
:id :nano-id
2424
:file_path [:and {:gen/fmap #(str % ".dpf")} :string]
2525
:profile_type :keyword
26+
:kind [:enum :flamegraph :diffgraph]
2627
:sample_count [:maybe nat-int?]
2728
:owner [:maybe :string]
2829
:edit_token [:maybe :string]

test/flamebin/db_test.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626

2727
(deftest manual-test
2828
(with-temp-db-and-state
29-
(db/insert-profile (dto/->Profile "QcXAqv" "some-path.dpf" "cpu" 12345
29+
(db/insert-profile (dto/->Profile "QcXAqv" "some-path.dpf" "cpu" :flamegraph 12345
3030
nil "alhdslfglksjdfhg" true "HAA" inst1))
3131
(is (= {:id "QcXAqv", :file_path "some-path.dpf", :profile_type :cpu,
3232
:upload_ts inst1, :sample_count 12345, :owner nil, :is_public true
33-
:config "HAA", :edit_token "alhdslfglksjdfhg"}
33+
:config "HAA", :edit_token "alhdslfglksjdfhg", :kind :flamegraph}
3434
(db/get-profile "QcXAqv")))
3535
(is (inst? (:upload_ts (db/get-profile "QcXAqv"))))
3636

37-
(db/insert-profile (dto/->Profile "tX8nuc" "another-path.dpf" "alloc" 54321
38-
"me" nil false nil inst1))
37+
(db/insert-profile (dto/->Profile "tX8nuc" "another-path.dpf" "alloc"
38+
:diffgraph 54321 "me" nil false nil inst1))
3939
(is (= {:id "tX8nuc", :file_path "another-path.dpf", :edit_token nil
4040
:owner "me", :sample_count 54321, :profile_type :alloc, :is_public false
41-
:config nil, :upload_ts inst1}
41+
:config nil, :upload_ts inst1, :kind :diffgraph}
4242
(db/get-profile "tX8nuc")))))
4343

4444
;;;; Generative testing

0 commit comments

Comments
 (0)