Skip to content

Commit

Permalink
Drop codename stuff
Browse files Browse the repository at this point in the history
Applications should implement their own "database codename" if
they require such.
  • Loading branch information
soininen committed Nov 1, 2024
1 parent 14e504b commit ea83c92
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- The ``codename`` field and related stuff has been removed from ``DatabaseMapping``.

### Fixed

### Security
Expand Down
17 changes: 0 additions & 17 deletions spinedb_api/db_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

from datetime import datetime, timezone
from functools import partialmethod
import hashlib
import logging
import os
import time
from types import MethodType
from alembic.config import Config
from alembic.environment import EnvironmentContext
Expand Down Expand Up @@ -142,7 +140,6 @@ def __init__(
upgrade (bool, optional): Whether the DB at the given `url` should be upgraded to the most recent
version.
backup_url (str, optional): A URL to backup the DB before upgrading.
codename (str, optional): A name to identify this object in your application.
create (bool, optional): Whether to create a new Spine DB at the given `url` if it's not already one.
apply_filters (bool, optional): Whether to apply filters in the `url`'s query segment.
memory (bool, optional): Whether to use a SQLite memory DB as replacement for the original one.
Expand Down Expand Up @@ -209,20 +206,6 @@ def _make_sq(self, item_type):
sq_name = self._sq_name_by_item_type[item_type]
return getattr(self, sq_name)

def suggest_display_name(self):
"""Returns a short name for the database mapping.
Returns:
str: suggested name for the database for display purposes.
"""
if not self.sa_url.drivername.startswith("sqlite"):
return self.sa_url.database
if self.sa_url.database is not None:
return os.path.splitext(os.path.basename(self.sa_url.database))[0]
hashing = hashlib.sha1()
hashing.update(bytes(str(time.time()), "utf-8"))
return hashing.hexdigest()

@staticmethod
def get_upgrade_db_prompt_data(url, create=False):
"""Returns data to prompt the user what to do if the DB at the given url is not the latest version.
Expand Down
6 changes: 0 additions & 6 deletions tests/test_DatabaseMapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ def test_shorthand_filter_query_works(self):


class TestDatabaseMapping(AssertSuccessTestCase):
def test_suggest_display_name(self):
with TemporaryDirectory() as temp_dir:
url = "sqlite:///" + os.path.join(temp_dir, "my_precious_database.sqlite")
with DatabaseMapping(url, create=True) as db_map:
self.assertEqual(db_map.suggest_display_name(), "my_precious_database")

def test_active_by_default_is_initially_true_for_zero_dimensional_entity_class(self):
with DatabaseMapping("sqlite://", create=True) as db_map:
item = self._assert_success(db_map.add_entity_class_item(name="Entity"))
Expand Down

0 comments on commit ea83c92

Please sign in to comment.