-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.py
More file actions
368 lines (351 loc) · 13.1 KB
/
Copy pathseed.py
File metadata and controls
368 lines (351 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
"""Optional seed script for local demos.
Creates one admin, two hosts, several guests, sample listings,
bookings, and reviews.
Usage (from the project root, with the virtual environment active):
python seed.py
"""
from datetime import date, timedelta
from app.database import SessionLocal
from app.models import Booking, BookingStatus, Favorite, Property, Review, User, UserRole
from app.services.auth_service import hash_password
DEFAULT_PASSWORD = "Password123!"
def seed() -> None:
db = SessionLocal()
try:
if db.query(User).first() is not None:
print("Database already contains users. Skipping seed.")
return
password_hash = hash_password(DEFAULT_PASSWORD)
admin = User(
name="Ava Sterling",
email="admin@stayfinder.com",
password_hash=password_hash,
role=UserRole.ADMIN,
)
maria = User(
name="Maria Lopez",
email="maria.host@stayfinder.com",
password_hash=password_hash,
role=UserRole.HOST,
)
james = User(
name="James Okonkwo",
email="james.host@stayfinder.com",
password_hash=password_hash,
role=UserRole.HOST,
)
emma = User(
name="Emma Chen",
email="emma.guest@stayfinder.com",
password_hash=password_hash,
role=UserRole.GUEST,
)
liam = User(
name="Liam Patel",
email="liam.guest@stayfinder.com",
password_hash=password_hash,
role=UserRole.GUEST,
)
sophia = User(
name="Sophia Rossi",
email="sophia.guest@stayfinder.com",
password_hash=password_hash,
role=UserRole.GUEST,
)
noah = User(
name="Noah Williams",
email="noah.guest@stayfinder.com",
password_hash=password_hash,
role=UserRole.GUEST,
)
db.add_all([admin, maria, james, emma, liam, sophia, noah])
db.flush()
properties = [
Property(
title="Sunny Venice Beach Apartment",
description=(
"Bright one-bedroom apartment two blocks from the boardwalk, "
"with a balcony, fast Wi-Fi, and a fully equipped kitchen."
),
city="Los Angeles",
country="USA",
address="18 Horizon Court, Venice",
price_per_night=185.0,
max_guests=3,
bedrooms=1,
bathrooms=1,
property_type="apartment",
image_url="https://images.unsplash.com/photo-1502672260266-1c1ef2d93688",
host_id=maria.id,
),
Property(
title="Hollywood Hills Villa",
description=(
"A modern villa with a private pool, canyon views, and space "
"for families or small groups visiting Los Angeles."
),
city="Los Angeles",
country="USA",
address="420 Mulholland Drive",
price_per_night=420.0,
max_guests=8,
bedrooms=4,
bathrooms=3,
property_type="villa",
image_url="https://images.unsplash.com/photo-1613490493576-7fde63acd811",
host_id=maria.id,
),
Property(
title="Cozy Downtown Loft",
description=(
"Industrial loft in the Arts District with exposed brick, "
"high ceilings, and walking access to restaurants and galleries."
),
city="Los Angeles",
country="USA",
address="900 Traction Avenue",
price_per_night=160.0,
max_guests=2,
bedrooms=1,
bathrooms=1,
property_type="apartment",
image_url="https://images.unsplash.com/photo-1505691938895-1758d7feb511",
host_id=maria.id,
),
Property(
title="Lake Tahoe Pine Cabin",
description=(
"Classic A-frame cabin surrounded by pines, with a wood stove, "
"hot tub, and a short drive to ski lifts and hiking trails."
),
city="South Lake Tahoe",
country="USA",
address="77 Cedar Ridge Road",
price_per_night=240.0,
max_guests=6,
bedrooms=3,
bathrooms=2,
property_type="cabin",
image_url="https://images.unsplash.com/photo-1449158743715-0a90ebb6d2d8",
host_id=maria.id,
),
Property(
title="Napa Valley Garden House",
description=(
"Quiet house among vineyards with a wraparound porch, "
"outdoor dining, and easy access to tasting rooms."
),
city="Napa",
country="USA",
address="12 Silverado Lane",
price_per_night=310.0,
max_guests=5,
bedrooms=3,
bathrooms=2,
property_type="house",
image_url="https://images.unsplash.com/photo-1564013799919-ab600027ffc6",
host_id=maria.id,
),
Property(
title="Santa Monica Boutique Suite",
description=(
"Hotel-style suite near the pier with daily housekeeping, "
"a rooftop lounge, and ocean-view breakfast."
),
city="Santa Monica",
country="USA",
address="1550 Ocean Avenue",
price_per_night=275.0,
max_guests=2,
bedrooms=1,
bathrooms=1,
property_type="hotel",
image_url="https://images.unsplash.com/photo-1566073771259-6a8506099945",
host_id=maria.id,
),
Property(
title="Manhattan Skyline Studio",
description=(
"Compact studio in Midtown with skyline views, a workspace, "
"and subway access to every major neighborhood."
),
city="New York",
country="USA",
address="350 West 42nd Street",
price_per_night=195.0,
max_guests=2,
bedrooms=0,
bathrooms=1,
property_type="apartment",
image_url="https://images.unsplash.com/photo-1493809842364-78817add7ffb",
host_id=james.id,
),
Property(
title="Brooklyn Brownstone Floor",
description=(
"Entire garden floor of a historic brownstone, with a private "
"patio, tall windows, and a chef's kitchen."
),
city="New York",
country="USA",
address="88 Park Place, Brooklyn",
price_per_night=260.0,
max_guests=4,
bedrooms=2,
bathrooms=1,
property_type="house",
image_url="https://images.unsplash.com/photo-1560448204-e02f11c3d0e2",
host_id=james.id,
),
Property(
title="Tuscany Countryside Villa",
description=(
"Stone villa outside Florence with olive trees, a pool, "
"and wide views over the Chianti hills."
),
city="Florence",
country="Italy",
address="Via delle Colline 24, Greve in Chianti",
price_per_night=380.0,
max_guests=10,
bedrooms=5,
bathrooms=4,
property_type="villa",
image_url="https://images.unsplash.com/photo-1523217582562-09d0def993a6",
host_id=james.id,
),
Property(
title="Scottish Highlands Cabin",
description=(
"Remote cabin near Inverness with a peat fireplace, "
"mountain views, and dark skies for stargazing."
),
city="Inverness",
country="United Kingdom",
address="Glen Affric Lodge Road",
price_per_night=170.0,
max_guests=4,
bedrooms=2,
bathrooms=1,
property_type="cabin",
image_url="https://images.unsplash.com/photo-1510798831971-661eb04b3739",
host_id=james.id,
),
]
db.add_all(properties)
db.flush()
venice, hills, _loft, tahoe, _napa, _suite, manhattan, brooklyn, tuscany, highlands = properties
today = date.today()
bookings = [
Booking(
property_id=venice.id,
guest_id=emma.id,
check_in=today - timedelta(days=40),
check_out=today - timedelta(days=35),
guests_count=2,
total_price=925.0,
status=BookingStatus.COMPLETED,
),
Booking(
property_id=brooklyn.id,
guest_id=emma.id,
check_in=today - timedelta(days=20),
check_out=today - timedelta(days=16),
guests_count=3,
total_price=1040.0,
status=BookingStatus.COMPLETED,
),
Booking(
property_id=tuscany.id,
guest_id=liam.id,
check_in=today - timedelta(days=60),
check_out=today - timedelta(days=53),
guests_count=6,
total_price=2660.0,
status=BookingStatus.COMPLETED,
),
Booking(
property_id=manhattan.id,
guest_id=liam.id,
check_in=today + timedelta(days=14),
check_out=today + timedelta(days=18),
guests_count=2,
total_price=780.0,
status=BookingStatus.CONFIRMED,
),
Booking(
property_id=tahoe.id,
guest_id=sophia.id,
check_in=today + timedelta(days=21),
check_out=today + timedelta(days=25),
guests_count=4,
total_price=960.0,
status=BookingStatus.PENDING,
),
Booking(
property_id=hills.id,
guest_id=noah.id,
check_in=today + timedelta(days=10),
check_out=today + timedelta(days=13),
guests_count=5,
total_price=1260.0,
status=BookingStatus.CANCELLED,
),
Booking(
property_id=highlands.id,
guest_id=noah.id,
check_in=today + timedelta(days=45),
check_out=today + timedelta(days=50),
guests_count=2,
total_price=850.0,
status=BookingStatus.PENDING,
),
]
db.add_all(bookings)
db.flush()
db.add_all(
[
Review(
property_id=venice.id,
user_id=emma.id,
rating=5,
comment="Walkable, clean, and the balcony sunsets were perfect.",
),
Review(
property_id=brooklyn.id,
user_id=emma.id,
rating=4,
comment="Loved the patio. A little street noise at night, but a great stay.",
),
Review(
property_id=tuscany.id,
user_id=liam.id,
rating=5,
comment="The villa and pool made our family trip unforgettable.",
),
]
)
db.add_all(
[
Favorite(user_id=emma.id, property_id=tuscany.id),
Favorite(user_id=liam.id, property_id=tahoe.id),
Favorite(user_id=sophia.id, property_id=venice.id),
]
)
db.commit()
print("Seed data created successfully.")
print("Sample accounts (password for all: Password123!)")
print(" admin@stayfinder.com (admin)")
print(" maria.host@stayfinder.com (host)")
print(" james.host@stayfinder.com (host)")
print(" emma.guest@stayfinder.com (guest)")
print(" liam.guest@stayfinder.com (guest)")
print(" sophia.guest@stayfinder.com (guest)")
print(" noah.guest@stayfinder.com (guest)")
except Exception:
db.rollback()
raise
finally:
db.close()
if __name__ == "__main__":
seed()