-
Notifications
You must be signed in to change notification settings - Fork 408
Automatic addition of database before connecting to it #4316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
01343fb
to
e39cd16
Compare
e39cd16
to
32aae73
Compare
0f4c534
to
8d84c11
Compare
e20770d
to
451b2a2
Compare
…onality of add_product
f9dffb1
to
2bed7bb
Compare
1111841
to
e25167e
Compare
3beb9b8
to
59dcff3
Compare
59dcff3
to
b95b3aa
Compare
82205e7
to
078f1a3
Compare
@@ -306,6 +309,58 @@ def getProductConfiguration(self, product_id): | |||
|
|||
return prod | |||
|
|||
@timeit | |||
def add_product_support(self, product): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions that are not on the API could be "private", i.e. having double underscore prefix in their name: __add_product_support
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
to assist addProduct() function that connects to | ||
an already existing database. | ||
""" | ||
self.__require_permission([permissions.SUPERUSER]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only API functions need to check permission. This function can't be called from outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, check removed
@@ -912,6 +915,46 @@ def add_product(self, orm_product, init_db=False): | |||
|
|||
self.__products[prod.endpoint] = prod | |||
|
|||
def get_if_database_in_use(self, product): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_if_database_in_use(self, product): | |
def is_database_used(self, connection): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
""" | ||
# get the database name from the product connection string | ||
is_sqlite = False | ||
if product.database.endswith('.sqlite'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if product.database.endswith('.sqlite'): | |
if product.engine == 'sqlite': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
LOG.info("The database string that will be added: %s", to_add) | ||
|
||
LOG.info("to add: %s", to_add) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
] | ||
|
||
# True if found, False otherwise | ||
LOG.info("dynamic list: %s", dynamic_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
# remove the first 16 charecters because in query it is | ||
# included in the path string | ||
dynamic_list = [ | ||
d[16:] if d.endswith('.sqlite') else d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't rely on the length of a specific connection string prefix. d.split(':', 1)
would split the connection string on the first :
character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
# remove the first 16 charecters because in query it is | ||
# included in the path string | ||
dynamic_list = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be merged with the previous list comprehension in line 936.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
# get the current state of connected databases from products | ||
dynamic_list = [ | ||
a.connection.replace('////', '/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQLAlchemy can be used for parsing the connection string: https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.engine.make_url
This could be used for a better check condition in the loop at line 951.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
054fa4b
to
14414fe
Compare
3748e36
to
09f1ae7
Compare
09f1ae7
to
83177b0
Compare
Introduced a new function
add_product_support()
using SQLAlchemy to enhance theaddProduct()
function.Automates the creation of the database for PostgreSQL and SQLite, eliminating the need for a manual script before connection.
Note: SQLite already supports automatic database creation.
Note2: The deletion of product doesn't delete the Postgres database, it was intentional , in case of accidental removal