You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/Managing-Realtime-Databases-with-Alembic.md
+39-34Lines changed: 39 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,67 +2,74 @@
2
2
title: Managing Realtime Databases with Alembic
3
3
---
4
4
5
-
Overview
6
-
========
5
+
# Overview
7
6
8
-
Asterisk 12 now uses[Alembic](https://pypi.python.org/pypi/alembic) to help manage Asterisk Realtime Database schemas. This includes creation of SQL scripts for a variety of database vendors, but also much more. Alembic is a full database migration tool, with support for upgrading the schemas of existing databases, versioning of schemas, creation of new tables and databases, and a whole lot more. This page covers basic configuration of the Alembic configuration file for usage with Asterisk Realtime as well as basic usage of Alembic. While a full description of Alembic is beyond the scope of this page, the information on this page should help an Asterisk administrator create or upgrade an Asterisk installation.
7
+
Asterisk 12 now uses[Alembic](https://pypi.python.org/pypi/alembic) to help manage Asterisk Realtime Database schemas. This includes creation of SQL scripts for a variety of database vendors, but also much more. Alembic is a full database migration tool, with support for upgrading the schemas of existing databases, versioning of schemas, creation of new tables and databases, and a whole lot more. This page covers basic configuration of the Alembic configuration file for usage with Asterisk Realtime as well as basic usage of Alembic. While a full description of Alembic is beyond the scope of this page, the information on this page should help an Asterisk administrator create or upgrade an Asterisk installation.
9
8
10
-
Alembic makes upgrading less painfulAs Asterisk changes and new fields are made controllable via realtime, new Alembic change scripts are added so you will be able to simply run the Alembic upgrade command again in order to modify your database.
9
+
Alembic makes upgrading less painful. As Asterisk changes and new fields are made controllable via realtime, new Alembic change scripts are added so you will be able to simply run the Alembic upgrade command again in order to modify your database.
11
10
12
-
While Alembic helps with database migrations within a release series (e.g., Asterisk 13.x.x) it does not work very well when jumping to a different release series (e.g., jumping from Asterisk 13.x.x to Asterisk 15.x.x). Data loss is possible when jumping to a different release series. Before a new series (e.g., Asterisk 15.0.0) is initially released breaking changes can be introduced that can result in data loss.
13
-
14
-
Always exercise due diligence and backup your database before upgrading. Tables can be fixed easily. Repopulating the data if it's lost however isn't.
11
+
While Alembic helps with database migrations within a release series (e.g., Asterisk 13.x.x) it does not work very well when jumping to a different release series (e.g., jumping from Asterisk 13.x.x to Asterisk 15.x.x).
12
+
- Data loss is possible when jumping to a different release series.
13
+
- Before a new series (e.g., Asterisk 15.0.0) is initially released breaking changes can be introduced that can result in data loss.
14
+
- Always exercise due diligence and backup your database before upgrading.
15
+
- Tables can be fixed easily.
16
+
- Repopulating the data if it's lost however isn't.
15
17
16
18
Please read the CHANGES file and the applicable UPGRADE files for important information about what changed between revisions.
17
19
18
-
Before you Begin
19
-
----------------
20
+
## Before you Begin
20
21
21
-
This tutorial assumes you already have some experience in setting up Realtime configuration with Asterisk for other modules. This page will not describe how to set up backend database connectors, and is written under the assumption that you will be using ODBC to connect to your database since the ODBC adaptor is capable of connecting to most commonly used database servers. For more information on configuring and setting up Asterisk Realtime, seeAsterisk Realtime Database configuration.
22
+
This tutorial assumes you already have some experience in setting up Realtime configuration with Asterisk for other modules. This page will not describe how to set up backend database connectors, and is written under the assumption that you will be using ODBC to connect to your database since the ODBC adaptor is capable of connecting to most commonly used database servers. For more information on configuring and setting up Asterisk Realtime, see: [Asterisk Realtime Database configuration](/Fundamentals/Asterisk-Configuration/Database-Support-Configuration/Realtime-Database-Configuration).
22
23
23
-
Installing Alembic
24
-
==================
24
+
## Installing Alembic
25
25
26
26
If you don't already have Alembic installed, perform the following:
27
27
28
28
This does assume that you have pip installed. If you do not have pip installed, easy\_install should work just as well. If you don't have [pip](https://github.com/pypa/pip) or easy\_install (or Python), then you should probably install those first.
29
29
30
-
$ pip install alembicAnd that's it!
30
+
```sh
31
+
pip install alembic
32
+
```
33
+
34
+
And that's it!
35
+
36
+
## Building the Database Tables
37
+
31
38
32
-
Building the Database Tables
33
-
============================
39
+
Alembic scripts were added to Asterisk in Asterisk 12, and will allow you to automatically populate your database with tables for most of the commonly used configuration options. The scripts are located in the [Asterisk contrib/ast-db-manage](http://svn.asterisk.org/svn/asterisk/trunk/contrib/ast-db-manage/) folder:
34
40
35
-
Alembic scripts were added to Asterisk in Asterisk 12, and will allow you to automatically populate your database with tables for most of the commonly used configuration options. The scripts are located in the [Asterisk contrib/ast-db-manage](http://svn.asterisk.org/svn/asterisk/trunk/contrib/ast-db-manage/) folder:
41
+
```sh
42
+
$ cd contrib/ast-db-manage
43
+
```
36
44
37
-
$ cd contrib/ast-db-manageFor the rest of this tutorial, we will assume that operations will be taken in the context of that directory.
45
+
For the rest of this tutorial, we will assume that operations will be taken in the context of that directory.
38
46
39
-
Configuring Alembic
40
-
-------------------
47
+
## Configuring Alembic
41
48
42
-
Within this directory, you will find a configuration sample file, `config.ini.sample`, which will need to be edited to connect to your database of choice. Open this file in your text editor of choice and then save a copy of this sample file as `config.ini`- this will serve as the configuration file you actually use with Alembic.
49
+
Within this directory, you will find a configuration sample file, `config.ini.sample`, which will need to be edited to connect to your database of choice. Open this file in your text editor of choice and then save a copy of this sample file as `config.ini`- this will serve as the configuration file you actually use with Alembic.
43
50
44
-
There are two different parameters in`config.ini` that require review:`sqlalchemy.url` and`script_location`. The first specifies the database to upgrade; the second which upgrades to perform.
51
+
There are two different parameters in`config.ini` that require review:`sqlalchemy.url` and`script_location`. The first specifies the database to upgrade; the second which upgrades to perform.
45
52
46
-
1. Update`sqlalchemy.url` to the URL for your database. An example is shown below for a MySQL database:
53
+
1. Update`sqlalchemy.url` to the URL for your database. An example is shown below for a MySQL database:
47
54
48
-
sqlalchemy.url = mysql://root:password@localhost/asteriskThis would connect to a MySQL database as user`root` with password`password`. The database is`asterisk`, located on`localhost`. Different databases will require different URL schemas; however, they should in general follow the format outlined above. Alembic supports many different database technologies, including`oracle`,`postgresql`, and`mssql`.
55
+
sqlalchemy.url = mysql://root:password@localhost/asteriskThis would connect to a MySQL database as user`root` with password`password`. The database is`asterisk`, located on`localhost`. Different databases will require different URL schemas; however, they should in general follow the format outlined above. Alembic supports many different database technologies, including`oracle`,`postgresql`, and`mssql`.
49
56
50
-
For more information, see the Alembic documentation on SQLAlchemy URLs:<http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html#database-urls>
51
-
2. Update`script_location` to the schema to update. Asterisk currently supports two sets of schemas:
57
+
For more information, see the Alembic documentation on SQLAlchemy URLs:<http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html#database-urls>
58
+
2. Update`script_location` to the schema to update. Asterisk currently supports two sets of schemas:
52
59
1. `config` - the set of schemas for Asterisk Realtime databases
53
60
2. `voicemail` - the schema for ODBC VoiceMail
54
61
55
-
Executing the database upgrade
56
-
------------------------------
62
+
## Executing the database upgrade
63
+
57
64
58
65
I'm sorry Dave, I'm afraid I can't let you do that.Using config.ini for Alembic will populate tables for all of the configuration objects that can be populated this way, so if you really don't want a table for sip peers, iax friends, voicemail, meetme, and music on hold, you may need to exercise a little fine control. Back up your database before continuing and be prepared to delete tables that you don't want when you are finished.
59
66
60
67
Your config.ini should be ready for use at this point, so close your text editor and return to the terminal. Then run:
61
68
62
69
$ alembic -c config.ini upgrade headAt this point, if you configured your config.ini to connect to the database properly, your tables should be ready.
63
70
64
-
Troubleshooting the upgrade
65
-
---------------------------
71
+
## Troubleshooting the upgrade
72
+
66
73
67
74
**Symptom:** Running 'alembic -c config.ini upgrade head' fails with a traceback:
68
75
@@ -76,8 +83,6 @@ ImportError: No module named MySQLdb**Solution**: You probably need the Python i
76
83
77
84
For example, with Ubuntu, install the following package and then re-run your Alembic upgrade.
| AST\_CAUSE\_NORMAL\_CIRCUIT\_CONGESTION | 34. No circuit/channel available(Note that we've called this "Circuit/channel congestion" for a while which can cause confusion with code 42) | OR2\_CAUSE\_NETWORK\_CONGESTION || general-error |
35
-
| AST\_CAUSE\_NETWORK\_OUT\_OF\_ORDER | 38. Network out of order || 500 ||
| AST\_CAUSE\_NORMAL\_CIRCUIT\_CONGESTION | 34. No circuit/channel available(Note that we've called this "Circuit/channel congestion" for a while which can cause confusion with code 42) | OR2\_CAUSE\_NETWORK\_CONGESTION || general-error |
35
+
| AST\_CAUSE\_NETWORK\_OUT\_OF\_ORDER | 38. Network out of order || 500 ||
0 commit comments