rDrama/files/classes/__init__.py
faul-sname 4892b58d10
Add migrations using alembic.
* #39 Add Flask-Migrate dep

* #39 Make it such that flask db init can run

https://github.com/miguelgrinberg/Flask-Migrate/issues/196#issuecomment-381343393

* Run flask db init, update migrations.env, commit artifacts

* Set up a script such that you can `docker-compose exec files bash -c 'cd /service; FLASK_APP="files/cli:app" flask '` and have it do whatever flask thing you want

* Fix circular dependency

* import * is evil

* Initial alembic migration, has issues with constraints and nullable columns

* Bring alts table up to date with alembic autogenerate

* Rerun flask db revision autogenerate

* Bring award_relationships table up to date with alembic autogenerate

* [#39/alembic] files/classes/__init__.py is evil but is at least explicitly evil now

* #39 fix model in files/classes/badges.py

* #39 fix model in files/classes/domains.py and files/classes/clients.py

* #39 fix models: comment saves, comment flags

* #39 fix models: comments

* Few more imports

* #39 columns that are not nullable should be flagged as not nullable

* #39 Add missing indexes to model defs

* [#39] add missing unique constraints to model defs

* [#39] Temporarily undo any model changes which cause the sqlalchemy model to be out of sync with the actual dump

* #39 Deforeignkeyify the correct column to make alembic happy

* #39 flask db revision --autogenerate now creates an empty migration

* #39 Migration format such that files are listed in creation order

* #39 Better first revision

* #39 Revert the model changes that were required to get to zero differences between db revision --autogenerate and the existing schema

* #39 The first real migration

* #39 Ensure that foreign key constraints are named in migration

* #39 Alembic migrations for FK constraints, column defs

* [#39] Run DB migrations before starting tests

* [#39] New test to ensure migrations are up to date

* [#39] More descriptive test failure message

* Add -T flag to docker-compose exec

* [#39] Run alembic migrations when starting the container
2022-05-17 18:55:17 -05:00

95 lines
4 KiB
Python

################################################################
# WARNING! THIS FILE IS EVIL. #
################################################################
# Previously, this file had a series of #
# from .alts import * #
# from .award import * #
# from .badges import * #
# and so on in that fashion. That means that anywhere that #
# from files.classes import * #
# (and there were a lot of places like that) got anything #
# was imported for any model imported. So if you, for example, #
# removed #
# from secrets import token_hex #
# from files/classes/user.py, the registration page would #
# break because files/routes/login.py did #
# from files.classes import * #
# in order to get the token_hex function rather than #
# importing it with something like #
# from secrets import token_hex #
# #
# Anyway, not fixing that right now, but in order to #
# what needed to be imported here such that #
# from files.classes import * #
# still imported the same stuff as before I ran the following: #
# $ find files/classes -type f -name '*.py' \ #
# -exec grep import '{}' ';' \ #
# | grep 'import' \ #
# | grep -v 'from [.]\|__init__\|from files.classes' \ #
# | sed 's/^[^:]*://g' \ #
# | sort \ #
# | uniq #
# and then reordered the list such that import * did not stomp #
# over stuff that had been explicitly imported. #
################################################################
# First the import * from places which don't go circular
from sqlalchemy import *
from flask import *
# Then everything except what's in files.*
import pyotp
import random
import re
import time
from copy import deepcopy
from datetime import datetime
from flask import g
from flask import render_template
from json import loads
from math import floor
from os import environ
from os import environ, remove, path
from random import randint
from secrets import token_hex
from sqlalchemy.orm import deferred, aliased
from sqlalchemy.orm import relationship
from sqlalchemy.orm import relationship, deferred
from urllib.parse import urlencode, urlparse, parse_qs
from urllib.parse import urlparse
# It is now safe to define the models
from .alts import Alt
from .award import AwardRelationship
from .badges import BadgeDef, Badge
from .clients import OauthApp, ClientAuth
from .comment import Comment
from .domains import BannedDomain
from .exiles import Exile
from .flags import Flag, CommentFlag
from .follows import Follow
from .marsey import Marsey
from .mod import Mod
from .mod_logs import ModAction
from .notifications import Notification
from .saves import SaveRelationship, CommentSaveRelationship
from .sub import Sub
from .sub_block import SubBlock
from .submission import Submission
from .subscriptions import Subscription
from .user import User
from .userblock import UserBlock
from .usernotes import UserTag, UserNote
from .views import ViewerRelationship
from .votes import Vote, CommentVote
# Then the import * from files.*
from files.helpers.const import *
from files.helpers.images import *
from files.helpers.lazy import *
from files.helpers.security import *
# Then the specific stuff we don't want stomped on
from files.helpers.discord import remove_user
from files.helpers.lazy import lazy
from files.__main__ import Base, app, cache