Skip to content

Commit 5ccf9f5

Browse files
nyaadevnyaadev
authored andcommitted
upgrade dependencies (#4)
upgrade dependencies and fix some things which broke mysql fulltextsearch module doesn't work but nobody uses that PyMySQL not upgraded due to julien-duponchelle/python-mysql-replication#337 ES not really tested as always xd (I need to make a proper dev setup)
1 parent fffd9a2 commit 5ccf9f5

File tree

8 files changed

+59
-76
lines changed

8 files changed

+59
-76
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pyenv eases the use of different Python versions, and as not all Linux distros o
4040

4141
### Finishing up
4242
- Run `python db_create.py` to create the database and import categories
43-
- Follow the advice of `db_create.py` and run `./db_migrate.py stamp head` to mark the database version for Alembic
43+
- Follow the advice of `db_create.py` and run `flask db stamp head` to mark the database version for Alembic
4444
- Start the dev server with `python run.py`
4545
- When you are finished developing, deactivate your virtualenv with `pyenv deactivate` or `source deactivate` (or just close your shell session)
4646

@@ -51,16 +51,16 @@ Continue below to learn about database migrations and enabling the advanced sear
5151
## Database migrations
5252
- Database migrations are done with [flask-Migrate](https://flask-migrate.readthedocs.io/), a wrapper around [Alembic](http://alembic.zzzcomputing.com/en/latest/).
5353
- If someone has made changes in the database schema and included a new migration script:
54-
- If your database has never been marked by Alembic (you're on a database from before the migrations), run `./db_migrate.py stamp head` before pulling the new migration script(s).
55-
- If you already have the new scripts, check the output of `./db_migrate.py history` instead and choose a hash that matches your current database state, then run `./db_migrate.py stamp <hash>`.
54+
- If your database has never been marked by Alembic (you're on a database from before the migrations), run `flask db stamp head` before pulling the new migration script(s).
55+
- If you already have the new scripts, check the output of `flask db history` instead and choose a hash that matches your current database state, then run `flask db stamp <hash>`.
5656
- Update your branch (eg. `git fetch && git rebase origin/master`)
57-
- Run `./db_migrate.py upgrade head` to run the migration. Done!
57+
- Run `flask db upgrade head` to run the migration. Done!
5858
- If *you* have made a change in the database schema:
5959
- Save your changes in `models.py` and ensure the database schema matches the previous version (ie. your new tables/columns are not added to the live database)
60-
- Run `./db_migrate.py migrate -m "Short description of changes"` to automatically generate a migration script for the changes
60+
- Run `flask db migrate -m "Short description of changes"` to automatically generate a migration script for the changes
6161
- Check the script (`migrations/versions/...`) and make sure it works! Alembic may not able to notice all changes.
62-
- Run `./db_migrate.py upgrade` to run the migration and verify the upgrade works.
63-
- (Run `./db_migrate.py downgrade` to verify the downgrade works as well, then upgrade again)
62+
- Run `flask db upgrade` to run the migration and verify the upgrade works.
63+
- (Run `flask db downgrade` to verify the downgrade works as well, then upgrade again)
6464

6565

6666
## Setting up and enabling Elasticsearch

db_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ def add_categories(categories, main_class, sub_class):
5757

5858
if database_empty:
5959
print('Remember to run the following to mark the database up-to-date for Alembic:')
60-
print('./db_migrate.py stamp head')
60+
print('flask db stamp head')
6161
# Technically we should be able to do this here, but when you have
6262
# Flask-Migrate and Flask-SQA and everything... I didn't get it working.

db_migrate.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

nyaa/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from flask_assets import Bundle # noqa F401
77

88
from nyaa.api_handler import api_blueprint
9-
from nyaa.extensions import assets, cache, db, fix_paginate, limiter, toolbar
9+
from nyaa.extensions import assets, cache, db, fix_paginate, limiter, toolbar, migrate
1010
from nyaa.template_utils import bp as template_utils_bp
1111
from nyaa.template_utils import caching_url_for
1212
from nyaa.utils import random_string
@@ -114,6 +114,7 @@ def internal_error(exception):
114114
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
115115
app.config['MYSQL_DATABASE_CHARSET'] = 'utf8mb4'
116116
db.init_app(app)
117+
migrate.init_app(app, db)
117118

118119
# Assets
119120
assets.init_app(app)

nyaa/extensions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
from flask_limiter import Limiter
99
from flask_limiter.util import get_remote_address
1010
from flask_sqlalchemy import BaseQuery, Pagination, SQLAlchemy
11+
from flask_migrate import Migrate
1112

1213
assets = Environment()
1314
db = SQLAlchemy()
1415
toolbar = DebugToolbarExtension()
1516
cache = Cache()
1617
limiter = Limiter(key_func=get_remote_address)
18+
migrate = Migrate()
1719

1820

1921
class LimitedPagination(Pagination):

nyaa/models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ def __repr__(self):
192192

193193
def update_comment_count(self):
194194
self.comment_count = db.session.query(func.count(
195-
Comment.id)).filter_by(torrent_id=self.id).first()[0]
195+
Comment.id)).filter(Comment.torrent_id == self.id).first()[0]
196196
return self.comment_count
197197

198198
@classmethod
199199
def update_comment_count_db(cls, torrent_id):
200200
cls.query.filter_by(id=torrent_id).update({'comment_count': db.session.query(
201-
func.count(Comment.id)).filter_by(torrent_id=torrent_id).as_scalar()}, False)
201+
func.count(Comment.id)).filter(Comment.torrent_id == torrent_id).as_scalar()}, False)
202202

