Skip to content

wcauchois/wednesday

Repository files navigation

Lots of React boilerplate stolen from https://github.com/workco/marvin.

Backend Stuff

Set up your virtualenv. Then,

python src/python/main.py

Alembic How-To

To check the current version of the database, run

alembic current

which should output something along the lines of

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
1c243796e75a (head)

To upgrade your database to the current version, simply run

alembic upgrade head

Alembic is currently configured to look at changes to src/python/models.py, and to create a new migration after updating the model we can, for example, run

alembic revision --autogenerate -m "add user_id column"

IMPORTANT NOTE: If you change a column name in the model, the autogenerated script will delete the old column and create a new one with the new name, thus deleting all the data. This behavior can apparently be edited in the generated script to just issue an alter table command (more info in the link below).

The above command will autogenerate a new migration script in alembic/versions which we should check for sanity. For example, this is our initial migration

"""added posts table

Revision ID: 1c243796e75a
Revises: 
Create Date: 2017-08-12 00:21:49.486189

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1c243796e75a'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.Column('parent_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['parent_id'], ['posts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


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

If something is off you can (I think?) just delete or edit the autogenerated file and try again. Then lastly, to commit the change the the database run

alembic upgrade head

Here is a tutorial with the basic commands.

Nginx Configuration

Aside from the normal proxy passthrough, you must configure Nginx for websockets, and to pass the X-Real-IP header used to determine the client's IP address.

Here's my configuration:

    server {
      listen 80;
      server_name yourserver.net;
      location /ws {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }
      location / {
        proxy_pass http://localhost:8080;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }
    }

See also https://easyengine.io/tutorials/nginx/forwarding-visitors-real-ip/.

(Note: I'm not sure if there's a way to avoid the duplication in that config, feel free to improve.)

Frontend Stuff

To get set up, run:

npm install
npm install -g webpack

Run webpack -w to watch for changes and auto-webpack.

Recommended to install the Immutable.js Object Formatter for Chrome devtools; it makes viewing Immutablejs objects sane (note this is based on this NPM package.

About

When you're working in this repo, it's always wednesday, my dudes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published