queue_log: Add alembic script for generate db table for queue_log
authorRodrigo Ramírez Norambuena <a@rodrigoramirez.com>
Sat, 1 Oct 2016 02:56:04 +0000 (23:56 -0300)
committerRodrigo Ramírez Norambuena <a@rodrigoramirez.com>
Fri, 22 Nov 2019 15:33:29 +0000 (15:33 +0000)
Change-Id: I35b928a6251f9da9a1742b2cd14c63a00c3d0f0c

contrib/ast-db-manage/README.md
contrib/ast-db-manage/queue_log.ini.sample [new file with mode: 0644]
contrib/ast-db-manage/queue_log/env.py [new symlink]
contrib/ast-db-manage/queue_log/script.py.mako [new file with mode: 0644]
contrib/ast-db-manage/queue_log/versions/4105ee839f58_create_queue_log_table.py [new file with mode: 0644]

index 7add3ee..42f2376 100644 (file)
@@ -11,6 +11,7 @@ repositories include:
 
  * `cdr` - Table used for Asterisk to store CDR records
  * `config` - Tables used for Asterisk realtime configuration
+ * `queue_log` - Table used for Asterisk to store Queue Log records
  * `voicemail` - Tables used for `ODBC_STOARGE` of voicemail messages
 
 Alembic uses SQLAlchemy, which has support for
diff --git a/contrib/ast-db-manage/queue_log.ini.sample b/contrib/ast-db-manage/queue_log.ini.sample
new file mode 100644 (file)
index 0000000..ada14b5
--- /dev/null
@@ -0,0 +1,58 @@
+# A generic, single database configuration.
+
+[alembic]
+# path to migration scripts
+script_location = queue_log
+
+# template used to generate migration files
+# file_template = %%(rev)s_%%(slug)s
+
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
+# set to 'true' to run the environment during
+# the 'revision' command, regardless of autogenerate
+# revision_environment = false
+
+#sqlalchemy.url = driver://user:pass@localhost/dbname
+
+
+#sqlalchemy.url = mysql://user:pass@localhost/queue_log
+sqlalchemy.url = postgresql://user:pass@localhost/queue_log
+
+
+# Logging configuration
+[loggers]
+keys = root,sqlalchemy,alembic
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+qualname =
+
+[logger_sqlalchemy]
+level = WARN
+handlers =
+qualname = sqlalchemy.engine
+
+[logger_alembic]
+level = INFO
+handlers =
+qualname = alembic
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(levelname)-5.5s [%(name)s] %(message)s
+datefmt = %H:%M:%S
diff --git a/contrib/ast-db-manage/queue_log/env.py b/contrib/ast-db-manage/queue_log/env.py
new file mode 120000 (symlink)
index 0000000..74b15c9
--- /dev/null
@@ -0,0 +1 @@
+../env.py
\ No newline at end of file
diff --git a/contrib/ast-db-manage/queue_log/script.py.mako b/contrib/ast-db-manage/queue_log/script.py.mako
new file mode 100644 (file)
index 0000000..43c0940
--- /dev/null
@@ -0,0 +1,24 @@
+"""${message}
+
+Revision ID: ${up_revision}
+Revises: ${down_revision | comma,n}
+Create Date: ${create_date}
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = ${repr(up_revision)}
+down_revision = ${repr(down_revision)}
+branch_labels = ${repr(branch_labels)}
+depends_on = ${repr(depends_on)}
+
+from alembic import op
+import sqlalchemy as sa
+${imports if imports else ""}
+
+def upgrade():
+    ${upgrades if upgrades else "pass"}
+
+
+def downgrade():
+    ${downgrades if downgrades else "pass"}
diff --git a/contrib/ast-db-manage/queue_log/versions/4105ee839f58_create_queue_log_table.py b/contrib/ast-db-manage/queue_log/versions/4105ee839f58_create_queue_log_table.py
new file mode 100644 (file)
index 0000000..7c4a04e
--- /dev/null
@@ -0,0 +1,38 @@
+"""create queue_log table
+
+Revision ID: 4105ee839f58
+Revises:
+Create Date: 2016-09-30 22:32:45.918340
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '4105ee839f58'
+down_revision = None
+branch_labels = None
+depends_on = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    op.create_table(
+        'queue_log',
+        sa.Column('id', sa.BigInteger, primary_key=True, nullable=False,
+                  unique=True, autoincrement=True),
+        sa.Column('time', sa.DateTime()),
+        sa.Column('callid', sa.String(80)),
+        sa.Column('queuename', sa.String(256)),
+        sa.Column('agent', sa.String(80)),
+        sa.Column('event', sa.String(32)),
+        sa.Column('data1', sa.String(100)),
+        sa.Column('data2', sa.String(100)),
+        sa.Column('data3', sa.String(100)),
+        sa.Column('data4', sa.String(100)),
+        sa.Column('data5', sa.String(100))
+    )
+
+
+def downgrade():
+    op.drop_table('queue_log')