comparison sat/memory/sqla_config.py @ 3582:71516731d0aa

core (memory/sqla): database migration using Alembic: Alembic database migration tool, which is the recommended one for SQLAlchemy has been integrated. When a database is created, it will be used to stamp to current (head) revision, otherwise, DB will be checked to see if it needs to be updated, and upgrade will be triggered if necessary.
author Goffi <goffi@goffi.org>
date Fri, 25 Jun 2021 17:55:23 +0200
parents
children 4edfd7521418
comparison
equal deleted inserted replaced
3581:84ea57a8d6b3 3582:71516731d0aa
1 #!/usr/bin/env python3
2
3 # Libervia: an XMPP client
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 from pathlib import Path
20 from urllib.parse import quote
21 from sat.core.constants import Const as C
22 from sat.tools import config
23
24
25 def getDbConfig() -> dict:
26 """Get configuration for database
27
28 @return: dict with following keys:
29 - type: only "sqlite" for now
30 - path: path to the sqlite DB
31 """
32 main_conf = config.parseMainConf()
33 local_dir = Path(config.getConfig(main_conf, "", "local_dir"))
34 database_path = (local_dir / C.SAVEFILE_DATABASE).expanduser()
35 url = f"sqlite+aiosqlite:///{quote(str(database_path))}"
36 return {
37 "type": "sqlite",
38 "path": database_path,
39 "url": url,
40 }