Skip to content

Commit 100417f

Browse files
committed
db: register PyMySQL as MySQLdb so mysql:// URLs work without +pymysql
Call pymysql.install_as_MySQLdb() on startup so SQLAlchemy's mysql:// dialect picks up PyMySQL automatically. Revert all mysql+pymysql:// URLs back to mysql:// in defaults, docs, tests, and the database module.
1 parent 91a4ac1 commit 100417f

5 files changed

Lines changed: 16 additions & 14 deletions

File tree

docs/modules/database.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ are using the OpenSIPS source tree. Default: `/usr/share/opensips`
4141
(administrator) access level which will be used to create/drop databases, as
4242
well as to create or ensure access for the non-privileged DB access user
4343
provided via `database_url`. The URL combines schema, username, password, host
44-
and port. Default: `mysql+pymysql://root@localhost`.
44+
and port. Default: `mysql://root@localhost`.
4545
* `database_url` (optional) - the connection string to the database. A good practice
4646
would be to use a non-administrator access user for this URL. Default:
47-
`mysql+pymysql://opensips:opensipsrw@localhost`.
47+
`mysql://opensips:opensipsrw@localhost`.
4848
* `database_name` (optional) - the name of the database. Modules may be separately added
4949
to this database if you choose not to install all of them. Default: `opensips`.
5050
* `database_modules` (optional) - accepts the `ALL` keyword that indicates all the
@@ -68,7 +68,7 @@ Consider the following configuration file:
6868
database_modules: ALL
6969
7070
#database_admin_url: postgresql://root@localhost
71-
database_admin_url: mysql+pymysql://root@localhost
71+
database_admin_url: mysql://root@localhost
7272
```
7373

7474
The following command will create the `opensips` database and all possible

opensipscli/db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
# PostgreSQL on Bullseye; 0.41.x is required for SA 2.0); the shim is
4343
# tested against SA 1.3–2.0 and behaves consistently
4444
from opensipscli.libs import sqlalchemy_utils
45+
import pymysql
46+
pymysql.install_as_MySQLdb()
4547
except ImportError:
4648
logger.info("sqlalchemy not available!")
4749
sqlalchemy_available = False

opensipscli/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"datagram_buffer_size": "65535",
7272

7373
# database module
74-
"database_url": "mysql+pymysql://opensips:opensipsrw@localhost",
74+
"database_url": "mysql://opensips:opensipsrw@localhost",
7575
"database_name": "opensips",
7676
"database_schema_path": "/usr/share/opensips",
7777

test/alltests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ def testMakeURL(self):
2626
assert repr(u) == 'x://user:***@host:12/db'
2727
assert str(u) == 'x://user:pass@host:12/db'
2828

29-
u = make_url('mysql+pymysql://opensips:opensipsrw@localhost/opensips')
30-
assert repr(u) == 'mysql+pymysql://opensips:***@localhost/opensips'
31-
assert str(u) == 'mysql+pymysql://opensips:opensipsrw@localhost/opensips'
29+
u = make_url('mysql://opensips:opensipsrw@localhost/opensips')
30+
assert repr(u) == 'mysql://opensips:***@localhost/opensips'
31+
assert str(u) == 'mysql://opensips:opensipsrw@localhost/opensips'
3232

33-
u = make_url('mysql+pymysql://opensips:opensipsrw@localhost')
34-
assert repr(u) == 'mysql+pymysql://opensips:***@localhost'
35-
assert str(u) == 'mysql+pymysql://opensips:opensipsrw@localhost'
33+
u = make_url('mysql://opensips:opensipsrw@localhost')
34+
assert repr(u) == 'mysql://opensips:***@localhost'
35+
assert str(u) == 'mysql://opensips:opensipsrw@localhost'
3636

37-
u = make_url('mysql+pymysql://root@localhost')
38-
assert repr(u) == 'mysql+pymysql://root@localhost'
39-
assert str(u) == 'mysql+pymysql://root@localhost'
37+
u = make_url('mysql://root@localhost')
38+
assert repr(u) == 'mysql://root@localhost'
39+
assert str(u) == 'mysql://root@localhost'
4040

4141

4242
if __name__ == "__main__":

test/test-database.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
CLI_CFG=/tmp/.__cli.cfg
2121
DB_NAME=_opensips_cli_test
2222

23-
MYSQL_URL=mysql+pymysql://opensips:opensipsrw@localhost
23+
MYSQL_URL=mysql://opensips:opensipsrw@localhost
2424
PGSQL_URL=postgresql://opensips:opensipsrw@localhost
2525

2626
TESTS=(

0 commit comments

Comments
 (0)