Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7888fdf
feat(database): Add persistent data management using sqlite & sqlalchemy
MaxNumerique Sep 1, 2025
cfcfdd4
default datetime changed for a non decprecated method
MaxNumerique Sep 1, 2025
2d24b77
Apply prepare changes
MaxNumerique Sep 1, 2025
73ff779
minor renames
MaxNumerique Sep 1, 2025
ee372e5
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 1, 2025
6163517
Apply prepare changes
MaxNumerique Sep 1, 2025
a53d000
test
MaxNumerique Sep 1, 2025
2974791
Apply prepare changes
MaxNumerique Sep 1, 2025
652149d
Using Flask-SQLAlchemy instead of SQLAlchemy for the database
MaxNumerique Sep 2, 2025
dad100a
Apply prepare changes
MaxNumerique Sep 2, 2025
1905756
clean this ?
MaxNumerique Sep 2, 2025
86560cb
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 2, 2025
1d4b231
Apply prepare changes
MaxNumerique Sep 2, 2025
62bf4bb
some comments
MaxNumerique Sep 2, 2025
bf9dfc0
delete commitlint
MaxNumerique Sep 3, 2025
ac4782f
Apply prepare changes
MaxNumerique Sep 3, 2025
6777263
tests added
MaxNumerique Sep 3, 2025
023ab17
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 3, 2025
2011ac5
Converted SQLALCHEMY_DATABASE_URI to use absolute paths
MaxNumerique Sep 3, 2025
a970a9c
Apply prepare changes
MaxNumerique Sep 3, 2025
0e9e361
abs path for sqlalchemy_database_uri
MaxNumerique Sep 3, 2025
db5a89a
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 3, 2025
a70ef53
abs path
MaxNumerique Sep 3, 2025
a985ba5
id and data infos set by database
MaxNumerique Sep 3, 2025
4772ac4
Apply prepare changes
MaxNumerique Sep 3, 2025
2e9266f
trigger
BotellaA Sep 3, 2025
6599029
again
BotellaA Sep 3, 2025
25adb82
trigger
BotellaA Sep 3, 2025
4088ff4
again
BotellaA Sep 4, 2025
b8e6ffc
new test session.commit to see if it is relevant
MaxNumerique Sep 4, 2025
5c90a33
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 4, 2025
cb60e9c
Apply prepare changes
MaxNumerique Sep 4, 2025
3ebe500
add type for sub-class of declarative_base()
MaxNumerique Sep 4, 2025
f2e07fc
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 4, 2025
83ee651
Apply prepare changes
MaxNumerique Sep 4, 2025
3bdf3b8
Type["Datas"]
MaxNumerique Sep 4, 2025
52e41bc
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 4, 2025
199727a
Apply prepare changes
MaxNumerique Sep 4, 2025
f597419
test type subclass
MaxNumerique Sep 4, 2025
8a778ad
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 4, 2025
e1490ca
Apply prepare changes
MaxNumerique Sep 4, 2025
76762fd
mypy Base(DeclarativeBase)
MaxNumerique Sep 4, 2025
a85d868
Apply prepare changes
MaxNumerique Sep 4, 2025
fd1967a
final mypy
MaxNumerique Sep 4, 2025
39764fc
Merge branch 'feat/database' of https://github.com/Geode-solutions/Op…
MaxNumerique Sep 4, 2025
410580f
Apply prepare changes
MaxNumerique Sep 4, 2025
4217ed4
input_file: str
MaxNumerique Sep 4, 2025
9db80dc
final
MaxNumerique Sep 4, 2025
5f4673c
input_file as str
MaxNumerique Sep 4, 2025
e3ac529
Apply prepare changes
MaxNumerique Sep 4, 2025
03ba365
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique Sep 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
extends: ["@commitlint/config-angular"],
rules: {
"scope-empty": [2, "never"],
"subject-empty": [2, "never"],
"subject-max-length": [0],
"body-leading-blank": [0],
"footer-leading-blank": [0],
"header-max-length": [0],
"scope-case": [0],
"subject-case": [0],
"subject-full-stop": [0],
"type-case": [0],
"type-empty": [0],
},
}
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ fastjsonschema==2.16.2
Flask[async]==3.0.3
Flask-Cors==6.0.1
werkzeug==3.0.3
sqlalchemy==2.0.43
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ geode-common==33.9.0
# via geode-viewables
geode-viewables==3.2.0
# via -r requirements.in
greenlet==3.2.4
# via sqlalchemy
itsdangerous==2.2.0
# via flask
jinja2==3.1.6
Expand Down Expand Up @@ -54,6 +56,10 @@ opengeode-io==7.3.2
# -r requirements.in
# geode-viewables
# opengeode-geosciencesio
sqlalchemy==2.0.43
# via -r requirements.in
typing-extensions==4.15.0
# via sqlalchemy
werkzeug==3.0.3
# via
# -r requirements.in
Expand Down
11 changes: 11 additions & 0 deletions src/opengeodeweb_back/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker


def get_engine(db_path: str):
return create_engine(f"sqlite:///{db_path}", echo=False)


def get_session(engine):
Session = sessionmaker(bind=engine)
return Session()
23 changes: 23 additions & 0 deletions src/opengeodeweb_back/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import uuid
from datetime import datetime
from sqlalchemy import Column, String, DateTime, JSON
from sqlalchemy.orm import declarative_base

Base = declarative_base()


def generate_uuid():
return str(uuid.uuid4())


class Data(Base):
__tablename__ = "datas"

id = Column(String, primary_key=True, default=generate_uuid)
name = Column(String, nullable=False)
native_file_name = Column(String, nullable=False)
viewable_file_name = Column(String, nullable=False)
geode_object = Column(String, nullable=False)
binary_light_viewable = Column(String, nullable=True)
input_files = Column(JSON, nullable=True)
created_at = Column(DateTime, default=datetime.now)
21 changes: 21 additions & 0 deletions src/opengeodeweb_back/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Local application imports
from . import geode_functions
from .models import Data, Base
from .database import get_engine, get_session


def increment_request_counter(current_app):
Expand Down Expand Up @@ -171,6 +173,25 @@ def save_all_viewables_and_return_info(
with open(saved_light_viewable_file_path, "rb") as f:
binary_light_viewable = f.read()

project_root_path = os.path.dirname(data_path)
engine = get_engine(os.path.join(project_root_path, "db.sqlite3"))

Base.metadata.create_all(engine)
session = get_session(engine)

data_entry = Data(
id=generated_id,
name=data.name(),
native_file_name=os.path.basename(saved_native_file_path[0]),
viewable_file_name=os.path.basename(saved_viewable_file_path),
geode_object=geode_object,
binary_light_viewable=binary_light_viewable.decode("utf-8"),
input_files=additional_files or [],
)
session.add(data_entry)
session.commit()
session.close()

return {
"name": data.name(),
"native_file_name": os.path.basename(saved_native_file_path[0]),
Expand Down
Loading