diff --git a/diagram.png b/diagram.png index 281926cd..b5374a8b 100644 Binary files a/diagram.png and b/diagram.png differ diff --git a/learn.json b/learn.json index 48f7291b..3cd68d64 100644 --- a/learn.json +++ b/learn.json @@ -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 } ] diff --git a/src/models.py b/src/models.py index 2e483bfc..338d5ffd 100644 --- a/src/models.py +++ b/src/models.py @@ -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')