Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
87825e7e
Commit
87825e7e
authored
1 year ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
compatibility fixes for SQLAlchemy 2.0
parent
f6698e60
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Ccs/database/tm_db.py
+16
-7
16 additions, 7 deletions
Ccs/database/tm_db.py
Ccs/tools/import_mib.py
+4
-3
4 additions, 3 deletions
Ccs/tools/import_mib.py
with
20 additions
and
10 deletions
Ccs/database/tm_db.py
+
16
−
7
View file @
87825e7e
...
@@ -10,6 +10,7 @@ from sqlalchemy import (
...
@@ -10,6 +10,7 @@ from sqlalchemy import (
Column
,
Integer
,
Boolean
,
Unicode
,
Index
,
UniqueConstraint
,
ForeignKey
,
create_engine
,
engine
)
Column
,
Integer
,
Boolean
,
Unicode
,
Index
,
UniqueConstraint
,
ForeignKey
,
create_engine
,
engine
)
from
sqlalchemy.dialects.mysql
import
VARBINARY
from
sqlalchemy.dialects.mysql
import
VARBINARY
from
sqlalchemy.orm
import
sessionmaker
,
relationship
,
scoped_session
from
sqlalchemy.orm
import
sessionmaker
,
relationship
,
scoped_session
from
sqlalchemy.sql
import
text
# from sqlalchemy.orm.session import Session
# from sqlalchemy.orm.session import Session
# Use for SQlite
# Use for SQlite
...
@@ -232,8 +233,6 @@ class FEEDataTelemetryPool(FEEDATA_BASE): # type: ignore
...
@@ -232,8 +233,6 @@ class FEEDataTelemetryPool(FEEDATA_BASE): # type: ignore
def
gen_mysql_conn_str
(
user
=
config_db
.
user
,
pw
=
config_db
.
pw
,
host
=
config_db
.
host
,
schema
=
''
):
def
gen_mysql_conn_str
(
user
=
config_db
.
user
,
pw
=
config_db
.
pw
,
host
=
config_db
.
host
,
schema
=
''
):
return
engine
.
url
.
URL
.
create
(
drivername
=
'
mysql
'
,
username
=
user
,
password
=
pw
,
host
=
host
,
database
=
schema
)
return
engine
.
url
.
URL
.
create
(
drivername
=
'
mysql
'
,
username
=
user
,
password
=
pw
,
host
=
host
,
database
=
schema
)
#SQLSOCKET=''
def
create_storage_db
(
protocol
=
'
PUS
'
,
force
=
False
):
def
create_storage_db
(
protocol
=
'
PUS
'
,
force
=
False
):
if
protocol
.
upper
()
not
in
[
'
PUS
'
,
'
RMAP
'
,
'
FEEDATA
'
,
'
ALL
'
]:
if
protocol
.
upper
()
not
in
[
'
PUS
'
,
'
RMAP
'
,
'
FEEDATA
'
,
'
ALL
'
]:
...
@@ -243,8 +242,8 @@ def create_storage_db(protocol='PUS', force=False):
...
@@ -243,8 +242,8 @@ def create_storage_db(protocol='PUS', force=False):
print
(
'
Creating schema
"
{}
"
for {} data storage...
'
.
format
(
config_db
.
storage_schema_name
,
protocol
.
upper
()))
print
(
'
Creating schema
"
{}
"
for {} data storage...
'
.
format
(
config_db
.
storage_schema_name
,
protocol
.
upper
()))
_engine
=
create_engine
(
gen_mysql_conn_str
(),
echo
=
"
-v
"
in
sys
.
argv
)
_engine
=
create_engine
(
gen_mysql_conn_str
(),
echo
=
"
-v
"
in
sys
.
argv
)
if
force
:
if
force
:
_engine
.
execute
(
'
DROP SCHEMA IF EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
_engine
.
execute
(
text
(
'
DROP SCHEMA IF EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
)
_engine
.
execute
(
'
CREATE SCHEMA IF NOT EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
_engine
.
execute
(
text
(
'
CREATE SCHEMA IF NOT EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
)
_engine
.
dispose
()
_engine
.
dispose
()
_engine
=
create_engine
(
gen_mysql_conn_str
(
schema
=
config_db
.
storage_schema_name
),
echo
=
"
-v
"
in
sys
.
argv
)
_engine
=
create_engine
(
gen_mysql_conn_str
(
schema
=
config_db
.
storage_schema_name
),
echo
=
"
-v
"
in
sys
.
argv
)
for
protocol
in
protocols
:
for
protocol
in
protocols
:
...
@@ -254,8 +253,8 @@ def create_storage_db(protocol='PUS', force=False):
...
@@ -254,8 +253,8 @@ def create_storage_db(protocol='PUS', force=False):
print
(
'
Creating schema
"
{}
"
for {} data storage...
'
.
format
(
config_db
.
storage_schema_name
,
protocol
.
upper
()))
print
(
'
Creating schema
"
{}
"
for {} data storage...
'
.
format
(
config_db
.
storage_schema_name
,
protocol
.
upper
()))
_engine
=
create_engine
(
gen_mysql_conn_str
(),
echo
=
"
-v
"
in
sys
.
argv
)
_engine
=
create_engine
(
gen_mysql_conn_str
(),
echo
=
"
-v
"
in
sys
.
argv
)
if
force
:
if
force
:
_engine
.
execute
(
'
DROP SCHEMA IF EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
_engine
.
execute
(
text
(
'
DROP SCHEMA IF EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
)
_engine
.
execute
(
'
CREATE SCHEMA IF NOT EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
_engine
.
execute
(
text
(
'
CREATE SCHEMA IF NOT EXISTS {}
'
.
format
(
config_db
.
storage_schema_name
))
)
_engine
.
dispose
()
_engine
.
dispose
()
_engine
=
create_engine
(
gen_mysql_conn_str
(
schema
=
config_db
.
storage_schema_name
),
echo
=
"
-v
"
in
sys
.
argv
)
_engine
=
create_engine
(
gen_mysql_conn_str
(
schema
=
config_db
.
storage_schema_name
),
echo
=
"
-v
"
in
sys
.
argv
)
protocols
[
protocol
.
upper
()][
1
].
metadata
.
create_all
(
_engine
)
protocols
[
protocol
.
upper
()][
1
].
metadata
.
create_all
(
_engine
)
...
@@ -280,10 +279,20 @@ def scoped_session_maker(db_schema, idb_version=None):
...
@@ -280,10 +279,20 @@ def scoped_session_maker(db_schema, idb_version=None):
return
return
_engine
=
create_engine
(
gen_mysql_conn_str
(
schema
=
schema
),
echo
=
"
-v
"
in
sys
.
argv
,
pool_size
=
15
)
_engine
=
create_engine
(
gen_mysql_conn_str
(
schema
=
schema
),
echo
=
"
-v
"
in
sys
.
argv
,
pool_size
=
15
)
session_factory
=
sessionmaker
(
bind
=
_engine
)
session_factory
=
sessionmaker
(
bind
=
_engine
)
scoped_session_factory
=
scoped_session
(
session_factory
)
# scoped_session_factory = scoped_session(session_factory)
scoped_session_factory
=
scoped_session_v2
(
session_factory
)
return
scoped_session_factory
return
scoped_session_factory
class
scoped_session_v2
(
scoped_session
):
"""
Wrapper class to cast SQL query statement string to TextClause before execution, as this is required since SQLAlchemy 2.0.
"""
def
execute
(
self
,
x
,
*
args
,
**
kwargs
):
return
super
().
execute
(
text
(
x
),
*
args
,
**
kwargs
)
# def load_telemetry_file(dummy: str) -> None:
# def load_telemetry_file(dummy: str) -> None:
# '''Loads a telemetry dumpfile in the database, populating
# '''Loads a telemetry dumpfile in the database, populating
# the tm_pool and tm tables.
# the tm_pool and tm tables.
...
...
This diff is collapsed.
Click to expand it.
Ccs/tools/import_mib.py
+
4
−
3
View file @
87825e7e
...
@@ -11,6 +11,7 @@ import getpass
...
@@ -11,6 +11,7 @@ import getpass
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.sql
import
text
sdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
sdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
...
@@ -62,11 +63,11 @@ def create_schema():
...
@@ -62,11 +63,11 @@ def create_schema():
# delete database schema
# delete database schema
print
(
'
...drop schema {}
'
.
format
(
DBNAME
))
print
(
'
...drop schema {}
'
.
format
(
DBNAME
))
s
.
execute
(
'
DROP SCHEMA IF EXISTS {}
'
.
format
(
DBNAME
))
s
.
execute
(
text
(
'
DROP SCHEMA IF EXISTS {}
'
.
format
(
DBNAME
))
)
# create database schema
# create database schema
print
(
'
...create schema {}
'
.
format
(
DBNAME
))
print
(
'
...create schema {}
'
.
format
(
DBNAME
))
s
.
execute
(
open
(
WBSQL
).
read
())
s
.
execute
(
text
(
open
(
WBSQL
).
read
())
)
s
.
close
()
s
.
close
()
...
@@ -86,7 +87,7 @@ def import_mib():
...
@@ -86,7 +87,7 @@ def import_mib():
rows
=
[(
'"'
+
i
.
replace
(
'
\t
'
,
'"
,
"'
).
strip
()
+
'"'
).
replace
(
'""'
,
'
DEFAULT
'
)
for
i
in
mfile
]
rows
=
[(
'"'
+
i
.
replace
(
'
\t
'
,
'"
,
"'
).
strip
()
+
'"'
).
replace
(
'""'
,
'
DEFAULT
'
)
for
i
in
mfile
]
try
:
try
:
for
row
in
rows
:
for
row
in
rows
:
s
.
execute
(
'
INSERT IGNORE INTO {} VALUES ({})
'
.
format
(
fn
[:
-
4
],
row
))
# IGNORE truncates too long strings
s
.
execute
(
text
(
'
INSERT IGNORE INTO {} VALUES ({})
'
.
format
(
fn
[:
-
4
],
row
))
)
# IGNORE truncates too long strings
except
Exception
as
err
:
except
Exception
as
err
:
s
.
rollback
()
s
.
rollback
()
s
.
close
()
s
.
close
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment