33
33
import inspect
34
34
import os
35
35
36
- from peewee import SqliteDatabase , Field
36
+ from peewee import Model , SqliteDatabase , Field
37
37
from peewee_migrate import Router
38
38
39
39
from unmanic .libs import unlogger
@@ -97,10 +97,19 @@ def update_schema(self):
97
97
"""
98
98
# Fetch all model classes
99
99
all_models = []
100
+ all_base_models = []
100
101
for model in list_all_models ():
101
102
imported_model = getattr (importlib .import_module ("unmanic.libs.unmodels" ), model )
102
103
if inspect .isclass (imported_model ) and issubclass (imported_model , BaseModel ):
104
+ # Add this model to both the 'all_models' list and our list of base models
103
105
all_models .append (imported_model )
106
+ all_base_models .append (imported_model )
107
+ elif inspect .isclass (imported_model ) and issubclass (imported_model , Model ):
108
+ # If the model is not one of the base models, it is an in-build model from peewee.
109
+ # For, this list of models we will not run a migration, but we will still ensure that the
110
+ # table is created in the DB
111
+ all_models .append (imported_model )
112
+ pass
104
113
105
114
# Start by creating all models
106
115
self .__log ("Initialising database tables" )
@@ -120,7 +129,7 @@ def update_schema(self):
120
129
# Newly added fields can be auto added with this function... no need for a migration script
121
130
# Ensure all files are also present for each of the model classes
122
131
self .__log ("Updating database fields" )
123
- for model in all_models :
132
+ for model in all_base_models :
124
133
# Fetch all peewee fields for the model class
125
134
# https://stackoverflow.com/questions/22573558/peewee-determining-meta-data-about-model-at-run-time
126
135
fields = model ._meta .fields
0 commit comments