203203
@property
204204
def created_utc_timestamp(self):
@@ -494,7 +494,7 @@ class User(db.Model):
494494
sukebei_torrents = db.relationship('SukebeiTorrent', back_populates='user', lazy='dynamic')
495495
sukebei_comments = db.relationship('SukebeiComment', back_populates='user', lazy='dynamic')
496496

497-
bans = db.relationship('Ban', uselist=True, foreign_keys='Ban.user_id')
497+
bans = db.relationship('Ban', uselist=True, foreign_keys='Ban.user_id', back_populates='user')
498498

499499
preferences = db.relationship('UserPreferences', back_populates='user', uselist=False)
500500

@@ -776,7 +776,8 @@ class Ban(db.Model):
776776
reason = db.Column(db.String(length=2048), nullable=False)
777777

778778
admin = db.relationship('User', uselist=False, lazy='joined', foreign_keys=[admin_id])
779-
user = db.relationship('User', uselist=False, lazy='joined', foreign_keys=[user_id])
779+
user = db.relationship('User', uselist=False, lazy='joined',
780+
foreign_keys=[user_id], back_populates='bans')
780781

781782
__table_args__ = (
782783
Index('user_ip_4', 'user_ip', mysql_length=4, unique=True),
@@ -880,7 +881,7 @@ class TrustedApplication(db.Model):
880881
why_give = db.Column(db.String(length=4000), nullable=False)
881882
status = db.Column(ChoiceType(TrustedApplicationStatus, impl=db.Integer()), nullable=False,
882883
default=TrustedApplicationStatus.NEW)
883-
reviews = db.relationship('TrustedReview', backref='trusted_applications')
884+
reviews = db.relationship('TrustedReview', back_populates='application')
884885
submitter = db.relationship('User', uselist=False, lazy='joined', foreign_keys=[submitter_id])
885886

886887
@hybrid_property
@@ -929,7 +930,7 @@ class TrustedReview(db.Model):
929930
nullable=False)
930931
reviewer = db.relationship('User', uselist=False, lazy='joined', foreign_keys=[reviewer_id])
931932
application = db.relationship('TrustedApplication', uselist=False, lazy='joined',
932-
foreign_keys=[app_id])
933+
foreign_keys=[app_id], back_populates='reviews')
933934

934935

935936
# Actually declare our site-specific classes

