Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
app.run(host=app.config['IP'], port=app.config['PORT'], threaded = False)

application = app

4 changes: 4 additions & 0 deletions config.env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
# CSH_LDAP credentials
LDAP_BIND_DN = os.environ.get("LDAP_BIND_DN", default="cn=quotefault,ou=Apps,dc=csh,dc=rit,dc=edu")
LDAP_BIND_PW = os.environ.get("LDAP_BIND_PW", default=None)
MAIL_USERNAME = os.environ.get("MAIL_USERNAME", default=None)
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD", default=None)
MAIL_SERVER = os.environ.get("MAIL_SERVER", default=None)
MAIL_PORT = os.environ.get("MAIL_PORT", default=465)
MAIL_USE_SSL = True

4 changes: 4 additions & 0 deletions config.sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
# CSH_LDAP credentials
LDAP_BIND_DN = ''
LDAP_BIND_PW = ''
MAIL_USERNAME = ''
MAIL_PASSWORD = ''
MAIL_SERVER = ''
MAIL_PORT = 465
MAIL_USE_SSL = True

12 changes: 12 additions & 0 deletions migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## What are Alembic and migrations?
Migrations give a versioned history of changes to the SQL Schema for this project.
A `revision` or `migration` defines changes to the structure of the database (such as adding/dropping tables or columns), as well as procedures for migrating existing data to the new structure. Migrations allow for safe(ish) rollbacks, and make it easier to make incremental changes to the database.

## Applying migrations
Once you have your db URI in `config.py`, run `flask db upgrade` to bring the db up to the latest revision.

## Creating new revisions
When you change `models.py`, you'll need to make a new migration.
Run `flask db revision -m "<descriptive title>"` to autogenerate one.
You should go manually inspect the created revision to make sure it does what you expect.
Once you've got your changes all set, be sure to commit the migration file in the same commit as your changes to `models.py`
75 changes: 75 additions & 0 deletions migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = migrations

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# timezone to use when rendering the date
# within the migration file as well as the filename.
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; this defaults
# to migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat migrations/versions

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = driver://user:pass@localhost/dbname


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

91 changes: 91 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from __future__ import with_statement

import logging
from logging.config import fileConfig

from flask import current_app

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
Comment thread
WillNilges marked this conversation as resolved.
config.set_main_option(
'sqlalchemy.url',
str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')

connectable = current_app.extensions['migrate'].db.engine

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

25 changes: 25 additions & 0 deletions migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}

25 changes: 25 additions & 0 deletions migrations/versions/3b8a4c7fbcc2_report_reviewed_column_added.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Report Reviewed Column Added

Revision ID: 3b8a4c7fbcc2
Revises: 76898f8ac346
Create Date: 2021-11-07 22:31:04.835460

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '3b8a4c7fbcc2'
down_revision = '76898f8ac346'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('report', sa.Column('reviewed', sa.Boolean(), nullable=False, default=False))


def downgrade():
op.drop_column('report', 'reviewed')

Comment thread
mxmeinhold marked this conversation as resolved.
57 changes: 57 additions & 0 deletions migrations/versions/4f95c173f1d9_initial_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Initial schema

Revision ID: 4f95c173f1d9
Revises:
Create Date: 2021-04-23 01:02:40.157049

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '4f95c173f1d9'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('api_key',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('hash', sa.String(length=64), nullable=True),
sa.Column('owner', sa.String(length=80), nullable=True),
sa.Column('reason', sa.String(length=120), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('hash'),
sa.UniqueConstraint('owner', 'reason', name='unique_key')
)
op.create_table('quote',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('submitter', sa.String(length=80), nullable=False),
sa.Column('quote', sa.String(length=200), nullable=False),
sa.Column('speaker', sa.String(length=50), nullable=False),
sa.Column('quote_time', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('quote')
)
op.create_table('vote',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('quote_id', sa.Integer(), nullable=True),
sa.Column('voter', sa.String(length=200), nullable=False),
sa.Column('direction', sa.Integer(), nullable=False),
sa.Column('updated_time', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['quote_id'], ['quote.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('vote')
op.drop_table('quote')
op.drop_table('api_key')
# ### end Alembic commands ###

34 changes: 34 additions & 0 deletions migrations/versions/76898f8ac346_add_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add reports

Revision ID: 76898f8ac346
Revises: 4f95c173f1d9
Create Date: 2021-04-23 01:18:03.934757

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '76898f8ac346'
down_revision = '4f95c173f1d9'
branch_labels = None
depends_on = None


def upgrade():
op.create_table('report',
sa.Column('id', sa.Integer(), nullable=False, autoincrement=True),
sa.Column('quote_id', sa.Integer(), nullable=False),
sa.Column('reporter', sa.Text(), nullable=False),
sa.Column('reason', sa.Text(), nullable=False),
sa.ForeignKeyConstraint(['quote_id'], ['quote.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.add_column('quote', sa.Column('hidden', sa.Boolean(), nullable=False, default=False))


def downgrade():
op.drop_column('quote', 'hidden')
op.drop_table('report')

Loading