简体   繁体   中英

Alembic and mysql on newest distro

I want to enable realtime configuration on asterisk server. In the 2021 with a Slackware current, all works fine, now with Slackware 15 and Debian 11 I fail.

I have installed the correct packages, configured and tested mariadb server, but when I try to populate the tables with alembic... On slackware-15.0 I get error about importing mysql python module (the package don't support python3 as web mainpage said).

On Debian 11 I get this error

alembic -c config.ini upgrade head
INFO  [alembic.runtime.setup] Testing for an old alembic_version table.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
/usr/lib/python3/dist-packages/alembic/script/revision.py:152: UserWarning: Revision 43956d550a44 referenced from 43956d550a44 -> 581a4264e537 (head), adding extensions is not present
  util.warn(
Traceback (most recent call last):
  File "/usr/bin/alembic", line 33, in <module>
    sys.exit(load_entry_point('alembic==1.4.3.dev0', 'console_scripts', 'alembic')())
  File "/usr/lib/python3/dist-packages/alembic/config.py", line 581, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/usr/lib/python3/dist-packages/alembic/config.py", line 575, in main
    self.run_cmd(cfg, options)
  File "/usr/lib/python3/dist-packages/alembic/config.py", line 552, in run_cmd
    fn(
  File "/usr/lib/python3/dist-packages/alembic/command.py", line 298, in upgrade
    script.run_env()
  File "/usr/lib/python3/dist-packages/alembic/script/base.py", line 489, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/usr/lib/python3/dist-packages/alembic/util/pyfiles.py", line 98, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/lib/python3/dist-packages/alembic/util/compat.py", line 184, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "config/env.py", line 152, in <module>
    run_migrations_online()
  File "config/env.py", line 93, in run_migrations_online
    for x in script.iterate_revisions('head', 'base'):
  File "/usr/lib/python3/dist-packages/alembic/script/revision.py", line 765, in _iterate_revisions
    requested_lowers = self.get_revisions(lower)
  File "/usr/lib/python3/dist-packages/alembic/script/revision.py", line 321, in get_revisions
    resolved_id, branch_label = self._resolve_revision_number(id_)
  File "/usr/lib/python3/dist-packages/alembic/script/revision.py", line 501, in _resolve_revision_number
    self._revision_map
  File "/usr/lib/python3/dist-packages/alembic/util/langhelpers.py", line 230, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/usr/lib/python3/dist-packages/alembic/script/revision.py", line 156, in _revision_map
    down_revision = map_[downrev]
KeyError: '43956d550a44'

any solution?

edit1: I have tested on opensuse 15.3 and all works fine, the packages related are

alembic
python2-alembic
python2-Mako
python2-SQLAlchemy
python2-mysql-connector-python
python2-mysqlclient
python2-python-dateutil
python2-python-editor

Workaround found.

a) create a vm,opensuse 15.3, install mariadb, alembic, and all deps

alembic
mariadb-server
mariadb-connector-odbc
asterisk
unixODBC
python2-alembic
python2-Mako
python2-SQLAlchemy
python2-mysql-connector-python
python2-mysqlclient
python2-python-dateutil
python2-python-editor

b)on the vm I create the database

mysql> create database asterisk;
mysql> create user myuser identified by 'password';
mysql> grant all on asterisk.* to myuser identified by 'password';
mysql> flush privileges;

c)then I download asterisk sources, extract on tmp folder, I go in the dir containing the dir ast-db-manage/

ast-db-manage/config.ini.sample
cp -av config.ini.sample config.ini
vim config.ini  #set user password...

d) finally insert the tables!

alembic -c config.ini upgrade head

e)testing the connection..

mysql -u myuser -p'password' -D asterisk -e '\s'

f)edit the two.ini files (the driver position and the file.ini position can be different, use locate or find)

vim /etc/odbcinst.ini
[MariaDB]
Driver      = libmaodbc.so
Description = MariaDB ODBC Connector

vim /etc/odbc.ini

[asterisk]
Description = MariaDB Asterisk
Driver = MariaDB
Database = asterisk
Server = localhost
User = myuser
Password = password
Port = 3306
Option = 3

g)test the odbc connector

isql -vv asterisk

h)finally dump the db and import on your slackware or debian machine

mysqldump -p asterisk > asteriskdb.dump

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM