Skip to content

Commit cdffb28

Browse files
committed
title case case study
1 parent 92b41b8 commit cdffb28

File tree

4 files changed

+200
-202
lines changed

4 files changed

+200
-202
lines changed

hardware_store/README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ This sample dataset represents a chain of hardware stores managing their invento
66
%% https://mermaid.js.org/syntax/entityRelationshipDiagram.html
77
88
erDiagram
9-
%% https://mermaid.js.org/syntax/entityRelationshipDiagram.html
10-
11-
store_locations {
9+
"Store Locations" {
1210
BIGINT id PK
1311
string name
1412
string address
1513
}
1614
17-
customers {
15+
"Customers" {
1816
BIGINT id PK
1917
string first_name
2018
string last_name
@@ -23,7 +21,7 @@ erDiagram
2321
string address
2422
}
2523
26-
assets {
24+
"Assets" {
2725
BIGINT id PK
2826
string name
2927
string serial_number
@@ -34,7 +32,7 @@ erDiagram
3432
BIGINT store_id FK
3533
}
3634
37-
transactions {
35+
"Transactions" {
3836
BIGINT id PK
3937
BIGINT asset_id FK
4038
BIGINT customer_id FK
@@ -44,7 +42,7 @@ erDiagram
4442
string note
4543
}
4644
47-
rentals {
45+
"Rentals" {
4846
BIGINT id PK
4947
BIGINT transaction_id FK
5048
TIMESTAMP rental_start
@@ -56,11 +54,10 @@ erDiagram
5654
5755
%% Relationships
5856
%% See: https://mermaid.js.org/syntax/entityRelationshipDiagram.html#relationship-syntax
59-
assets ||--|{ store_locations : "store_id"
60-
transactions ||--|| assets : "asset_id"
61-
transactions ||--|{ customers : "customer_id"
62-
rentals ||--|| transactions : "transaction_id"
63-
57+
"Assets" ||--|{ "Store Locations" : "store_id"
58+
"Transactions" ||--|| "Assets" : "asset_id"
59+
"Transactions" ||--|{ "Customers" : "customer_id"
60+
"Rentals" ||--|| "Transactions" : "transaction_id"
6461
```
6562

6663

hardware_store/generate_data.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Helper function to clean values for COPY
1818
def clean_value(value):
1919
if value is None:
20-
return r"\N" # PostgreSQL NULL
20+
return r"\N"
2121
if isinstance(value, str):
2222
return value.replace("\t", " ").replace("\n", " ")
2323
return str(value)
@@ -81,11 +81,11 @@ def generate_rentals(transaction_ids):
8181
transaction_ids = list(range(1, NUM_TRANSACTIONS + 1))
8282

8383
tables = {
84-
"store_locations": generate_store_locations(),
85-
"customers": generate_customers(),
86-
"assets": generate_assets(store_ids),
87-
"transactions": generate_transactions(asset_ids, customer_ids),
88-
"rentals": generate_rentals(transaction_ids),
84+
"Store Locations": generate_store_locations(),
85+
"Customers": generate_customers(),
86+
"Assets": generate_assets(store_ids),
87+
"Transactions": generate_transactions(asset_ids, customer_ids),
88+
"Rentals": generate_rentals(transaction_ids),
8989
}
9090

9191
# Write to SQL file
@@ -95,7 +95,8 @@ def generate_rentals(transaction_ids):
9595
f.write('SET search_path="Hardware Store";\n\n')
9696

9797
for table_name, generator in tables.items():
98-
f.write(f"COPY {table_name} FROM stdin;\n")
98+
# Add quotes around table name since it contains spaces
99+
f.write(f'COPY "{table_name}" FROM stdin;\n')
99100
for row in generator:
100101
cleaned_row = "\t".join(map(clean_value, row))
101102
f.write(f"{cleaned_row}\n")

0 commit comments

Comments
 (0)