Find a file
2023-02-15 14:05:08 -06:00
.github/workflows Remove special cases for unused awards. 2022-11-09 20:37:04 -06:00
files Merge pull request #502 from justcool393/feature-award-feature-flag 2023-02-12 20:21:54 -06:00
migrations remove profile songs (ref #470) (#499) 2023-02-10 13:56:04 -06:00
thirdparty/sqlalchemy-easy-profile Make proper use of defaultdict. 2022-11-11 09:43:15 -06:00
util Remove explicit Docker container names to allow storing multiple in parallel. 2023-02-15 14:05:08 -06:00
.dockerignore Add a .dockerignore to make builds faster and smaller. 2022-05-14 02:12:55 -05:00
.editorconfig Add .editorconfig. 2022-05-08 23:14:58 -05:00
.gitattributes Convert text file line endings to LF. 2022-05-09 07:20:47 -05:00
.gitignore Fix some deprecations and factor out a helper function (#387) 2022-10-27 22:15:48 -05:00
dependabot.yml Add trailing LF to text files 2022-05-10 21:05:51 -04:00
docker-compose-operation.yml Remove explicit Docker container names to allow storing multiple in parallel. 2023-02-15 14:05:08 -06:00
docker-compose.yml Remove explicit Docker container names to allow storing multiple in parallel. 2023-02-15 14:05:08 -06:00
Dockerfile remove profile songs (ref #470) (#499) 2023-02-10 13:56:04 -06:00
env add SQLALCHEMY_WARN_20 env var to env 2023-02-08 15:50:51 -06:00
LICENSE Convert text file line endings to LF. 2022-05-09 07:20:47 -05:00
pg_hba.conf Add trailing LF to text files 2022-05-10 21:05:51 -04:00
poetry.lock remove profile songs (ref #470) (#499) 2023-02-10 13:56:04 -06:00
pyproject.toml remove profile songs (ref #470) (#499) 2023-02-10 13:56:04 -06:00
readme.md Minor README tweaks. 2023-02-12 20:22:16 -06:00
redis.conf Convert text file line endings to LF. 2022-05-09 07:20:47 -05:00
schema.sql Try restoring schema.sql 2022-05-22 21:29:10 -04:00
seed-db.sql Fixed a merge conflict that I somehow missed and removed marsey images from seed db 2022-05-22 08:27:13 -05:00
site_settings.json remove vestiges of fart mode 2022-11-07 03:30:31 -06:00
supervisord.conf.dev Fix: Changes to the User table cause unavoidable breakages in the Leaderboard system. 2022-11-21 10:09:17 -06:00
supervisord.conf.release Add an override value for the number of active cores to use. 2023-02-12 11:15:04 -06:00

Build status

This code runs https://www.themotte.org .

Installation (Windows/Linux/MacOS)

1 - Install a container runtime and the Docker commandline tools on your machine.

On Windows, Docker will pester you to pay them money for licensing. If you want something less proprietary, consider Container Desktop or Stevedore instead.

2 - Install Git. If you're on Windows and want a GUI, Github Desktop is quite nice.

3 - Run the following commands in the terminal or command line for first-time setup:

git clone https://github.com/themotte/rDrama/

cd rDrama

4 - Run the following command to start the site:

docker-compose up --build

The first time you do this, it will take a while. It'll be (much) faster next time.

4 - That's it! Visit localhost in your browser.

Code edits will be reflected (almost) immediately. If you make any setup changes or database changes, you'll need to ctrl-C the docker-compose status log and run docker-compose up --build again.

Run the E2E tests:

./util/test.py

Database Stuff

What is a migration?

Prior to the fork of themotte from rDrama, there were no database migrations, and the database schema was stored in schema.sql. Any time a column or such was added to a model, one hoped that the author remembered to update schema.sql to add that column. One of the first changes we made after forking this repo was to add database migrations using Alembic.

Database migrations are instructions for how to convert an out-of-date database into an up-to-date database. This can involve changing the schema, or changing data within the database.

Why use database migrations

Database migrations allow us to specify where data moves when there are schema changes. This is important when we're live -- if we rename the comments.ban_reason column to comments.reason_banned for naming consistency or whatever, and we do this by dropping the ban_reason column and adding a reason_banned column, we will lose all user data in that column. We don't want to do this. With migrations, we could instead specify that the operation in question should be a column rename, or, if the database engine does not support renaming columns, that we should do a three-step process of "add new column, migrate data over, drop old column".

Database schema change workflow

As an example, let's say we want to add a column is_flagged to the comments table.

  1. Update the Comment model in files/classes/comment.py
	from files.__main__ import Base
	class Comment(Base):
		__tablename__ = "comments"
		id = Column(Integer, primary_key=True)
		...
+		is_flagged = Column(Boolean, default=False, nullable=False)
  1. Autogenerate a migration with a descriptive message. To do this, run
./util/command.py db revision --autogenerate --message="add is_flagged field to comments"

This will create a migration in the migrations/versions directory with a name like migrations/versions/2022_05_23_05_38_40_9c27db0b3918_add_is_flagged_field_to_comments.py and content like

"""add is_flagged field to comments
Revision ID: 9c27db0b3918
Revises: 16d6335dd9a3
Create Date: 2022-05-23 05:38:40.398762+00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '9c27db0b3918'
down_revision = '16d6335dd9a3'
branch_labels = None
depends_on = None
def upgrade():
    op.add_column('comments', sa.Column('is_flagged', sa.Boolean(), nullable=False))
def downgrade():
    op.drop_column('comments', 'is_flagged')
  1. Examine the autogenerated migration to make sure that everything looks right (it adds the column you expected it to add and nothing else, all constraints are named, etc.) If you see a None in one of the alembic operations, e.g. op.create_foreign_key_something(None, 'usernotes', 'users', ['author_id']), please replace it with a descriptive string before you commit the migration.

  2. Restart the Docker container to make sure it works.

docker-compose up --build

So what's up with schema.sql, can I just change that?

No, please do not do that. Instead, please make a migration as described above.