Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dam2452 committed Jan 29, 2025
1 parent 6f2f2e9 commit b875e4b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/RANCZO-WIDEO/
/bot/RANCZO-TRANSKRYPCJE/
/bot/RANCZO-WIDEO/
/bot/KIEPSCY-WIDEO/
/bot/KIEPSCY-TRANSKRYPCJE/
/OLD/
/STARE RANCZ WIDEO/
/passwords.env
Expand Down
8 changes: 8 additions & 0 deletions bot/database/database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,25 @@ async def init_pool(
database: Optional[str] = None,
user: Optional[str] = None,
password: Optional[str] = None,
schema: Optional[str] = None,
):
config = {
"host": host or settings.POSTGRES_HOST,
"port": port or settings.POSTGRES_PORT,
"database": database or settings.POSTGRES_DB,
"user": user or settings.POSTGRES_USER,
"password": password or settings.POSTGRES_PASSWORD,
"server_settings": {
"search_path": schema,
},

}

DatabaseManager.pool = await asyncpg.create_pool(**config)




@staticmethod
def get_db_connection():
return DatabaseManager.pool.acquire()
Expand Down
15 changes: 12 additions & 3 deletions bot/database/init_db.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
SET TIME ZONE 'GMT-2';

CREATE EXTENSION IF NOT EXISTS pg_trgm;

CREATE TABLE IF NOT EXISTS user_profiles (
user_id BIGINT PRIMARY KEY,
username TEXT UNIQUE,
Expand Down Expand Up @@ -101,7 +99,6 @@ CREATE TABLE IF NOT EXISTS search_history (
);

CREATE INDEX IF NOT EXISTS idx_search_history_timestamp ON search_history(timestamp);
CREATE INDEX IF NOT EXISTS idx_search_history_quote ON search_history USING gin(quote gin_trgm_ops);

CREATE TABLE IF NOT EXISTS last_clips (
id SERIAL PRIMARY KEY,
Expand Down Expand Up @@ -159,6 +156,18 @@ ON common_messages (key);

CREATE INDEX IF NOT EXISTS idx_ranczo_messages_key
ON ranczo_messages (key);
CREATE TABLE IF NOT EXISTS kiepscy_messages (
handler_name TEXT NOT NULL,
key TEXT NOT NULL,
message TEXT NOT NULL,
PRIMARY KEY (handler_name, key)
);

CREATE INDEX IF NOT EXISTS idx_kiepscy_messages_key
ON kiepscy_messages (key);

CREATE INDEX IF NOT EXISTS idx_kiepscy_messages_handler_name
ON kiepscy_messages (handler_name);

CREATE INDEX IF NOT EXISTS idx_common_messages_handler_name
ON common_messages (handler_name);
Expand Down
1 change: 1 addition & 0 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def on_startup() -> None:
database=settings.POSTGRES_DB,
user=settings.POSTGRES_USER,
password=settings.POSTGRES_PASSWORD,
schema=settings.POSTGRES_SCHEMA,
)
await DatabaseManager.init_db()

Expand Down
1 change: 1 addition & 0 deletions bot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Settings(BaseSettings):
POSTGRES_HOST: str = Field(...)
POSTGRES_PORT: int = Field(...)
POSTGRES_DB: str = Field(...)
POSTGRES_SCHEMA: str = Field(...)

SPECIALIZED_TABLE: str = Field(...)

Expand Down

0 comments on commit b875e4b

Please sign in to comment.