-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
421 additions
and
938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1 @@ | ||
API_KEY=your_api_key_here | ||
|
||
FIREBASE_API_KEY=your_firebase_api_key_here | ||
FIREBASE_DATABASE_URL=your_firebase_database_url_here | ||
FIREBASE_APP_ID=your_firebase_app_id_here | ||
FIREBASE_AUTH_DOMAIN=your_firebase_auth_domain_here | ||
FIREBASE_CLIENT_EMAIL=your_firebase_client_email_here | ||
FIREBASE_CLIENT_ID=your_firebase_client_id_here | ||
FIREBASE_CLIENT_X509_CERT_URL=your_firebase_client_x509_cert_url_here | ||
FIREBASE_MESSAGING_SENDER_ID=your_firebase_messaging_sender_id_here | ||
FIREBASE_PRIVATE_KEY=your_firebase_private_key_here | ||
FIREBASE_PRIVATE_KEY_ID=your_firebase_private_key_id_here | ||
FIREBASE_PROJECT_ID=your_firebase_project_id_here | ||
FIREBASE_STORAGE_BUCKET=your_firebase_storage_bucket_here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sqlite3 | ||
|
||
# Path to the schema file | ||
SCHEMA_FILE = "./api/database/schema.sql" | ||
|
||
# Path to the SQLite database file (it will be created if it doesn't exist) | ||
DATABASE_PATH = "./api/database/database.db" | ||
|
||
|
||
def execute(query, params=(), fetchall=False): | ||
conn = sqlite3.connect(DATABASE_PATH) | ||
conn.row_factory = sqlite3.Row # Enables row access by column name | ||
cursor = conn.cursor() | ||
|
||
if not fetchall: | ||
data = cursor.execute(query, params).fetchone() | ||
else: | ||
data = cursor.execute(query, params).fetchall() | ||
|
||
conn.commit() | ||
conn.close() | ||
|
||
return data | ||
|
||
|
||
def connect(): | ||
try: | ||
# Connect to SQLite database | ||
conn = sqlite3.connect(DATABASE_PATH) | ||
cursor = conn.cursor() | ||
print("Connected to the database successfully!") | ||
|
||
# Read the schema.sql file | ||
with open(SCHEMA_FILE, "r") as file: | ||
schema_sql = file.read() | ||
# Execute the schema SQL script | ||
cursor.executescript(schema_sql) | ||
print("Schema executed successfully!") | ||
|
||
# Commit changes and close the connection | ||
conn.commit() | ||
conn.close() | ||
print("Database connection closed.") | ||
except Exception as e: | ||
print(f"An error occurred: {e}") |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- Table to store client information | ||
CREATE TABLE IF NOT EXISTS Client ( | ||
client_id INTEGER PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
phone VARCHAR(20), | ||
address VARCHAR(255) | ||
); | ||
|
||
-- Table to store invoice information | ||
CREATE TABLE IF NOT EXISTS Invoice ( | ||
invoice_id INTEGER PRIMARY KEY, | ||
client_id INTEGER NOT NULL, | ||
reference VARCHAR(50) NOT NULL, | ||
created_at DATE NOT NULL, | ||
total_price DECIMAL(10, 2) NOT NULL, | ||
FOREIGN KEY (client_id) REFERENCES Client(client_id) | ||
); | ||
|
||
-- Table to store product information | ||
CREATE TABLE IF NOT EXISTS Product ( | ||
product_id INTEGER PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
unit_price DECIMAL(10, 2) NOT NULL | ||
); | ||
|
||
-- Table to link products and invoices | ||
CREATE TABLE IF NOT EXISTS InvoiceProduct ( | ||
invoice_product_id INTEGER PRIMARY KEY, | ||
invoice_id INTEGER NOT NULL, | ||
product_id INTEGER NOT NULL, | ||
quantity INTEGER NOT NULL, | ||
total_price DECIMAL(10, 2) NOT NULL, | ||
FOREIGN KEY (invoice_id) REFERENCES Invoice(invoice_id), | ||
FOREIGN KEY (product_id) REFERENCES Product(product_id) | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import sqlite3 | ||
from datetime import datetime | ||
|
||
from config import DATABASE_PATH, connect, execute | ||
|
||
|
||
def seed_database(): | ||
try: | ||
# Insert data into the Client table | ||
execute( | ||
""" | ||
INSERT INTO Client (client_id, name, phone, address) | ||
VALUES | ||
(1, 'John Smith', '+33 xx3 x21 63x', 'ABC Street'), | ||
(2, 'Davison Star', '+33 7xx 93x x05', 'DEF Street'); | ||
""" | ||
) | ||
|
||
# Insert data into the Product table | ||
execute( | ||
""" | ||
INSERT INTO Product (product_id, name, unit_price) | ||
VALUES | ||
(1, 'Product A', 2500.00), | ||
(2, 'Product B', 1500.00), | ||
(3, 'Product C', 3500.00); | ||
""" | ||
) | ||
|
||
# Insert data into the Invoice table with formatted dates | ||
execute( | ||
""" | ||
INSERT INTO Invoice (invoice_id, client_id, reference, created_at, total_price) | ||
VALUES | ||
(1, 1, 'INV001', ?, 5000.00), | ||
(2, 2, 'INV002', ?, 3500.00); | ||
""", | ||
( | ||
datetime(2025, 1, 11, 10, 0, 0, 123456).strftime( | ||
"%Y-%m-%dT%H:%M:%S.%fZ" | ||
), | ||
datetime(2025, 1, 12, 15, 30, 0, 654321).strftime( | ||
"%Y-%m-%dT%H:%M:%S.%fZ" | ||
), | ||
), | ||
) | ||
|
||
# Insert data into the InvoiceProduct table (relating products to invoices) | ||
execute( | ||
""" | ||
INSERT INTO InvoiceProduct (invoice_product_id, invoice_id, product_id, quantity, total_price) | ||
VALUES | ||
(1, 1, 1, 1, 2500.00), | ||
(2, 1, 2, 1, 1500.00), | ||
(3, 2, 2, 1, 1500.00), | ||
(4, 2, 3, 1, 3500.00); | ||
""" | ||
) | ||
|
||
print("Database seeded successfully!") | ||
|
||
except sqlite3.Error as e: | ||
print(f"Error occurred while seeding database: {e}") | ||
|
||
|
||
# Run the seed function | ||
if __name__ == "__main__": | ||
# Delete db if exists | ||
if os.path.exists(DATABASE_PATH): | ||
os.remove(DATABASE_PATH) | ||
|
||
connect() | ||
seed_database() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.