telegram bot logs, first pass
This commit is contained in:
42
db/migrate/20250731035548_create_telegram_bot_logs.rb
Normal file
42
db/migrate/20250731035548_create_telegram_bot_logs.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# typed: true
|
||||
class CreateTelegramBotLogs < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :telegram_bot_logs do |t|
|
||||
# Telegram user information
|
||||
t.bigint :telegram_user_id, null: false
|
||||
t.string :telegram_username
|
||||
t.string :telegram_first_name
|
||||
t.string :telegram_last_name
|
||||
t.bigint :telegram_chat_id, null: false
|
||||
|
||||
# Request metadata
|
||||
t.timestamp :request_timestamp, null: false
|
||||
t.string :status, null: false
|
||||
t.text :error_message
|
||||
|
||||
# Performance metrics
|
||||
t.float :fingerprint_computation_time
|
||||
t.float :search_computation_time
|
||||
t.integer :search_results_count, default: 0
|
||||
|
||||
# Response and image data
|
||||
t.jsonb :response_data, default: {}
|
||||
t.binary :processed_image_sha256
|
||||
|
||||
t.timestamps
|
||||
|
||||
# Indexes for performance
|
||||
t.index :telegram_user_id
|
||||
t.index :request_timestamp
|
||||
t.index :search_results_count
|
||||
t.index :processed_image_sha256
|
||||
t.index %i[telegram_user_id request_timestamp]
|
||||
end
|
||||
|
||||
# Foreign key constraint to BlobFile (sha256 field)
|
||||
add_foreign_key :telegram_bot_logs,
|
||||
:blob_files,
|
||||
column: :processed_image_sha256,
|
||||
primary_key: :sha256
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddPerformanceTimingToTelegramBotLogs < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_column :telegram_bot_logs, :download_time, :float
|
||||
add_column :telegram_bot_logs, :image_processing_time, :float
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddTotalRequestTimeToTelegramBotLogs < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_column :telegram_bot_logs, :total_request_time, :float
|
||||
end
|
||||
end
|
||||
107
db/structure.sql
107
db/structure.sql
@@ -2324,6 +2324,52 @@ CREATE TABLE public.schema_migrations (
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: telegram_bot_logs; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.telegram_bot_logs (
|
||||
id bigint NOT NULL,
|
||||
telegram_user_id bigint NOT NULL,
|
||||
telegram_username character varying,
|
||||
telegram_first_name character varying,
|
||||
telegram_last_name character varying,
|
||||
telegram_chat_id bigint NOT NULL,
|
||||
request_timestamp timestamp without time zone NOT NULL,
|
||||
status character varying NOT NULL,
|
||||
error_message text,
|
||||
fingerprint_computation_time double precision,
|
||||
search_computation_time double precision,
|
||||
search_results_count integer DEFAULT 0,
|
||||
response_data jsonb DEFAULT '{}'::jsonb,
|
||||
processed_image_sha256 bytea,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
download_time double precision,
|
||||
image_processing_time double precision,
|
||||
total_request_time double precision
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: telegram_bot_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.telegram_bot_logs_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: telegram_bot_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.telegram_bot_logs_id_seq OWNED BY public.telegram_bot_logs.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: trained_regression_models; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@@ -3050,6 +3096,13 @@ ALTER TABLE ONLY public.pghero_query_stats ALTER COLUMN id SET DEFAULT nextval('
|
||||
ALTER TABLE ONLY public.pghero_space_stats ALTER COLUMN id SET DEFAULT nextval('public.pghero_space_stats_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: telegram_bot_logs id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.telegram_bot_logs ALTER COLUMN id SET DEFAULT nextval('public.telegram_bot_logs_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: trained_regression_models id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -3336,6 +3389,14 @@ ALTER TABLE ONLY public.schema_migrations
|
||||
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
|
||||
|
||||
|
||||
--
|
||||
-- Name: telegram_bot_logs telegram_bot_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.telegram_bot_logs
|
||||
ADD CONSTRAINT telegram_bot_logs_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: trained_regression_models trained_regression_models_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -3541,6 +3602,13 @@ CREATE UNIQUE INDEX idx_on_post_file_id_thumb_type_frame_17152086d1 ON public.do
|
||||
CREATE UNIQUE INDEX idx_on_post_file_id_thumbnail_id_28e9a641fb ON public.domain_post_file_bit_fingerprints USING btree (post_file_id, thumbnail_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_on_telegram_user_id_request_timestamp_075ae9ab44; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX idx_on_telegram_user_id_request_timestamp_075ae9ab44 ON public.telegram_bot_logs USING btree (telegram_user_id, request_timestamp);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_blob_files_on_sha256; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4619,6 +4687,34 @@ CREATE INDEX index_pghero_query_stats_on_database_and_captured_at ON public.pghe
|
||||
CREATE INDEX index_pghero_space_stats_on_database_and_captured_at ON public.pghero_space_stats USING btree (database, captured_at);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_telegram_bot_logs_on_processed_image_sha256; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_telegram_bot_logs_on_processed_image_sha256 ON public.telegram_bot_logs USING btree (processed_image_sha256);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_telegram_bot_logs_on_request_timestamp; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_telegram_bot_logs_on_request_timestamp ON public.telegram_bot_logs USING btree (request_timestamp);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_telegram_bot_logs_on_search_results_count; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_telegram_bot_logs_on_search_results_count ON public.telegram_bot_logs USING btree (search_results_count);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_telegram_bot_logs_on_telegram_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_telegram_bot_logs_on_telegram_user_id ON public.telegram_bot_logs USING btree (telegram_user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_trained_regression_models_on_created_at; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -5130,6 +5226,14 @@ ALTER INDEX public.index_blob_files_on_sha256 ATTACH PARTITION public.index_blob
|
||||
ALTER INDEX public.index_blob_files_on_sha256 ATTACH PARTITION public.index_blob_files_63_on_sha256;
|
||||
|
||||
|
||||
--
|
||||
-- Name: telegram_bot_logs fk_rails_001ca2ed89; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.telegram_bot_logs
|
||||
ADD CONSTRAINT fk_rails_001ca2ed89 FOREIGN KEY (processed_image_sha256) REFERENCES public.blob_files(sha256);
|
||||
|
||||
|
||||
--
|
||||
-- Name: domain_user_job_event_add_tracked_objects fk_rails_03ea351597; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -5449,6 +5553,9 @@ ALTER TABLE ONLY public.domain_twitter_tweets
|
||||
SET search_path TO "$user", public;
|
||||
|
||||
INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20250805045947'),
|
||||
('20250805044757'),
|
||||
('20250731035548'),
|
||||
('20250727173100'),
|
||||
('20250726051748'),
|
||||
('20250726051451'),
|
||||
|
||||
Reference in New Issue
Block a user