mirror of https://github.com/JohnHammond/CTFd.git
Clear caches after populate and enable foreign keys in SQLite
parent
abcb791b73
commit
6092ed1f31
|
@ -181,6 +181,17 @@ def create_app(config="CTFd.config.Config"):
|
||||||
if url.drivername.startswith("sqlite"):
|
if url.drivername.startswith("sqlite"):
|
||||||
db.create_all()
|
db.create_all()
|
||||||
stamp_latest_revision()
|
stamp_latest_revision()
|
||||||
|
|
||||||
|
# Enable foreign keys for SQLite
|
||||||
|
from sqlalchemy.engine import Engine
|
||||||
|
from sqlalchemy import event
|
||||||
|
|
||||||
|
@event.listens_for(Engine, "connect")
|
||||||
|
def set_sqlite_pragma(dbapi_connection, connection_record):
|
||||||
|
cursor = dbapi_connection.cursor()
|
||||||
|
cursor.execute("PRAGMA foreign_keys=ON")
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# This creates tables instead of db.create_all()
|
# This creates tables instead of db.create_all()
|
||||||
# Allows migrations to happen properly
|
# Allows migrations to happen properly
|
||||||
|
|
|
@ -7,6 +7,7 @@ import random
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from CTFd import create_app
|
from CTFd import create_app
|
||||||
|
from CTFd.cache import clear_config, clear_standings, clear_pages
|
||||||
from CTFd.models import (
|
from CTFd.models import (
|
||||||
Users,
|
Users,
|
||||||
Teams,
|
Teams,
|
||||||
|
@ -338,3 +339,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
db.session.close()
|
db.session.close()
|
||||||
|
|
||||||
|
clear_config()
|
||||||
|
clear_standings()
|
||||||
|
clear_pages()
|
||||||
|
|
Loading…
Reference in New Issue