Skip to content

Instantly share code, notes, and snippets.

@mazz
Created January 12, 2017 03:30
Show Gist options
  • Save mazz/53581e919c182a61d28883bc235e75bb to your computer and use it in GitHub Desktop.
Save mazz/53581e919c182a61d28883bc235e75bb to your computer and use it in GitHub Desktop.
websauna admin does not detect audiostream table
"""Place your SQLAlchemy models in this file."""
import datetime
from uuid import uuid4
from sqlalchemy import Column, Unicode, String, Integer, ForeignKey, UnicodeText
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from websauna.system.model.meta import Base
from websauna.system.model.columns import UTCDateTime
from websauna.utils.time import now
class Media(Base):
#: The table in the database
__tablename__ = "media"
#: Database primary key for the row (running counter)
id = Column(Integer, autoincrement=True, primary_key=True)
#: Publicly exposed non-guessable
uuid = Column(UUID(as_uuid=True), default=uuid4)
#: url
url = Column(Unicode(384), default=None)
#: title of content
title = Column(Unicode(384), default=None)
#: duration of content
duration = Column(String(8), default=None)
#: description of content
description = Column(UnicodeText, default=None)
#: When this content was published
published_at = Column(UTCDateTime, default=None)
#: Relationship mapping between media and audiostream.
#: Each audiostream can have only media.
#: Deleting media deletes its audiostreams.
audiostreams = relationship("AudioStream",
back_populates="media",
lazy="dynamic",
cascade="all, delete-orphan",
single_parent=True)
def is_recent(self):
return self.published_at >= now() - datetime.timedelta(days=1)
def __repr__(self):
return "#{}: {}".format(self.id, self.url)
def __str__(self):
"""Python default and admin UI string presentation."""
return self.url
class AudioStream(Base):
#: The table in the database
__tablename__ = "audiostream"
#: Database primary key for the row (running counter)
id = Column(Integer, autoincrement=True, primary_key=True)
#: Publicly exposed non-guessable id
uuid = Column(UUID(as_uuid=True), default=uuid4)
#: What the user sees for this audiostream
filepath = Column(Unicode(512), default=None)
bitrate = Column(String(4), default=None)
extension = Column(String(4), default=None)
#: download url
# url = Column(Unicode(768), default=None)
#: Which question this choice is part of
media_id = Column(Integer, ForeignKey('media.id'))
media = relationship("Media", back_populates="audiostreams")
def __repr__(self):
"""Shell and debugger presentation."""
return "#{}@{}".format(self.extension, self.bitrate)
def __str__(self):
"""Python default and admin UI string presentation."""
return "#{}@{}".format(self.extension, self.bitrate)
@mazz
Copy link
Author

mazz commented Jan 12, 2017

(websauna_env)~/webapp/websauna_env/hearit (master ✘)✖✹✭ ᐅ ws-alembic -c hearit/conf/development.ini -x packages=all revision --auto -m "Initial migration"
configure_tasks
tasks scan!
configure_models
[22:24:31] [websauna.system.core.redis create_redis] Creating a new Redis connection pool. Process 7374, thread MainThread, max_connections 16
[22:24:31] [websauna.system.devop.alembic parse_allowed_packages] Considering migrations for models in Python packages ['all']
[22:24:31] [websauna.system.devop.alembic run_alembic] Starting online migration engine on database connection Engine(postgresql://hearit:***@localhost:5432/hearit_dev) version history table alembic_history_hearit
[22:24:31] [alembic.runtime.migration __init__] Context impl PostgresqlImpl.
[22:24:31] [alembic.runtime.migration __init__] Will assume transactional DDL.
[22:24:31] [alembic.autogenerate.compare _compare_tables] Detected added table 'group'
[22:24:31] [alembic.autogenerate.compare _compare_tables] Detected added table 'media'
[22:24:31] [alembic.autogenerate.compare _compare_tables] Detected added table 'user_activation'
[22:24:31] [alembic.autogenerate.compare _compare_tables] Detected added table 'audiostream'
[22:24:31] [alembic.autogenerate.compare _compare_tables] Detected added table 'users'
[22:24:31] [alembic.autogenerate.compare _compare_tables] Detected added table 'usergroup'
[22:24:31] [websauna.system.devop.alembic run_alembic] All done
  Generating /Users/maz/webapp/websauna_env/hearit/alembic/versions/545fcfcd2e65_initial_migration.py ... done
(websauna_env)~/webapp/websauna_env/hearit (master ✘)✖✹✭ ᐅ ws-alembic -c hearit/conf/development.ini -x packages=all upgrade head                          
configure_tasks
tasks scan!
configure_models
[22:24:56] [websauna.system.core.redis create_redis] Creating a new Redis connection pool. Process 7433, thread MainThread, max_connections 16
[22:24:56] [websauna.system.devop.alembic parse_allowed_packages] Considering migrations for models in Python packages ['all']
[22:24:56] [websauna.system.devop.alembic run_alembic] Starting online migration engine on database connection Engine(postgresql://hearit:***@localhost:5432/hearit_dev) version history table alembic_history_hearit
[22:24:56] [alembic.runtime.migration __init__] Context impl PostgresqlImpl.
[22:24:56] [alembic.runtime.migration __init__] Will assume transactional DDL.
[22:24:56] [alembic.runtime.migration run_migrations] Running upgrade  -> 545fcfcd2e65, Initial migration
[22:24:56] [alembic.runtime.migration update_to_step] new branch insert 545fcfcd2e65
[22:24:56] [websauna.system.devop.alembic run_alembic] All done

@mazz
Copy link
Author

mazz commented Jan 12, 2017

screen shot 2017-01-11 at 22 29 11

@mazz
Copy link
Author

mazz commented Jan 12, 2017

screen shot 2017-01-11 at 22 29 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment