Skip to content

Commit

Permalink
Merge pull request #47 from gustavomm19/solution
Browse files Browse the repository at this point in the history
Solution
  • Loading branch information
tommygonzaleza authored Dec 19, 2023
2 parents 3474b99 + 558ed79 commit 22a8241
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 14 deletions.
Binary file modified diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions learn.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"syntax": "python",
"description" : "Use your recently adquired knowledge to build a data-model for your starwars blog",
"projectType": "project",
"solution": "https://github.com/breatheco-de/exercise-starwars-data-modeling/tree/solution",
"talents": [
{ "badge": "fully-committed", "points": 5 }
]
Expand Down
112 changes: 98 additions & 14 deletions src/models.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,116 @@
import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship, declarative_base
import uuid
from sqlalchemy import Column, ForeignKey, Integer, String, Numeric
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.types import ARRAY, TIMESTAMP
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
from eralchemy2 import render_er

Base = declarative_base()

class Person(Base):
__tablename__ = 'person'
# Here we define columns for the table person
class User(Base):
__tablename__ = 'user'

id = Column(Integer, primary_key=True)
user = Column(String(250))
password = Column(String(250))
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)

class Film(Base):
__tablename__ = 'film'

id = Column(Integer, primary_key=True)
characters = Column(String(250))
director = Column(String(250))
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)
episode_id = Column(Integer)
opening_crawl = Column(String(250))
producer = Column(String(250))
release_date = Column(String(250))
title = Column(String(250))
url = Column(String(250))

class Character(Base):
__tablename__ = 'character'
# Here we define columns for the table character
# Notice that each column is also a normal Python instance attribute.
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
birth_year = Column(String(250))
eye_color = Column(String(250))
gender = Column(String(250))
hair_color = Column(String(250))
height = Column(Integer)
homeworld = Column(String(250))
mass = Column(Integer)
skin_color = Column(String(250))
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)
films = Column(ARRAY(String(250)))
species = Column(ARRAY(String(250)))
url = Column(String(250))

class Address(Base):
__tablename__ = 'address'
class Specie(Base):
__tablename__ = 'specie'
# Here we define columns for the table address.
# Notice that each column is also a normal Python instance attribute.
id = Column(Integer, primary_key=True)
street_name = Column(String(250))
street_number = Column(String(250))
post_code = Column(String(250), nullable=False)
person_id = Column(Integer, ForeignKey('person.id'))
person = relationship(Person)
average_height = Column(Numeric)
average_lifespan = Column(Integer)
classification = Column(String(250))
designation = Column(String(250))
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)
eye_colors = Column(String(250))
hair_colors = Column(String(250))
homeworld = Column(String(250))
language = Column(String(250))
name = Column(String(250))
films = Column(ARRAY(String(250)))
people = Column(ARRAY(String(250)))
skin_colors = Column(String(250))
url = Column(String(250))

def to_dict(self):
return {}
class Planet(Base):
__tablename__ = 'planet'

id = Column(Integer, primary_key=True)
climate = Column(String(250))
diameter = Column(Numeric)
gravity = Column(Numeric)
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)
name = Column(String(250))
orbital_period = Column(Integer)
population = Column(Integer)
residents = Column(ARRAY(String(250)))
rotation_period = Column(Integer)
surface_water = Column(Integer)
terrain = Column(String(250))
url = Column(String(250))

class FavoritePlanet(Base):
__tablename__ = 'favorite_planet'

id = Column(Integer, primary_key=True)
user = relationship(User)
planet = relationship(Planet)
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)

class FavoriteCharacter(Base):
__tablename__ = 'favorite_character'

id = Column(Integer, primary_key=True)
user = relationship(User)
character = relationship(Character)
created = Column(TIMESTAMP, server_default=func.now(), nullable=False)
edited = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp(), nullable=False)
## Draw from SQLAlchemy base
render_er(Base, 'diagram.png')

0 comments on commit 22a8241

Please sign in to comment.