forked from FrederikBaerentsen/BrickTracker
bricktracker
migrations
sql
views
__init__.py
app.py
config.py
configuration.py
configuration_list.py
exceptions.py
fields.py
instructions.py
instructions_list.py
login.py
minifigure.py
minifigure_list.py
navbar.py
parser.py
part.py
part_list.py
rebrickable.py
rebrickable_image.py
rebrickable_minifigure.py
rebrickable_part.py
rebrickable_set.py
rebrickable_set_list.py
record.py
record_list.py
reload.py
retired.py
retired_list.py
set.py
set_checkbox.py
set_checkbox_list.py
set_list.py
socket.py
socket_decorator.py
sql.py
sql_counter.py
sql_migration.py
sql_migration_list.py
sql_stats.py
theme.py
theme_list.py
version.py
wish.py
wish_list.py
docs
static
templates
.dockerignore
.env.sample
.gitignore
CHANGELOG.md
Dockerfile
LICENSE
README.md
__init__.py
app.py
compose.legacy.yml
compose.local.yaml
compose.yaml
entrypoint.sh
requirements.txt
test-server.sh
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
from glob import glob
|
|
import logging
|
|
import os
|
|
|
|
from .sql_migration import BrickSQLMigration
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class BrickSQLMigrationList(object):
|
|
migrations: list[BrickSQLMigration]
|
|
|
|
def __init__(self):
|
|
# Load the migrations only there is none already loaded
|
|
migrations = getattr(self, 'migrations', None)
|
|
|
|
if migrations is None:
|
|
logger.info('Loading SQL migrations list')
|
|
|
|
BrickSQLMigrationList.migrations = []
|
|
|
|
path: str = os.path.join(
|
|
os.path.dirname(__file__),
|
|
'sql/migrations/*.sql'
|
|
)
|
|
|
|
files = glob(path)
|
|
|
|
for file in files:
|
|
try:
|
|
BrickSQLMigrationList.migrations.append(
|
|
BrickSQLMigration(file)
|
|
)
|
|
# Ignore file if error
|
|
except Exception:
|
|
pass
|
|
|
|
# Get the sorted list of pending migrations
|
|
def pending(
|
|
self,
|
|
current: int,
|
|
/
|
|
) -> list[BrickSQLMigration]:
|
|
pending: list[BrickSQLMigration] = []
|
|
|
|
for migration in self.migrations:
|
|
if migration.is_needed(current):
|
|
pending.append(migration)
|
|
|
|
# Sort the list
|
|
pending.sort(key=lambda e: e.version)
|
|
|
|
return pending
|