Skip to content

Commit b1191b8

Browse files
Rename database operations
1 parent 94cab67 commit b1191b8

File tree

5 files changed

+53
-47
lines changed

5 files changed

+53
-47
lines changed
File renamed without changes.

database-operations/create_table.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import logging
3+
from dotenv import load_dotenv
4+
from postgresql_client import PostgresSQLClient
5+
6+
# Configure logging
7+
logging.basicConfig(
8+
filename='log/create_table.log',
9+
level=logging.INFO,
10+
format='%(asctime)s - %(levelname)s - %(message)s',
11+
)
12+
13+
DB = os.getenv('POSTGRES_DB')
14+
USER = os.getenv('POSTGRES_USER')
15+
PASSWORD = os.getenv('POSTGRES_PASSWORD')
16+
17+
def create_products_table():
18+
pc = PostgresSQLClient(
19+
database=DB,
20+
user=USER,
21+
password=PASSWORD
22+
)
23+
24+
create_products_table_query = """
25+
DROP TABLE IF EXISTS products;
26+
CREATE TABLE products (
27+
id VARCHAR(50),
28+
name VARCHAR(255),
29+
description TEXT,
30+
original_price NUMERIC(10, 2),
31+
price NUMERIC(10, 2),
32+
fulfillment_type VARCHAR(50),
33+
brand VARCHAR(100),
34+
review_count INTEGER,
35+
rating_average NUMERIC(3, 2),
36+
favourite_count INTEGER,
37+
current_seller VARCHAR(255),
38+
number_of_images INTEGER,
39+
has_video BOOLEAN,
40+
category VARCHAR(100),
41+
quantity_sold INTEGER,
42+
discount NUMERIC(5, 2)
43+
);
44+
"""
45+
46+
try:
47+
pc.execute_query(create_products_table_query)
48+
logging.info("Table 'products' created successfully.")
49+
except Exception as e:
50+
logging.error(f"Failed to create table with error: {e}")
51+
52+
if __name__ == "__main__":
53+
create_products_table()

database_operations/create_table.py

-47
This file was deleted.

0 commit comments

Comments
 (0)