]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip: Change suppress_moh_on_sendonly to OPT_BOOL_T
authorGeorge Joseph <gjoseph@sangoma.com>
Fri, 15 Nov 2024 17:24:42 +0000 (10:24 -0700)
committerGeorge Joseph <gjoseph@sangoma.com>
Tue, 19 Nov 2024 19:55:40 +0000 (12:55 -0700)
The suppress_moh_on_sendonly endpoint option should have been
defined as OPT_BOOL_T in pjsip_configuration.c and AST_BOOL_VALUES
in the alembic script instead of OPT_YESNO_T and YESNO_VALUES.

Also updated contrib/ast-db-manage/README.md to indicate that
AST_BOOL_VALUES should always be used and provided an example.

Resolves: #995

contrib/ast-db-manage/README.md
contrib/ast-db-manage/config/versions/4f91fc18c979_add_suppress_moh_on_sendonly.py
res/res_pjsip/pjsip_configuration.c

index f2ba41ed8b250ef98c4317789fcc9ff79163f7f8..e3585be890b93531f59a69447326609080771cd0 100644 (file)
@@ -1,5 +1,4 @@
-Asterisk Database Manager
-=========================
+# 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
@@ -17,11 +16,8 @@ repositories include:
 Alembic uses SQLAlchemy, which has support for
 [many databases](http://docs.sqlalchemy.org/en/rel_0_8/dialects/index.html).
 
-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
--------------
+## Example Usage
 
 First, create an ini file that contains database connection details.  For help
 with connection string details, see the
@@ -50,16 +46,47 @@ to upgrade or downgrade to, as well.
 
     $ alembic -c config.ini upgrade 4da0c5f79a9c
 
-Offline Mode
-------------
+## 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
---------------------------
+## Adding Database Migrations
 
 The best way to learn about how to add additional database migrations is to
 refer to the [Alembic documentation](http://alembic.readthedocs.org).
+
+### Notes
+
+* For boolean columns, always use the AST_BOOL_VALUES type.  
+  Example:
+
+```
+from alembic import op
+import sqlalchemy as sa
+# This works for MySQL/MariaDB and others as well
+from sqlalchemy.dialects.postgresql import ENUM
+
+AST_BOOL_NAME = 'ast_bool_values'
+AST_BOOL_VALUES = [ '0', '1',
+                    'off', 'on',
+                    'false', 'true',
+                    'no', 'yes' ]
+
+def upgrade():
+    # ast_bool_values have already been created, so use postgres enum object type
+    # to get around "already created" issue - works okay with MySQL/MariaDB and others.
+    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
+    op.add_column('ps_endpoints', sa.Column('suppress_moh_on_sendonly', ast_bool_values))
+
+def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_suppress_moh_on_sendonly_ast_bool_values', 'ps_endpoints')
+    op.drop_column('ps_endpoints', 'suppress_moh_on_sendonly')
+```
+
+
+Older scripts used YESNO_VALUES but that is no longer supported.
+
index fb6a3efc7190e8320293c886b521d7ca857cdd0f..777889ab7cd8d8fd97eb6ab0a462752bcdca0a14 100644 (file)
@@ -14,17 +14,17 @@ from alembic import op
 import sqlalchemy as sa
 from sqlalchemy.dialects.postgresql import ENUM
 
-YESNO_NAME = 'yesno_values'
-YESNO_VALUES = ['yes', 'no']
-
+AST_BOOL_NAME = 'ast_bool_values'
+AST_BOOL_VALUES = [ '0', '1',
+                    'off', 'on',
+                    'false', 'true',
+                    'no', 'yes' ]
 
 def upgrade():
-    yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
-
-    op.add_column('ps_endpoints', sa.Column('suppress_moh_on_sendonly', yesno_values))
-
+    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
+    op.add_column('ps_endpoints', sa.Column('suppress_moh_on_sendonly', ast_bool_values))
 
 def downgrade():
     if op.get_context().bind.dialect.name == 'mssql':
-        op.drop_constraint('ck_ps_endpoints_suppress_moh_on_sendonly_yesno_values', 'ps_endpoints')
+        op.drop_constraint('ck_ps_endpoints_suppress_moh_on_sendonly_ast_bool_values', 'ps_endpoints')
     op.drop_column('ps_endpoints', 'suppress_moh_on_sendonly')
index 8ac1d2c24031d35f14371ebbae2c0d9dde85bbf9..03c4aad9eb4ef20b328e023ff97de39e15b82b98 100644 (file)
@@ -2305,7 +2305,7 @@ int ast_res_pjsip_initialize_configuration(void)
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_aoc", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_aoc));
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "tenantid", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, tenantid));
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "suppress_moh_on_sendonly",
-               "no", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, suppress_moh_on_sendonly));
+               "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, suppress_moh_on_sendonly));
 
        if (ast_sip_initialize_sorcery_transport()) {
                ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");