mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 11:50:00 +00:00
Ghetto migrate solution, in case you re-run db_create, it won't add categories again
This commit is contained in:
parent
3bdff6246f
commit
b147cfeb81
15
db_create.py
15
db_create.py
|
@ -5,9 +5,10 @@ from nyaa import app, db, models
|
||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
# Insert categories
|
# Insert categories and insert if it doesn't eixst
|
||||||
|
existing_cats = models.MainCategory.query.all()
|
||||||
if app.config['SITE_FLAVOR'] == 'nyaa':
|
if not existing_cats:
|
||||||
|
if app.config['SITE_FLAVOR'] == 'nyaa':
|
||||||
CATEGORIES = [
|
CATEGORIES = [
|
||||||
('Anime', ['Anime Music Video', 'English-translated', 'Non-English-translated', 'Raw']),
|
('Anime', ['Anime Music Video', 'English-translated', 'Non-English-translated', 'Raw']),
|
||||||
('Audio', ['Lossless', 'Lossy']),
|
('Audio', ['Lossless', 'Lossy']),
|
||||||
|
@ -16,22 +17,22 @@ if app.config['SITE_FLAVOR'] == 'nyaa':
|
||||||
('Pictures', ['Graphics', 'Photos']),
|
('Pictures', ['Graphics', 'Photos']),
|
||||||
('Software', ['Applications', 'Games']),
|
('Software', ['Applications', 'Games']),
|
||||||
]
|
]
|
||||||
elif app.config['SITE_FLAVOR'] == 'sukebei':
|
elif app.config['SITE_FLAVOR'] == 'sukebei':
|
||||||
CATEGORIES = [
|
CATEGORIES = [
|
||||||
('Art', ['Anime', 'Doujinshi', 'Games', 'Manga', 'Pictures']),
|
('Art', ['Anime', 'Doujinshi', 'Games', 'Manga', 'Pictures']),
|
||||||
('Real Life', ['Photobooks / Pictures', 'Videos']),
|
('Real Life', ['Photobooks / Pictures', 'Videos']),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
CATEGORIES = []
|
CATEGORIES = []
|
||||||
|
|
||||||
for main_cat_name, sub_cat_names in CATEGORIES:
|
for main_cat_name, sub_cat_names in CATEGORIES:
|
||||||
main_cat = models.MainCategory(name=main_cat_name)
|
main_cat = models.MainCategory(name=main_cat_name)
|
||||||
for i, sub_cat_name in enumerate(sub_cat_names):
|
for i, sub_cat_name in enumerate(sub_cat_names):
|
||||||
# Composite keys can't autoincrement, set sub_cat id manually (1-index)
|
# Composite keys can't autoincrement, set sub_cat id manually (1-index)
|
||||||
sub_cat = models.SubCategory(id=i+1, name=sub_cat_name, main_category=main_cat)
|
sub_cat = models.SubCategory(id=i+1, name=sub_cat_name, main_category=main_cat)
|
||||||
db.session.add(main_cat)
|
db.session.add(main_cat)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Create fulltext index
|
# Create fulltext index
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue