Rewrite sqlachemy code for 1.4 to 2.x migration
This commit is contained in:
parent
146eb995a8
commit
2ff958c55f
2
app.py
2
app.py
@ -38,7 +38,7 @@ app.config["KI_LDAP_AUTH_PASSWORD"] = os.getenv("KI_LDAP_AUTH_PASSWORD")
|
||||
app.config["KI_LDAP_BASE_DN"] = os.getenv("KI_LDAP_BASE_DN")
|
||||
|
||||
CORS(app)
|
||||
db = SQLAlchemy(app)
|
||||
db = SQLAlchemy(app, session_options={"future": True})
|
||||
migrate = Migrate(app, db, compare_type=True)
|
||||
|
||||
app.logger.info("Hello from KI")
|
||||
|
@ -19,7 +19,7 @@ def seed_contacttypes():
|
||||
|
||||
for contacttype in csv_reader:
|
||||
id = int(contacttype["id"])
|
||||
db_contacttype = ContactType.query.get(id)
|
||||
db_contacttype = db.session.get(ContactType, id)
|
||||
|
||||
if db_contacttype is None:
|
||||
db.session.add(ContactType(id=int(contacttype["id"]), name=contacttype["name"]))
|
||||
@ -99,7 +99,7 @@ def seed(dev: bool):
|
||||
|
||||
for skill in skills_csv_reader:
|
||||
id = int(skill["id"])
|
||||
db_skill = Skill.query.get(id)
|
||||
db_skill = db.session.get(Skill, id)
|
||||
|
||||
if db_skill is None:
|
||||
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
||||
@ -113,7 +113,7 @@ def seed(dev: bool):
|
||||
|
||||
for iso in iso_csv_reader:
|
||||
id = iso["639-1"]
|
||||
db_language = Language.query.get(id)
|
||||
db_language = db.session.get(Language, id)
|
||||
|
||||
if db_language is None:
|
||||
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
||||
|
@ -33,7 +33,7 @@ def update_languages(profile, languages_data):
|
||||
if "id" not in language_data["language"]:
|
||||
continue
|
||||
|
||||
language = Language.query.get(language_data["language"]["id"])
|
||||
language = db.session.get(Language, language_data["language"]["id"])
|
||||
profile_language = ProfileLanguage.query.filter(ProfileLanguage.profile == profile,
|
||||
ProfileLanguage.language == language).first()
|
||||
|
||||
@ -110,7 +110,7 @@ def update_contacts(profile, contacts_data):
|
||||
if "id" in contact_data:
|
||||
contact_id = int(contact_data["id"])
|
||||
contact_ids_to_be_deleted.remove(contact_id)
|
||||
contact = Contact.query.get(contact_id)
|
||||
contact = db.session.get(Contact, contact_id)
|
||||
else:
|
||||
contact = Contact(profile=profile, contacttype=contacttype)
|
||||
db.session.add(contact)
|
||||
@ -122,7 +122,7 @@ def update_contacts(profile, contacts_data):
|
||||
|
||||
|
||||
def update_profile(user_id: int):
|
||||
user = User.query.get(user_id)
|
||||
user = db.session.get(User, user_id)
|
||||
|
||||
if user is None:
|
||||
return make_response({}, 404)
|
||||
|
@ -10,7 +10,7 @@ from ki.auth import auth
|
||||
from ki.handlers import find_profiles as find_profiles_handler
|
||||
from ki.handlers import update_profile as update_profile_handler
|
||||
from ki.models import ContactType, Language, Skill, Token, User
|
||||
from app import app
|
||||
from app import app, db
|
||||
|
||||
content_type_svg = "image/svg+xml"
|
||||
content_type_png = "image/png"
|
||||
@ -66,7 +66,7 @@ def handle_completion_request(model, key):
|
||||
|
||||
|
||||
def handle_icon_request(model, id, path):
|
||||
object = model.query.get(id)
|
||||
object = db.session.get(model, id)
|
||||
|
||||
if object is None:
|
||||
return make_response({}, 404)
|
||||
|
Loading…
Reference in New Issue
Block a user