Skip to content

Commit

Permalink
[Fixes🦾] Add db Column UUID to id fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
[esekyi] committed Aug 25, 2024
1 parent 6fed586 commit 738d242
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/models/category.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from app import db
from datetime import datetime
import uuid
from sqlalchemy.dialects.postgresql import UUID


class Category(db.Model):
id = db.Column(db.String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = db.Column(db.String(80), unique=True, nullable=False)
description = db.Column(db.Text)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
Expand Down
11 changes: 6 additions & 5 deletions app/models/comment.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from app import db
from datetime import datetime
import uuid
from sqlalchemy.dialects.postgresql import UUID


class Comment(db.Model):
id = db.Column(db.String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
id = db.Column(UUID(as_uuid=True), primary_key=True,
default=uuid.uuid4)
text = db.Column(db.Text, nullable=False)
user_id = db.Column(db.String(36), db.ForeignKey(
'user.id'), nullable=False)
recipe_id = db.Column(db.String(36), db.ForeignKey(
user_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('user.id'), nullable=False)
recipe_id = db.Column(UUID(as_uuid=True), db.ForeignKey(
'recipe.id'), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(
Expand Down
7 changes: 4 additions & 3 deletions app/models/ingredient.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from app import db
from datetime import datetime
import uuid
from sqlalchemy.dialects.postgresql import UUID


class Ingredient(db.Model):
id = db.Column(db.String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
id = db.Column(UUID(as_uuid=True), primary_key=True,
default=uuid.uuid4)
name = db.Column(db.String(120), nullable=False)
quantity = db.Column(db.String(50), nullable=False)
recipe_id = db.Column(db.String(36), db.ForeignKey(
recipe_id = db.Column(UUID(as_uuid=True), db.ForeignKey(
'recipe.id'), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(
Expand Down
9 changes: 5 additions & 4 deletions app/models/recipe.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from app import db
from datetime import datetime
import uuid
from sqlalchemy.dialects.postgresql import UUID


class Recipe(db.Model):
id = db.Column(db.String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
id = db.Column(UUID(as_uuid=True), primary_key=True,
default=uuid.uuid4)
title = db.Column(db.String(120), nullable=False)
description = db.Column(db.Text, nullable=False)
instructions = db.Column(db.Text, nullable=False)
prep_time = db.Column(db.Integer) # in minutes
cook_time = db.Column(db.Integer) # in minutes
servings = db.Column(db.Integer)
image_url = db.Column(db.String(255))
category_id = db.Column(db.String(36), db.ForeignKey(
category_id = db.Column(UUID(as_uuid=True), db.ForeignKey(
'category.id'), nullable=False)
user_id = db.Column(db.String(36), db.ForeignKey(
user_id = db.Column(UUID(as_uuid=True), db.ForeignKey(
'user.id'), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(
Expand Down
9 changes: 6 additions & 3 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
from datetime import datetime
import uuid
from flask_login import UserMixin
from sqlalchemy.dialects.postgresql import UUID


class User(db.Model, UserMixin):
id = db.Column(db.String(36), primary_key=True,
default=lambda: str(uuid.uuid4()))
id = db.Column(UUID(as_uuid=True), primary_key=True,
default = uuid.uuid4)
first_name = db.Column(db.String(50), nullable=False)
last_name = db.Column(db.String(50), nullable=False)
username = db.Column(db.String(80), unique=True, nullable=False, index=True)
email = db.Column(db.String(120), unique=True, nullable=False, index=True)
password_hash = db.Column(db.String(128), nullable=False)
password_hash = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
Expand Down

0 comments on commit 738d242

Please sign in to comment.