Skip to content

Commit

Permalink
Try to make database start at the right run number
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpunk committed Feb 29, 2024
1 parent b611a3b commit fa83032
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion runregistry-rest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"DATABASE_URI", "sqlite:////tmp/test.sqlite"
),
DEPLOYMENT_ENV=os.environ.get("DEPLOYMENT_ENV", "DEV"),
RUN_START=int(os.getenv("RUN_START", "1000")),
SQLALCHEMY_ECHO=False,
)

Expand Down Expand Up @@ -109,7 +110,7 @@ def get(self):
# the primary key sequence may not match
current_max_run = (
db.session.query(func.max(RunNumber.run_number)).scalar()
or int(os.getenv("RUN_START", "1000"))
or app.config["RUN_START"]
) + 1
run = RunNumber(run_number=current_max_run)
db.session.add(run)
Expand Down
9 changes: 7 additions & 2 deletions runregistry-rest/database.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from datetime import datetime

from api import db
from api import db, app

__all__ = ["RunNumber", "RunRegistryConfig", "RunRegistryMeta"]


class RunNumber(db.Model):
run_number = db.Column(
db.Integer, primary_key=True, autoincrement=True, nullable=False, index=True
db.Integer,
db.Sequence("run_number_sequence", start=app.config["RUN_START"]),
primary_key=True,
autoincrement=True,
nullable=False,
index=True,
)
flag = db.Column(db.Boolean, nullable=False, default=False)
start_time = db.Column(db.TIMESTAMP(6), nullable=False, default=datetime.now)
Expand Down

0 comments on commit fa83032

Please sign in to comment.