This patch introduces a new identifier for channels: tenantid. It's a stringfield on the channel that can be used for general purposes. It will be inherited by other channels the same way that linkedid is. You can set tenantid in a few ways. The first is to set it in the dialplan with the Set and CHANNEL functions: exten => example,1,Set(CHANNEL(tenantid)=My tenant ID) It can also be accessed via CHANNEL: exten => example,2,NoOp(CHANNEL(tenantid)) Another method is to use the new tenantid option for pjsip endpoints in pjsip.conf: [my_endpoint] type=endpoint tenantid=My tenant ID This is considered the best approach since you will be able to see the tenant ID as early as the Newchannel event. It can also be set using set_var in pjsip.conf on the endpoint like setting other channel variable: set_var=CHANNEL(tenantid)=My tenant ID Note that set_var will not show tenant ID on the Newchannel event, however. Tenant ID has also been added to CDR. It's read-only and can be accessed via CDR(tenantid). You can also get the tenant ID of the last channel communicated with via CDR(peertenantid). Tenant ID will also show up in CEL records if it has been set, and the version number has been bumped accordingly. Fixes: #740 UserNote: tenantid has been added to channels. It can be read in dialplan via CHANNEL(tenantid), and it can be set using Set(CHANNEL(tenantid)=My tenant ID). In pjsip.conf, it is recommended to use the new tenantid option for pjsip endpoints (e.g., tenantid=My tenant ID) so that it will show up in Newchannel events. You can set it like any other channel variable using set_var in pjsip.conf as well, but note that this will NOT show up in Newchannel events. Tenant ID is also available in CDR and can be accessed with CDR(tenantid). The peer tenant ID can also be accessed with CDR(peertenantid). CEL includes tenant ID as well if it has been set. UpgradeNote: A new versioned struct (ast_channel_initializers) has been added that gets passed to __ast_channel_alloc_ap. The new function ast_channel_alloc_with_initializers should be used when creating channels that require the use of this struct. Currently the only value in the struct is for tenantid, but now more fields can be added to the struct as necessary rather than the __ast_channel_alloc_ap function. A new option (tenantid) has been added to endpoints in pjsip.conf as well. CEL has had its version bumped to include tenant ID. |
9 months ago | |
---|---|---|
.. | ||
cdr | Remove as much trailing whitespace as possible. | 7 years ago |
config | channel: Add multi-tenant identifier. | 9 months ago |
queue_log | ast-db-manage: Synchronize revisions between comments and code. | 2 years ago |
voicemail | app_voicemail_odbc: remove macrocontext from voicemail_messages table | 1 year ago |
.gitignore | alembic: Update list of TLS methods available on ps_transports. | 1 year ago |
README.md | contrib: Spelling fixes | 3 years ago |
cdr.ini.sample | alembic: Adjust sippeers, queue_members, and voicemail_messages tables. | 11 years ago |
config.ini.sample | alembic: Adjust sippeers, queue_members, and voicemail_messages tables. | 11 years ago |
env.py | alembic: Fix compatibility with SQLAlchemy 2.0+. | 1 year ago |
queue_log.ini.sample | queue_log: Add alembic script for generate db table for queue_log | 6 years ago |
voicemail.ini.sample | alembic: Adjust sippeers, queue_members, and voicemail_messages tables. | 11 years ago |
README.md
Asterisk Database Manager
Asterisk includes optional database integration for a variety of features. The purpose of this effort is to assist in managing the database schema for Asterisk database integration.
This is implemented as a set of repositories that contain database schema migrations, using Alembic. The existing repositories include:
cdr
- Table used for Asterisk to store CDR recordsconfig
- Tables used for Asterisk realtime configurationqueue_log
- Table used for Asterisk to store Queue Log recordsvoicemail
- Tables used forODBC_STORAGE
of voicemail messages
Alembic uses SQLAlchemy, which has support for many databases.
IMPORTANT NOTE: This is brand new and the initial migrations are still subject to change. Only use this for testing purposes for now.
Example Usage
First, create an ini file that contains database connection details. For help with connection string details, see the SQLAlchemy docs.
$ cp config.ini.sample config.ini
... edit config.ini and change sqlalchemy.url ...
Next, bring the database up to date with the current schema.
$ alembic -c config.ini upgrade head
In the future, as additional database migrations are added, you can run alembic again to migrate the existing tables to the latest schema.
$ alembic -c config.ini upgrade head
The migrations support both upgrading and downgrading. You could go all the way back to where you started with no tables by downgrading back to the base revision.
$ alembic -c config.ini downgrade base
base
and head
are special revisions. You can refer to specific revisions
to upgrade or downgrade to, as well.
$ alembic -c config.ini upgrade 4da0c5f79a9c
Offline Mode
If you would like to just generate the SQL statements that would have been executed, you can use alembic's offline mode.
$ alembic -c config.ini upgrade head --sql
Adding Database Migrations
The best way to learn about how to add additional database migrations is to refer to the Alembic documentation.