ankane / blazer

Business intelligence made simple
MIT License
4.56k stars 474 forks source link

Blazer UUID problem #333

Closed alec-c4 closed 3 years ago

alec-c4 commented 3 years ago

Hi! Blazer doesn't work with UUID identifiers.

My migration:

class InstallBlazer < ActiveRecord::Migration[6.1]
  def change
    create_table :blazer_queries, id: :uuid do |t|
      t.references :creator, type: :uuid
      t.string :name
      t.text :description
      t.text :statement
      t.string :data_source
      t.string :status
      t.timestamps null: false
    end

    create_table :blazer_audits, id: :uuid do |t|
      t.references :user, type: :uuid
      t.references :query, type: :uuid
      t.text :statement
      t.string :data_source
      t.datetime :created_at
    end

    create_table :blazer_dashboards, id: :uuid do |t|
      t.references :creator, type: :uuid
      t.string :name
      t.timestamps null: false
    end

    create_table :blazer_dashboard_queries, id: :uuid do |t|
      t.references :dashboard, type: :uuid
      t.references :query, type: :uuid
      t.integer :position
      t.timestamps null: false
    end

    create_table :blazer_checks, id: :uuid do |t|
      t.references :creator, type: :uuid
      t.references :query, type: :uuid
      t.string :state
      t.string :schedule
      t.text :emails
      t.text :slack_channels
      t.string :check_type
      t.text :message
      t.datetime :last_run_at
      t.timestamps null: false
    end
  end
end

My exception:

server  | Started GET "/assets/blazer/favicon-392743107d0d14fea5699cff1e80d209db7058ef660e643ff9c9f07e990ac084.png" for ::1 at 2021-05-03 23:14:07 +0300
server  | Started POST "/blazer/queries" for ::1 at 2021-05-03 23:14:14 +0300
server  |   User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."created_at" ASC LIMIT $2  [["id", "149eedae-3b29-4874-87fb-9c40e49d0a08"], ["LIMIT", 1]]
server  |   Role Load (0.5ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", "149eedae-3b29-4874-87fb-9c40e49d0a08"]]
server  |   ↳ config/routes.rb:25:in `block (2 levels) in <main>'
server  | Processing by Blazer::QueriesController#create as HTML
server  |   Parameters: {"authenticity_token"=>"[FILTERED]", "query"=>{"statement"=>"SELECT date_trunc('week', created_at), COUNT(*) FROM users GROUP BY 1\r\n", "data_source"=>"main", "name"=>"q", "description"=>""}, "commit"=>"Create"}
server  |   TRANSACTION (0.2ms)  BEGIN
server  |   Blazer::Query Create (1.5ms)  INSERT INTO "blazer_queries" ("creator_id", "name", "description", "statement", "data_source", "status", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"  [["creator_id", "149eedae-3b29-4874-87fb-9c40e49d0a08"], ["name", "q"], ["description", ""], ["statement", "SELECT date_trunc('week', created_at), COUNT(*) FROM users GROUP BY 1\r\n"], ["data_source", "main"], ["status", "active"], ["created_at", "2021-05-03 20:14:14.248103"], ["updated_at", "2021-05-03 20:14:14.248103"]]
server  |   TRANSACTION (0.2ms)  COMMIT
server  | Redirected to http://localhost:5000/blazer/queries/e2f90dce-a86a-4d3b-adbb-098c53ca8630-q
server  | Completed 302 Found in 7ms (ActiveRecord: 1.9ms | Allocations: 4515)
server  |
server  |
server  | Started GET "/blazer/queries/e2f90dce-a86a-4d3b-adbb-098c53ca8630-q" for ::1 at 2021-05-03 23:14:14 +0300
server  |   User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."created_at" ASC LIMIT $2  [["id", "149eedae-3b29-4874-87fb-9c40e49d0a08"], ["LIMIT", 1]]
server  |   Role Load (0.5ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", "149eedae-3b29-4874-87fb-9c40e49d0a08"]]
server  |   ↳ config/routes.rb:25:in `block (2 levels) in <main>'
server  | Processing by Blazer::QueriesController#show as HTML
server  |   Parameters: {"id"=>"e2f90dce-a86a-4d3b-adbb-098c53ca8630-q"}
server  |   Blazer::Query Load (0.3ms)  SELECT "blazer_queries".* FROM "blazer_queries" WHERE "blazer_queries"."id" = $1 LIMIT $2  [["id", nil], ["LIMIT", 1]]
server  | Completed 404 Not Found in 2ms (ActiveRecord: 0.3ms | Allocations: 1524)
server  |
server  |
server  |
server  | ActiveRecord::RecordNotFound (Couldn't find Blazer::Query with 'id'=e2f90dce):
server  |
server  | activerecord (6.1.3.1) lib/active_record/core.rb:338:in `find'
server  | blazer (a505849e893a) app/controllers/blazer/queries_controller.rb:327:in `set_query'
server  | activesupport (6.1.3.1) lib/active_support/callbacks.rb:427:in `block in make_lambda'
server  | activesupport (6.1.3.1) lib/active_support/callbacks.rb:179:in `block (2 levels) in halting_and_conditional'
server  | actionpack (6.1.3.1) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
server  | activesupport (6.1.3.1) lib/active_support/callbacks.rb:180:in `block in halting_and_conditional'
server  | activesupport (6.1.3.1) lib/active_support/callbacks.rb:512:in `block in invoke_before'
server  | activesupport (6.1.3.1) lib/active_support/callbacks.rb:512:in `each'

But query was saved

[3] pry(main)> Blazer::Query.all
  Blazer::Query Load (0.7ms)  SELECT "blazer_queries".* FROM "blazer_queries"
=> [#<Blazer::Query:0x00007f85b36e1230
  id: "e2f90dce-a86a-4d3b-adbb-098c53ca8630",
  creator_id: "149eedae-3b29-4874-87fb-9c40e49d0a08",
  name: "q",
  description: "",
  statement: "SELECT date_trunc('week', created_at), COUNT(*) FROM users GROUP BY 1\r\n",
  data_source: "main",
  status: "active",
  created_at: Mon, 03 May 2021 20:14:14.248103000 UTC +00:00,
  updated_at: Mon, 03 May 2021 20:14:14.248103000 UTC +00:00>]
ankane commented 3 years ago

Hey @alec-c4, check out #307. I appreciate the PR, but it isn't something I'd like to support.

alec-c4 commented 3 years ago

@ankane My PR adds support for both types - numeric and UUID, so you'll be free from UUID related issues ;)

alec-c4 commented 3 years ago

@mdjamal is that you're looking for? i mean PR :)

ankane commented 3 years ago

Ha, can point users to your fork if they don't want to use numeric ids for Blazer.