requirements.txt

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,68 @@
1-
alembic==1.4.3
1+
alembic==1.6.5
22
appdirs==1.4.4
33
argon2-cffi==20.1.0
4-
attrs==20.3.0
5-
autopep8==1.5.4
4+
attrs==21.2.0
5+
autopep8==1.5.7
66
blinker==1.4
77
certifi==2020.12.5
8-
cffi==1.14.4
9-
chardet==3.0.4
10-
click==7.1.2
11-
dnspython==2.0.0
12-
elasticsearch==7.10.0
8+
cffi==1.14.5
9+
chardet==4.0.0
10+
click==8.0.1
11+
dnspython==2.1.0
12+
elasticsearch==7.13.1
1313
elasticsearch-dsl==7.3.0
1414
email-validator==1.1.2
15-
flake8==3.8.4
15+
flake8==3.9.2
1616
flake8-isort==4.0.0
17-
Flask==1.1.2
17+
Flask==2.0.1
1818
Flask-Assets==2.0
19-
Flask-Caching==1.9.0
19+
Flask-Caching==1.10.1
2020
Flask-DebugToolbar==0.11.0
2121
Flask-Limiter==1.4
22-
Flask-Migrate==2.5.3
23-
flask-paginate==0.7.1
24-
Flask-Script==2.0.6
25-
Flask-SQLAlchemy==2.4.4
26-
Flask-WTF==0.14.3
27-
gevent==20.9.0
28-
greenlet==0.4.17
22+
Flask-Migrate==3.0.1
23+
flask-paginate==0.8.1
24+
Flask-SQLAlchemy==2.5.1
25+
Flask-WTF==0.15.1
26+
gevent==21.1.2
27+
greenlet==1.1.0
2928
idna==2.10
3029
iniconfig==1.1.1
31-
isort==5.6.4
32-
itsdangerous==1.1.0
33-
Jinja2==2.11.2
30+
isort==5.8.0
31+
itsdangerous==2.0.1
32+
Jinja2==3.0.1
3433
limits==1.5.1
35-
Mako==1.1.3
36-
MarkupSafe==1.1.1
34+
Mako==1.1.4
35+
MarkupSafe==2.0.1
3736
mccabe==0.6.1
38-
mysql-replication==0.22
39-
mysqlclient==2.0.1
37+
mysql-replication==0.23
38+
mysqlclient==2.0.3
4039
orderedset==2.0.3
41-
packaging==20.7
40+
packaging==20.9
4241
passlib==1.7.4
4342
pluggy==0.13.1
4443
progressbar33==2.4
45-
py==1.9.0
46-
pycodestyle==2.6.0
44+
py==1.10.0
45+
pycodestyle==2.7.0
4746
pycparser==2.20
48-
pyflakes==2.2.0
47+
pyflakes==2.3.1
4948
PyMySQL==0.10.1
5049
pyparsing==2.4.7
51-
pytest==6.1.2
50+
pytest==6.2.4
5251
python-dateutil==2.8.1
5352
python-editor==1.0.4
54-
python-utils==2.4.0
53+
python-utils==2.5.6
5554
redis==3.5.3
56-
requests==2.25.0
57-
six==1.15.0
58-
SQLAlchemy==1.3.20
59-
SQLAlchemy-Utils==0.36.8
55+
requests==2.25.1
56+
six==1.16.0
57+
SQLAlchemy==1.4.17
58+
SQLAlchemy-Utils==0.37.6
6059
statsd==3.3.0
61-
testfixtures==6.15.0
60+
testfixtures==6.17.1
6261
toml==0.10.2
63-
urllib3==1.26.2
62+
urllib3==1.26.5
6463
uWSGI==2.0.19.1
6564
webassets==2.0
66-
Werkzeug==1.0.1
65+
Werkzeug==2.0.1
6766
WTForms==2.3.3
6867
zope.event==4.5.0
69-
zope.interface==5.2.0
68+
zope.interface==5.4.0

run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
from nyaa import create_app
33

44
app = create_app('config')
5+
56
if __name__ == "__main__":
6-
app.run(host='0.0.0.0', port=5500, debug=True)
7+
app.run(host='0.0.0.0', port=5500, debug=True)

0 commit comments

Comments
 (0)