mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-13 15:19:03 +00:00
Initial commit.
This commit is contained in:
40
db_create.py
Normal file
40
db_create.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import sys
|
||||
from nyaa import app, db, models
|
||||
|
||||
# Create tables
|
||||
|
||||
db.create_all()
|
||||
|
||||
# Insert categories
|
||||
|
||||
if app.config['TABLE_PREFIX'] == 'nyaa_':
|
||||
CATEGORIES = [
|
||||
('Anime', ['Anime Music Video', 'English-translated', 'Non-English-translated', 'Raw']),
|
||||
('Audio', ['Lossless', 'Lossy']),
|
||||
('Literature', ['English-translated', 'Non-English-translated', 'Raw']),
|
||||
('Live Action', ['English-translated', 'Idol/Promotional Video', 'Non-English-translated', 'Raw']),
|
||||
('Pictures', ['Graphics', 'Photos']),
|
||||
('Software', ['Applications', 'Games']),
|
||||
]
|
||||
elif app.config['TABLE_PREFIX'] == 'sukebei_':
|
||||
CATEGORIES = [
|
||||
('Art', ['Anime', 'Doujinshi', 'Games', 'Manga', 'Pictures']),
|
||||
('Real Life', ['Photobooks / Pictures', 'Videos']),
|
||||
]
|
||||
else:
|
||||
CATEGORIES = []
|
||||
|
||||
for main_cat_name, sub_cat_names in CATEGORIES:
|
||||
main_cat = models.MainCategory(name=main_cat_name)
|
||||
for i, sub_cat_name in enumerate(sub_cat_names):
|
||||
# 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)
|
||||
db.session.add(main_cat)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Create fulltext index
|
||||
|
||||
if app.config['USE_MYSQL']:
|
||||
db.engine.execute('ALTER TABLE ' + app.config['TABLE_PREFIX'] + 'torrents ADD FULLTEXT KEY (display_name)')
|
||||
|
||||
Reference in New Issue
Block a user