Skip to content

Commit 008df48

Browse files
committed
title case case study
1 parent 92b41b8 commit 008df48

File tree

4 files changed

+201
-200
lines changed

4 files changed

+201
-200
lines changed

hardware_store/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ This sample dataset represents a chain of hardware stores managing their invento
88
erDiagram
99
%% https://mermaid.js.org/syntax/entityRelationshipDiagram.html
1010
11-
store_locations {
11+
erDiagram
12+
"Store Locations" {
1213
BIGINT id PK
1314
string name
1415
string address
1516
}
1617
17-
customers {
18+
"Customers" {
1819
BIGINT id PK
1920
string first_name
2021
string last_name
@@ -23,7 +24,7 @@ erDiagram
2324
string address
2425
}
2526
26-
assets {
27+
"Assets" {
2728
BIGINT id PK
2829
string name
2930
string serial_number
@@ -34,7 +35,7 @@ erDiagram
3435
BIGINT store_id FK
3536
}
3637
37-
transactions {
38+
"Transactions" {
3839
BIGINT id PK
3940
BIGINT asset_id FK
4041
BIGINT customer_id FK
@@ -44,7 +45,7 @@ erDiagram
4445
string note
4546
}
4647
47-
rentals {
48+
"Rentals" {
4849
BIGINT id PK
4950
BIGINT transaction_id FK
5051
TIMESTAMP rental_start
@@ -56,11 +57,10 @@ erDiagram
5657
5758
%% Relationships
5859
%% 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-
60+
"Assets" ||--|{ "Store Locations" : "store_id"
61+
"Transactions" ||--|| "Assets" : "asset_id"
62+
"Transactions" ||--|{ "Customers" : "customer_id"
63+
"Rentals" ||--|| "Transactions" : "transaction_id"
6464
```
6565

6666

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)