contentdb/setup.py

33 lines
854 B
Python
Raw Normal View History

2018-03-19 19:25:13 +01:00
import os, sys, datetime
2018-03-18 18:43:30 +01:00
2018-03-19 19:25:13 +01:00
delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
2018-03-18 18:43:30 +01:00
2018-03-19 19:08:41 +01:00
if delete_db and os.path.isfile("db.sqlite"):
os.remove("db.sqlite")
2018-03-18 18:43:30 +01:00
2018-03-19 19:08:41 +01:00
if not os.path.isfile("db.sqlite"):
2018-03-18 19:05:53 +01:00
from app.models import *
2018-03-18 18:43:30 +01:00
print("Creating database tables...")
2018-03-18 19:05:53 +01:00
db.create_all()
2018-03-18 18:43:30 +01:00
print("Filling database...")
2018-03-18 19:05:53 +01:00
ruben = User("rubenwardy")
ruben.github_username = "rubenwardy"
db.session.add(ruben)
2018-03-19 19:08:41 +01:00
2018-03-19 19:25:13 +01:00
mod1 = Package()
2018-03-19 19:08:41 +01:00
mod1.name = "awards"
mod1.title = "Awards"
2018-03-20 01:44:47 +01:00
mod1.type = PackageType.MOD
2018-03-19 19:08:41 +01:00
mod1.author = ruben
mod1.description = "Adds achievements and an API to register new ones."
mod1.repo = "https://github.com/rubenwardy/awards"
mod1.issueTracker = "https://github.com/rubenwardy/awards/issues"
mod1.forums = "https://forum.minetest.net/viewtopic.php?t=4870"
db.session.add(mod1)
2018-03-18 19:05:53 +01:00
db.session.commit()
2018-03-18 18:43:30 +01:00
else:
print("Database already exists")