Skip to content
Snippets Groups Projects
Commit 8e548f5f authored by DewanaGustavus's avatar DewanaGustavus
Browse files

chore: fix some seeding invalid data

parent 76374092
No related merge requests found
...@@ -8,6 +8,7 @@ PRODUCTS_LIMIT = 200 ...@@ -8,6 +8,7 @@ PRODUCTS_LIMIT = 200
# Get data from database # Get data from database
select_users = '''SELECT id select_users = '''SELECT id
FROM users FROM users
WHERE category = \'user\'
ORDER BY rand() ORDER BY rand()
LIMIT ''' + str(USERS_LIMIT) LIMIT ''' + str(USERS_LIMIT)
cursor.execute(select_users) cursor.execute(select_users)
...@@ -31,9 +32,10 @@ for i in range(CARTS_COUNT): ...@@ -31,9 +32,10 @@ for i in range(CARTS_COUNT):
user_index = randint(0, USERS_LIMIT - 1) user_index = randint(0, USERS_LIMIT - 1)
product_index = randint(0, PRODUCTS_LIMIT - 1) product_index = randint(0, PRODUCTS_LIMIT - 1)
while((users[user_index][0], products[product_index][0]) in existing_carts) : while((users[user_index][0], products[product_index][0]) in existing_carts
user_id = randint(0, USERS_LIMIT - 1) or products[product_index][1] == 0) :
product_id = randint(0, PRODUCTS_LIMIT - 1) user_index = randint(0, USERS_LIMIT - 1)
product_index = randint(0, PRODUCTS_LIMIT - 1)
user_id = users[user_index][0] user_id = users[user_index][0]
product_id = products[product_index][0] product_id = products[product_index][0]
...@@ -42,6 +44,7 @@ for i in range(CARTS_COUNT): ...@@ -42,6 +44,7 @@ for i in range(CARTS_COUNT):
carts_val = (user_id, product_id, quantity) carts_val = (user_id, product_id, quantity)
cursor.execute(carts_sql, carts_val) cursor.execute(carts_sql, carts_val)
existing_carts.append((user_id, product_id))
db.commit() db.commit()
print("Insertion success") print("Insertion success")
\ No newline at end of file
...@@ -8,7 +8,7 @@ for i in range(USER_COUNT): ...@@ -8,7 +8,7 @@ for i in range(USER_COUNT):
name = faker.name() name = faker.name()
username = name + "-" + str(i) username = name + "-" + str(i)
email = name + "@gmail.com" email = username + "@gmail.com"
password = name password = name
description = faker.text() description = faker.text()
category = "user" category = "user"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment