diff --git a/db/migrate/20240924121509_add_index_to_created_at_for_tipline_request.rb b/db/migrate/20240924121509_add_index_to_created_at_for_tipline_request.rb new file mode 100644 index 000000000..7d780e1f3 --- /dev/null +++ b/db/migrate/20240924121509_add_index_to_created_at_for_tipline_request.rb @@ -0,0 +1,10 @@ +class AddIndexToCreatedAtForTiplineRequest < ActiveRecord::Migration[6.1] + def change + execute "CREATE INDEX tipline_request_created_at_year ON tipline_requests (date_trunc('year', created_at))" + execute "CREATE INDEX tipline_request_created_at_quarter ON tipline_requests (date_trunc('quarter', created_at))" + execute "CREATE INDEX tipline_request_created_at_month ON tipline_requests (date_trunc('month', created_at))" + execute "CREATE INDEX tipline_request_created_at_week ON tipline_requests (date_trunc('week', created_at))" + execute "CREATE INDEX tipline_request_created_at_day ON tipline_requests (date_trunc('day', created_at))" + add_index :tipline_requests, :created_at + end +end diff --git a/db/migrate/20240924121533_add_index_to_created_at_for_tipline_message.rb b/db/migrate/20240924121533_add_index_to_created_at_for_tipline_message.rb new file mode 100644 index 000000000..9209bccc6 --- /dev/null +++ b/db/migrate/20240924121533_add_index_to_created_at_for_tipline_message.rb @@ -0,0 +1,10 @@ +class AddIndexToCreatedAtForTiplineMessage < ActiveRecord::Migration[6.1] + def change + execute "CREATE INDEX tipline_message_created_at_year ON tipline_messages (date_trunc('year', created_at))" + execute "CREATE INDEX tipline_message_created_at_quarter ON tipline_messages (date_trunc('quarter', created_at))" + execute "CREATE INDEX tipline_message_created_at_month ON tipline_messages (date_trunc('month', created_at))" + execute "CREATE INDEX tipline_message_created_at_week ON tipline_messages (date_trunc('week', created_at))" + execute "CREATE INDEX tipline_message_created_at_day ON tipline_messages (date_trunc('day', created_at))" + add_index :tipline_messages, :created_at + end +end diff --git a/db/migrate/20240924130424_add_created_at_index_for_data_points.rb b/db/migrate/20240924130424_add_created_at_index_for_data_points.rb new file mode 100644 index 000000000..4a422c05a --- /dev/null +++ b/db/migrate/20240924130424_add_created_at_index_for_data_points.rb @@ -0,0 +1,7 @@ +class AddCreatedAtIndexForDataPoints < ActiveRecord::Migration[6.1] + def change + add_index :tipline_subscriptions, :created_at + add_index :tipline_newsletter_deliveries, :created_at + add_index :annotations, :created_at + end +end diff --git a/db/schema.rb b/db/schema.rb index b92f4f463..12b8a9b84 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_09_13_210101) do +ActiveRecord::Schema.define(version: 202010161522429) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -26,41 +26,41 @@ END; $function$ SQL - create_function :version_field_name, sql_definition: <<-'SQL' - CREATE OR REPLACE FUNCTION public.version_field_name(event_type text, object_after text) + create_function :dynamic_annotation_fields_value, sql_definition: <<-'SQL' + CREATE OR REPLACE FUNCTION public.dynamic_annotation_fields_value(field_name character varying, value text) RETURNS text LANGUAGE plpgsql IMMUTABLE AS $function$ DECLARE - name TEXT; + dynamic_field_value TEXT; BEGIN - IF event_type = 'create_dynamicannotationfield' OR event_type = 'update_dynamicannotationfield' + IF field_name = 'external_id' OR field_name = 'smooch_user_id' OR field_name = 'verification_status_status' THEN - SELECT REGEXP_REPLACE(object_after, '^.*field_name":"([^"]+).*$', '\1') INTO name; + SELECT value INTO dynamic_field_value; ELSE - SELECT '' INTO name; + SELECT NULL INTO dynamic_field_value; END IF; - RETURN name; + RETURN dynamic_field_value; END; $function$ SQL - create_function :version_annotation_type, sql_definition: <<-'SQL' - CREATE OR REPLACE FUNCTION public.version_annotation_type(event_type text, object_after text) + create_function :task_fieldset, sql_definition: <<-'SQL' + CREATE OR REPLACE FUNCTION public.task_fieldset(annotation_type text, data text) RETURNS text LANGUAGE plpgsql IMMUTABLE AS $function$ DECLARE - name TEXT; + fieldset TEXT; BEGIN - IF event_type = 'create_dynamic' OR event_type = 'update_dynamic' + IF annotation_type = 'task' AND data LIKE '%fieldset: %' THEN - SELECT REGEXP_REPLACE(object_after, '^.*annotation_type":"([^"]+).*$', '\1') INTO name; + SELECT REGEXP_REPLACE(data, '^.*fieldset: ([0-9a-z_]+).*$', '\1') INTO fieldset; ELSE - SELECT '' INTO name; + SELECT NULL INTO fieldset; END IF; - RETURN name; + RETURN fieldset; END; $function$ SQL @@ -83,41 +83,41 @@ END; $function$ SQL - create_function :task_fieldset, sql_definition: <<-'SQL' - CREATE OR REPLACE FUNCTION public.task_fieldset(annotation_type text, data text) + create_function :version_annotation_type, sql_definition: <<-'SQL' + CREATE OR REPLACE FUNCTION public.version_annotation_type(event_type text, object_after text) RETURNS text LANGUAGE plpgsql IMMUTABLE AS $function$ DECLARE - fieldset TEXT; + name TEXT; BEGIN - IF annotation_type = 'task' AND data LIKE '%fieldset: %' + IF event_type = 'create_dynamic' OR event_type = 'update_dynamic' THEN - SELECT REGEXP_REPLACE(data, '^.*fieldset: ([0-9a-z_]+).*$', '\1') INTO fieldset; + SELECT REGEXP_REPLACE(object_after, '^.*annotation_type":"([^"]+).*$', '\1') INTO name; ELSE - SELECT NULL INTO fieldset; + SELECT '' INTO name; END IF; - RETURN fieldset; + RETURN name; END; $function$ SQL - create_function :dynamic_annotation_fields_value, sql_definition: <<-'SQL' - CREATE OR REPLACE FUNCTION public.dynamic_annotation_fields_value(field_name character varying, value text) + create_function :version_field_name, sql_definition: <<-'SQL' + CREATE OR REPLACE FUNCTION public.version_field_name(event_type text, object_after text) RETURNS text LANGUAGE plpgsql IMMUTABLE AS $function$ DECLARE - dynamic_field_value TEXT; + name TEXT; BEGIN - IF field_name = 'external_id' OR field_name = 'smooch_user_id' OR field_name = 'verification_status_status' + IF event_type = 'create_dynamicannotationfield' OR event_type = 'update_dynamicannotationfield' THEN - SELECT value INTO dynamic_field_value; + SELECT REGEXP_REPLACE(object_after, '^.*field_name":"([^"]+).*$', '\1') INTO name; ELSE - SELECT NULL INTO dynamic_field_value; + SELECT '' INTO name; END IF; - RETURN dynamic_field_value; + RETURN name; END; $function$ SQL @@ -133,15 +133,15 @@ create_table "accounts", id: :serial, force: :cascade do |t| t.integer "user_id" - t.integer "team_id" t.string "url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "team_id" t.text "omniauth_info" t.string "uid" t.string "provider" t.string "token" t.string "email" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.index ["uid", "provider", "token", "email"], name: "index_accounts_on_uid_and_provider_and_token_and_email" t.index ["url"], name: "index_accounts_on_url", unique: true t.index ["user_id"], name: "index_accounts_on_user_id" @@ -156,41 +156,44 @@ t.integer "annotator_id" t.text "entities" t.text "data" + t.datetime "created_at" + t.datetime "updated_at" t.string "file" + t.text "attribution" t.integer "lock_version", default: 0, null: false t.boolean "locked", default: false - t.text "attribution" t.text "fragment" - t.datetime "created_at" - t.datetime "updated_at" t.index "task_fieldset((annotation_type)::text, data)", name: "task_fieldset", where: "((annotation_type)::text = 'task'::text)" t.index "task_team_task_id((annotation_type)::text, data)", name: "task_team_task_id", where: "((annotation_type)::text = 'task'::text)" t.index ["annotated_type", "annotated_id"], name: "index_annotations_on_annotated_type_and_annotated_id" - t.index ["annotation_type"], name: "index_annotation_type_order", opclass: :varchar_pattern_ops + t.index ["annotation_type"], name: "index_annotation_type_order" t.index ["annotation_type"], name: "index_annotations_on_annotation_type" + t.index ["created_at"], name: "index_annotations_on_created_at" end create_table "api_keys", id: :serial, force: :cascade do |t| t.string "access_token", default: "", null: false - t.string "title" - t.integer "user_id" - t.integer "team_id" t.datetime "expire_at" - t.jsonb "rate_limits", default: {} - t.string "application" t.datetime "created_at" t.datetime "updated_at" + t.string "application" + t.jsonb "rate_limits", default: {} + t.string "title" t.string "description" + t.bigint "team_id" + t.bigint "user_id" + t.index ["team_id"], name: "index_api_keys_on_team_id" + t.index ["user_id"], name: "index_api_keys_on_user_id" end create_table "assignments", id: :serial, force: :cascade do |t| t.integer "assigned_id", null: false t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "assigned_type" t.integer "assigner_id" t.text "message" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.index ["assigned_id", "assigned_type", "user_id"], name: "index_assignments_on_assigned_id_and_assigned_type_and_user_id", unique: true t.index ["assigned_id", "assigned_type"], name: "index_assignments_on_assigned_id_and_assigned_type" t.index ["assigned_id"], name: "index_assignments_on_assigned_id" @@ -217,9 +220,9 @@ t.text "description" t.bigint "user_id", null: false t.bigint "project_media_id" - t.text "context" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "context" t.bigint "team_id" t.index ["project_media_id"], name: "index_claim_descriptions_on_project_media_id", unique: true t.index ["team_id"], name: "index_claim_descriptions_on_team_id" @@ -236,10 +239,10 @@ create_table "clusters", force: :cascade do |t| t.integer "project_media_id" - t.datetime "first_item_at" - t.datetime "last_item_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.datetime "first_item_at" + t.datetime "last_item_at" t.bigint "feed_id" t.integer "team_ids", default: [], null: false, array: true t.integer "channels", default: [], null: false, array: true @@ -256,10 +259,10 @@ create_table "dynamic_annotation_annotation_types", primary_key: "annotation_type", id: :string, force: :cascade do |t| t.string "label", null: false t.text "description" - t.boolean "singleton", default: true - t.jsonb "json_schema" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "singleton", default: true + t.jsonb "json_schema" t.index ["json_schema"], name: "index_dynamic_annotation_annotation_types_on_json_schema", using: :gin end @@ -270,9 +273,9 @@ t.text "description" t.boolean "optional", default: true t.text "settings" - t.string "default_value" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "default_value" end create_table "dynamic_annotation_field_types", primary_key: "field_type", id: :string, force: :cascade do |t| @@ -282,25 +285,23 @@ t.datetime "updated_at", null: false end - create_table "dynamic_annotation_fields", id: :serial, force: :cascade do |t| + create_table "dynamic_annotation_fields", id: :integer, default: -> { "nextval('new_dynamic_annotation_fields_id_seq'::regclass)" }, force: :cascade do |t| t.integer "annotation_id", null: false t.string "field_name", null: false t.string "annotation_type", null: false t.string "field_type", null: false t.text "value", null: false - t.jsonb "value_json", default: "{}" + t.jsonb "value_json", default: {} t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index "dynamic_annotation_fields_value(field_name, value)", name: "dynamic_annotation_fields_value", where: "((field_name)::text = ANY ((ARRAY['external_id'::character varying, 'smooch_user_id'::character varying, 'verification_status_status'::character varying])::text[]))" + t.index "dynamic_annotation_fields_value(field_name, value)", name: "dynamic_annotation_fields_value", where: "((field_name)::text = ANY (ARRAY[('external_id'::character varying)::text, ('smooch_user_id'::character varying)::text, ('verification_status_status'::character varying)::text]))" t.index ["annotation_id", "field_name"], name: "index_dynamic_annotation_fields_on_annotation_id_and_field_name" - t.index ["annotation_id"], name: "index_dynamic_annotation_fields_on_annotation_id" - t.index ["annotation_type"], name: "index_dynamic_annotation_fields_on_annotation_type" t.index ["field_name"], name: "index_dynamic_annotation_fields_on_field_name" t.index ["field_type"], name: "index_dynamic_annotation_fields_on_field_type" t.index ["value"], name: "fetch_unique_id", unique: true, where: "(((field_name)::text = 'external_id'::text) AND (value <> ''::text) AND (value <> '\"\"'::text))" t.index ["value"], name: "index_status", where: "((field_name)::text = 'verification_status_status'::text)" + t.index ["value"], name: "smooch_request_message_id_unique_id", unique: true, where: "(((field_name)::text = 'smooch_message_id'::text) AND (value <> ''::text) AND (value <> '\"\"'::text))" t.index ["value"], name: "smooch_user_unique_id", unique: true, where: "(((field_name)::text = 'smooch_user_id'::text) AND (value <> ''::text) AND (value <> '\"\"'::text))" - t.index ["value"], name: "translation_request_id", unique: true, where: "((field_name)::text = 'translation_request_id'::text)" t.index ["value_json"], name: "index_dynamic_annotation_fields_on_value_json", using: :gin end @@ -336,9 +337,9 @@ t.string "title" t.bigint "user_id", null: false t.bigint "claim_description_id", null: false - t.string "language", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "language", default: "", null: false t.string "signature" t.string "tags", default: [], array: true t.integer "publisher_id" @@ -373,9 +374,9 @@ t.bigint "team_id", null: false t.bigint "feed_id", null: false t.jsonb "settings", default: {} - t.boolean "shared", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "shared", default: false t.bigint "saved_search_id" t.index ["feed_id"], name: "index_feed_teams_on_feed_id" t.index ["saved_search_id"], name: "index_feed_teams_on_saved_search_id" @@ -386,9 +387,9 @@ create_table "feeds", force: :cascade do |t| t.string "name", null: false t.jsonb "settings", default: {} - t.boolean "published", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "published", default: false t.bigint "saved_search_id" t.bigint "user_id" t.bigint "team_id" @@ -411,8 +412,8 @@ t.string "identity" t.boolean "success" t.string "failure_reason" - t.string "user_type" t.integer "user_id" + t.string "user_type" t.string "context" t.string "ip" t.text "user_agent" @@ -426,11 +427,11 @@ t.integer "user_id" t.integer "account_id" t.string "url" - t.string "file" - t.string "quote" - t.string "type" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "quote" + t.string "type" + t.string "file" t.integer "uuid", default: 0, null: false t.index ["url"], name: "index_medias_on_url", unique: true end @@ -513,19 +514,19 @@ end create_table "project_medias", id: :serial, force: :cascade do |t| - t.integer "project_id" t.integer "media_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "user_id" - t.integer "source_id" - t.integer "team_id" - t.jsonb "channel", default: {"main"=>0} - t.boolean "read", default: false, null: false - t.integer "sources_count", default: 0, null: false t.integer "archived", default: 0 t.integer "targets_count", default: 0, null: false + t.integer "sources_count", default: 0, null: false + t.integer "team_id" + t.boolean "read", default: false, null: false + t.integer "source_id" + t.integer "project_id" t.integer "last_seen" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.jsonb "channel", default: {"main"=>0} t.integer "unmatched", default: 0 t.string "custom_title" t.string "title_field" @@ -544,18 +545,18 @@ create_table "projects", id: :serial, force: :cascade do |t| t.integer "user_id" t.integer "team_id" - t.integer "project_group_id" t.string "title" - t.boolean "is_default", default: false t.text "description" t.string "lead_image" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "archived", default: 0 + t.text "settings" t.string "token" t.integer "assignments_count", default: 0 + t.integer "project_group_id" t.integer "privacy", default: 0, null: false - t.integer "archived", default: 0 - t.text "settings" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.boolean "is_default", default: false t.index ["id"], name: "index_projects_on_id" t.index ["is_default"], name: "index_projects_on_is_default" t.index ["privacy"], name: "index_projects_on_privacy" @@ -567,24 +568,23 @@ create_table "relationships", id: :serial, force: :cascade do |t| t.integer "source_id", null: false t.integer "target_id", null: false - t.integer "user_id" t.string "relationship_type", null: false - t.float "original_weight", default: 0.0 - t.float "float", default: 0.0 - t.jsonb "original_details", default: "{}" - t.string "original_relationship_type" - t.string "original_model" - t.integer "original_source_id" - t.string "original_source_field" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "user_id" + t.float "weight", default: 0.0 t.integer "confirmed_by" t.datetime "confirmed_at" - t.float "weight", default: 0.0 t.string "source_field" t.string "target_field" t.string "model" t.jsonb "details", default: "{}" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.float "original_weight", default: 0.0 + t.jsonb "original_details", default: "{}" + t.string "original_relationship_type" + t.string "original_model" + t.integer "original_source_id" + t.string "original_source_field" t.index "LEAST(source_id, target_id), GREATEST(source_id, target_id)", name: "relationships_least_greatest_idx", unique: true t.index ["relationship_type"], name: "index_relationships_on_relationship_type" t.index ["source_id", "relationship_type"], name: "index_relationships_on_source_id_and_relationship_type" @@ -598,18 +598,18 @@ t.bigint "feed_id", null: false t.string "request_type", null: false t.text "content", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "request_id" t.integer "media_id" - t.integer "fact_checked_by_count", default: 0, null: false - t.integer "project_medias_count", default: 0, null: false t.integer "medias_count", default: 0, null: false t.integer "requests_count", default: 0, null: false t.datetime "last_submitted_at" t.string "webhook_url" t.datetime "last_called_webhook_at" t.integer "subscriptions_count", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "fact_checked_by_count", default: 0, null: false + t.integer "project_medias_count", default: 0, null: false t.index ["feed_id"], name: "index_requests_on_feed_id" t.index ["media_id"], name: "index_requests_on_media_id" t.index ["request_id"], name: "index_requests_on_request_id" @@ -642,15 +642,15 @@ create_table "sources", id: :serial, force: :cascade do |t| t.integer "user_id" - t.integer "team_id" t.string "name" t.string "slogan" t.string "avatar" - t.integer "archived", default: 0 - t.string "file" - t.integer "lock_version", default: 0, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "team_id" + t.string "file" + t.integer "archived", default: 0 + t.integer "lock_version", default: 0, null: false end create_table "tag_texts", id: :serial, force: :cascade do |t| @@ -671,52 +671,54 @@ t.text "mapping" t.boolean "required", default: false t.integer "team_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "json_schema" t.integer "order", default: 0 - t.string "associated_type", default: "ProjectMedia", null: false t.string "fieldset", default: "", null: false t.boolean "show_in_browser_extension", default: true, null: false - t.string "json_schema" + t.string "associated_type", default: "ProjectMedia", null: false t.text "conditional_info" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.index ["team_id", "fieldset", "associated_type"], name: "index_team_tasks_on_team_id_and_fieldset_and_associated_type" end create_table "team_users", id: :serial, force: :cascade do |t| t.integer "team_id" t.integer "user_id" - t.string "type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "role" + t.string "status", default: "member" t.integer "invited_by_id" t.string "invitation_token" t.string "raw_invitation_token" t.datetime "invitation_accepted_at" - t.string "file" t.text "settings" - t.string "role" - t.string "status", default: "member" + t.string "type" t.string "invitation_email" + t.string "file" t.integer "lock_version", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.index ["team_id", "user_id"], name: "index_team_users_on_team_id_and_user_id", unique: true t.index ["type"], name: "index_team_users_on_type" t.index ["user_id", "team_id", "status"], name: "index_team_users_on_user_id_and_team_id_and_status" + t.index ["user_id", "team_id"], name: "index_team_users_on_user_id_and_team_id" end create_table "teams", id: :serial, force: :cascade do |t| t.string "name" t.string "logo" - t.boolean "private", default: true, null: false + t.boolean "private", default: true t.integer "archived", default: 0 - t.string "country" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.text "description" t.string "slug" - t.boolean "inactive", default: false t.text "settings" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.boolean "inactive", default: false + t.string "country" t.index ["country"], name: "index_teams_on_country" t.index ["inactive"], name: "index_teams_on_inactive" + t.index ["slug"], name: "index_teams_on_slug" t.index ["slug"], name: "unique_team_slugs", unique: true end @@ -733,6 +735,12 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "state" + t.index "date_trunc('day'::text, created_at)", name: "tipline_message_created_at_day" + t.index "date_trunc('month'::text, created_at)", name: "tipline_message_created_at_month" + t.index "date_trunc('quarter'::text, created_at)", name: "tipline_message_created_at_quarter" + t.index "date_trunc('week'::text, created_at)", name: "tipline_message_created_at_week" + t.index "date_trunc('year'::text, created_at)", name: "tipline_message_created_at_year" + t.index ["created_at"], name: "index_tipline_messages_on_created_at" t.index ["external_id", "state"], name: "index_tipline_messages_on_external_id_and_state", unique: true t.index ["team_id"], name: "index_tipline_messages_on_team_id" t.index ["uid"], name: "index_tipline_messages_on_uid" @@ -746,6 +754,7 @@ t.bigint "tipline_newsletter_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["created_at"], name: "index_tipline_newsletter_deliveries_on_created_at" t.index ["tipline_newsletter_id"], name: "index_tipline_newsletter_deliveries_on_tipline_newsletter_id" end @@ -798,8 +807,14 @@ t.integer "smooch_report_sent_at", default: 0 t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.index "date_trunc('day'::text, created_at)", name: "tipline_request_created_at_day" + t.index "date_trunc('month'::text, created_at)", name: "tipline_request_created_at_month" + t.index "date_trunc('quarter'::text, created_at)", name: "tipline_request_created_at_quarter" + t.index "date_trunc('week'::text, created_at)", name: "tipline_request_created_at_week" + t.index "date_trunc('year'::text, created_at)", name: "tipline_request_created_at_year" t.index ["associated_type", "associated_id"], name: "index_tipline_requests_on_associated" t.index ["associated_type", "associated_id"], name: "index_tipline_requests_on_associated_type_and_associated_id" + t.index ["created_at"], name: "index_tipline_requests_on_created_at" t.index ["language"], name: "index_tipline_requests_on_language" t.index ["platform"], name: "index_tipline_requests_on_platform" t.index ["smooch_message_id"], name: "index_tipline_requests_on_smooch_message_id", unique: true, where: "((smooch_message_id IS NOT NULL) AND ((smooch_message_id)::text <> ''::text))" @@ -832,9 +847,10 @@ t.string "uid" t.string "language" t.integer "team_id" - t.string "platform" t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }, null: false t.datetime "updated_at", default: -> { "CURRENT_TIMESTAMP" }, null: false + t.string "platform" + t.index ["created_at"], name: "index_tipline_subscriptions_on_created_at" t.index ["language", "team_id"], name: "index_tipline_subscriptions_on_language_and_team_id" t.index ["language"], name: "index_tipline_subscriptions_on_language" t.index ["platform"], name: "index_tipline_subscriptions_on_platform" @@ -847,7 +863,6 @@ t.string "name", default: "", null: false t.string "login", default: "", null: false t.string "token", default: "", null: false - t.boolean "default", default: false t.string "email" t.string "encrypted_password", default: "" t.string "reset_password_token" @@ -858,6 +873,23 @@ t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "image" + t.integer "current_team_id" + t.text "settings" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.boolean "is_admin", default: false + t.text "cached_teams" + t.string "type" + t.integer "api_key_id" + t.integer "source_id" + t.string "unconfirmed_email" + t.integer "current_project_id" + t.boolean "is_active", default: true + t.datetime "last_accepted_terms_at" t.string "invitation_token" t.string "raw_invitation_token" t.datetime "invitation_created_at" @@ -866,32 +898,15 @@ t.integer "invitation_limit" t.integer "invited_by_id" t.string "invited_by_type" - t.datetime "last_accepted_terms_at" - t.string "image" - t.string "type" - t.integer "source_id" - t.boolean "is_active", default: true - t.boolean "is_admin", default: false - t.integer "current_project_id" - t.integer "integer" - t.text "settings" - t.datetime "last_active_at" - t.text "cached_teams" - t.integer "current_team_id" - t.boolean "completed_signup", default: true - t.integer "api_key_id" - t.string "unconfirmed_email" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" t.string "encrypted_otp_secret" t.string "encrypted_otp_secret_iv" t.string "encrypted_otp_secret_salt" t.integer "consumed_timestep" t.boolean "otp_required_for_login" t.string "otp_backup_codes", array: true + t.boolean "default", default: false + t.boolean "completed_signup", default: true + t.datetime "last_active_at" t.integer "failed_attempts", default: 0, null: false t.string "unlock_token" t.datetime "locked_at" @@ -907,8 +922,7 @@ end create_table "versions", id: :serial, force: :cascade do |t| - t.string "item_type" - t.string "{:null=>false}" + t.string "item_type", null: false t.string "item_id", null: false t.string "event", null: false t.string "whodunnit" @@ -916,17 +930,20 @@ t.text "object_changes" t.datetime "created_at" t.text "meta" + t.string "event_type" + t.text "object_after" t.integer "associated_id" t.string "associated_type" - t.string "event_type" t.integer "team_id" - t.text "object_after" t.index ["associated_id"], name: "index_versions_on_associated_id" t.index ["event_type"], name: "index_versions_on_event_type" t.index ["item_type", "item_id", "whodunnit"], name: "index_versions_on_item_type_and_item_id_and_whodunnit" t.index ["team_id"], name: "index_versions_on_team_id" end + add_foreign_key "accounts", "teams" + add_foreign_key "api_keys", "teams" + add_foreign_key "api_keys", "users" add_foreign_key "claim_descriptions", "project_medias" add_foreign_key "claim_descriptions", "users" add_foreign_key "explainer_items", "explainers" @@ -941,5 +958,8 @@ add_foreign_key "feed_teams", "teams" add_foreign_key "project_media_requests", "project_medias" add_foreign_key "project_media_requests", "requests" + add_foreign_key "project_medias", "users" add_foreign_key "requests", "feeds" + add_foreign_key "sources", "teams" + add_foreign_key "users", "sources" end diff --git a/lib/check_data_points.rb b/lib/check_data_points.rb index 37cb2925a..18f9ccb71 100644 --- a/lib/check_data_points.rb +++ b/lib/check_data_points.rb @@ -123,12 +123,13 @@ def query_based_on_granularity(query, granularity, type = nil) # But I'll limit the value to the following [year, quarter, month, week, day] if GRANULARITY_VALUES.include?(granularity) if type == 'newsletter' - query = query.group("date_trunc('#{granularity}', tipline_newsletter_deliveries.created_at)") + query = query.group("date_trunc('#{granularity}', tipline_newsletter_deliveries.created_at)").count else - query.group("date_trunc('#{granularity}', created_at)") + query.group("date_trunc('#{granularity}', created_at)").count end + else + query.count end - query.count end def elastic_search_top_items(team_id, start_date, end_date, limit, with_tags = false) diff --git a/test/lib/check_data_points_test.rb b/test/lib/check_data_points_test.rb index eefac8660..677cf979f 100644 --- a/test/lib/check_data_points_test.rb +++ b/test/lib/check_data_points_test.rb @@ -41,11 +41,14 @@ def teardown # Verify all tipline requests assert_equal 5, CheckDataPoints.tipline_requests(@team.id, @start_date, @end_date) assert_equal 1, CheckDataPoints.tipline_requests(@team2.id, @start_date, @end_date) + # Verify granularity + from = (Time.now - 4.month).strftime("%Y-%m-%d") + result_g = CheckDataPoints.tipline_requests(@team.id, from, @end_date, 'month') + assert_equal [2, 5], result_g.values.sort # Verify tipline requests by search_type result = CheckDataPoints.tipline_requests_by_search_type(@team.id, @start_date, @end_date) actual = { "irrelevant_search_result_requests" => 1, "relevant_search_result_requests" => 2, "timeout_search_requests" => 1 } assert_equal actual, result - from = (Time.now - 4.month).strftime("%Y-%m-%d") result = CheckDataPoints.tipline_requests_by_search_type(@team.id, from, @end_date) actual = { "irrelevant_search_result_requests" => 1, "relevant_search_result_requests" => 3, "timeout_search_requests" => 1 } assert_equal actual, result