From 296ba2347c2220d467c67949ffb50a295e7dbbae Mon Sep 17 00:00:00 2001 From: nickolasdaniel Date: Fri, 11 Mar 2022 16:50:10 +0200 Subject: [PATCH] Made a symlink to db scripts and modified Dockerfile and entrypoint script for cgrates integration image --- data/docker/integration/Dockerfile | 17 +- data/docker/integration/docker-entrypoint.sh | 5 +- data/docker/integration/scripts/mongo | 1 + .../integration/scripts/mongo/create_user.js | 9 - .../integration/scripts/mongo/setup_cgr_db.sh | 14 - data/docker/integration/scripts/mysql | 1 + .../mysql/create_db_with_users_extra.sql | 9 - data/docker/integration/scripts/postgres | 1 + .../scripts/postgres/create_cdrs_tables.sql | 59 --- .../scripts/postgres/create_db_with_users.sh | 9 - .../scripts/postgres/create_ers_db.sh | 4 - .../postgres/create_tariffplan_tables.sql | 477 ------------------ .../scripts/postgres/pg_cdr_migration.sql | 42 -- .../scripts/postgres/setup_cgr_db.sh | 30 -- 14 files changed, 16 insertions(+), 662 deletions(-) create mode 120000 data/docker/integration/scripts/mongo delete mode 100644 data/docker/integration/scripts/mongo/create_user.js delete mode 100755 data/docker/integration/scripts/mongo/setup_cgr_db.sh create mode 120000 data/docker/integration/scripts/mysql delete mode 100644 data/docker/integration/scripts/mysql/create_db_with_users_extra.sql create mode 120000 data/docker/integration/scripts/postgres delete mode 100644 data/docker/integration/scripts/postgres/create_cdrs_tables.sql delete mode 100755 data/docker/integration/scripts/postgres/create_db_with_users.sh delete mode 100755 data/docker/integration/scripts/postgres/create_ers_db.sh delete mode 100644 data/docker/integration/scripts/postgres/create_tariffplan_tables.sql delete mode 100644 data/docker/integration/scripts/postgres/pg_cdr_migration.sql delete mode 100755 data/docker/integration/scripts/postgres/setup_cgr_db.sh diff --git a/data/docker/integration/Dockerfile b/data/docker/integration/Dockerfile index 7cdc8087d..9802832c0 100644 --- a/data/docker/integration/Dockerfile +++ b/data/docker/integration/Dockerfile @@ -4,7 +4,7 @@ RUN groupadd -r mongodb && useradd -r -g mongodb mongodb RUN groupadd -r redis && useradd -r -g redis redis RUN groupadd -r kafka && useradd -r -g kafka kafka -RUN mkdir -p /usr/share/man/man1 /var/spool/cgrates/ers/in /var/spool/cgrates/ers/out /var/spool/cgrates/cdre/csv /var/spool/cgrates/cdre/fwv /var/spool/cgrates/tpe /var/spool/cgrates/failed_posts /var/spool/cgrates/analyzers /run /data/configdb /data/db /kafka /logs +RUN mkdir -p /usr/share/cgrates/conf /usr/share/man/man1 /var/spool/cgrates/ers/in /var/spool/cgrates/ers/out /var/spool/cgrates/cdre/csv /var/spool/cgrates/cdre/fwv /var/spool/cgrates/tpe /var/spool/cgrates/failed_posts /var/spool/cgrates/analyzers /run /data/configdb /data/db /kafka /logs RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections @@ -18,8 +18,11 @@ RUN echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | RUN wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list -RUN wget -qO - https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | apt-key add - -RUN printf "deb https://dl.bintray.com/rabbitmq-erlang/debian buster erlang\ndeb https://dl.bintray.com/rabbitmq/debian buster main" | tee /etc/apt/sources.list.d/bintray.rabbitmq.list +RUN wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb +RUN dpkg -i erlang-solutions_1.0_all.deb +RUN apt-get update +RUN apt-get install -y erlang erlang-nox +RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash RUN apt-get update RUN apt-get install -y mongodb-org postgresql rabbitmq-server @@ -27,9 +30,9 @@ RUN apt-get install -y mongodb-org postgresql rabbitmq-server WORKDIR /kafka -RUN wget "https://archive.apache.org/dist/kafka/2.1.1/kafka_2.11-2.1.1.tgz" -RUN tar -xvzf ./kafka_2.11-2.1.1.tgz --strip 1 -RUN rm kafka_2.11-2.1.1.tgz +RUN wget "https://archive.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz" +RUN tar -xvzf ./kafka_2.11-2.1.0.tgz --strip 1 +RUN rm kafka_2.11-2.1.0.tgz COPY ./conf/server.properties /kafka/config/server.properties WORKDIR / @@ -50,7 +53,7 @@ RUN set -ex; \ echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf -RUN wget -O go.tgz "https://storage.googleapis.com/golang/go1.15.7.linux-amd64.tar.gz" --progress=dot:giga +RUN wget -O go.tgz "https://storage.googleapis.com/golang/go1.17.7.linux-amd64.tar.gz" --progress=dot:giga RUN tar -C /usr/local -xzf go.tgz RUN rm go.tgz diff --git a/data/docker/integration/docker-entrypoint.sh b/data/docker/integration/docker-entrypoint.sh index c8b9aa57f..55a8426c6 100755 --- a/data/docker/integration/docker-entrypoint.sh +++ b/data/docker/integration/docker-entrypoint.sh @@ -7,7 +7,8 @@ export KAFKA_HEAP_OPTS="-Xmx100M -Xms100M" /kafka/bin/kafka-server-start.sh -daemon /kafka/config/server.properties rsyslogd -f /etc/rsyslogd.conf -pg_ctlcluster 13 main start & +version=$(ls /var/lib/postgresql) +pg_ctlcluster $version main start & mongod --bind_ip 127.0.0.1 --logpath /logs/mongodb.log & redis-server /etc/redis/redis.conf & MYSQL_ROOT_PASSWORD="CGRateS.org" /scripts/mariadb-ep.sh mysqld > /logs/mariadb_script.log 2>&1 @@ -56,4 +57,4 @@ mysql -u root -pCGRateS.org -h localhost < /scripts/mysql/create_db_with_users_e mysql -u root -pCGRateS.org -h localhost -D cgrates < /scripts/mysql/create_cdrs_tables.sql > /dev/null 2>&1 mysql -u root -pCGRateS.org -h localhost -D cgrates < /scripts/mysql/create_tariffplan_tables.sql > /dev/null 2>&1 -ln -s /cgrates/data /usr/share/cgrates \ No newline at end of file +cp -r data/. /usr/share/cgrates \ No newline at end of file diff --git a/data/docker/integration/scripts/mongo b/data/docker/integration/scripts/mongo new file mode 120000 index 000000000..221af3976 --- /dev/null +++ b/data/docker/integration/scripts/mongo @@ -0,0 +1 @@ +../../../storage/mongo/ \ No newline at end of file diff --git a/data/docker/integration/scripts/mongo/create_user.js b/data/docker/integration/scripts/mongo/create_user.js deleted file mode 100644 index 169461df6..000000000 --- a/data/docker/integration/scripts/mongo/create_user.js +++ /dev/null @@ -1,9 +0,0 @@ -db = db.getSiblingDB('cgrates') -db.createUser( - { - user: "cgrates", - pwd: "CGRateS.org", - roles: [ { role: "dbAdmin", db: "cgrates" } ] - } -) - diff --git a/data/docker/integration/scripts/mongo/setup_cgr_db.sh b/data/docker/integration/scripts/mongo/setup_cgr_db.sh deleted file mode 100755 index 4cbc93516..000000000 --- a/data/docker/integration/scripts/mongo/setup_cgr_db.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /usr/bin/env sh - - -mongo --quiet create_user.js -cu=$? - -if [ $cu = 0 ]; then - echo "" - echo "\t+++ CGR-DB successfully set-up! +++" - echo "" - exit 0 -fi - - diff --git a/data/docker/integration/scripts/mysql b/data/docker/integration/scripts/mysql new file mode 120000 index 000000000..50ba904e1 --- /dev/null +++ b/data/docker/integration/scripts/mysql @@ -0,0 +1 @@ +../../../storage/mysql/ \ No newline at end of file diff --git a/data/docker/integration/scripts/mysql/create_db_with_users_extra.sql b/data/docker/integration/scripts/mysql/create_db_with_users_extra.sql deleted file mode 100644 index 2d9e5c601..000000000 --- a/data/docker/integration/scripts/mysql/create_db_with_users_extra.sql +++ /dev/null @@ -1,9 +0,0 @@ - --- --- Sample db and users creation. Replace here with your own details --- - -CREATE DATABASE cgrates2; - -GRANT ALL on cgrates.* TO 'cgrates'@'127.0.0.1' IDENTIFIED BY 'CGRateS.org'; -GRANT ALL on cgrates2.* TO 'cgrates'@'127.0.0.1' IDENTIFIED BY 'CGRateS.org'; diff --git a/data/docker/integration/scripts/postgres b/data/docker/integration/scripts/postgres new file mode 120000 index 000000000..a019a3978 --- /dev/null +++ b/data/docker/integration/scripts/postgres @@ -0,0 +1 @@ +../../../storage/postgres/ \ No newline at end of file diff --git a/data/docker/integration/scripts/postgres/create_cdrs_tables.sql b/data/docker/integration/scripts/postgres/create_cdrs_tables.sql deleted file mode 100644 index 3ae7d5ccb..000000000 --- a/data/docker/integration/scripts/postgres/create_cdrs_tables.sql +++ /dev/null @@ -1,59 +0,0 @@ --- --- Table structure for table `cdrs` --- - -DROP TABLE IF EXISTS cdrs; -CREATE TABLE cdrs ( - id SERIAL PRIMARY KEY, - cgrid VARCHAR(40) NOT NULL, - run_id VARCHAR(64) NOT NULL, - origin_host VARCHAR(64) NOT NULL, - source VARCHAR(64) NOT NULL, - origin_id VARCHAR(128) NOT NULL, - tor VARCHAR(16) NOT NULL, - request_type VARCHAR(24) NOT NULL, - tenant VARCHAR(64) NOT NULL, - category VARCHAR(64) NOT NULL, - account VARCHAR(128) NOT NULL, - subject VARCHAR(128) NOT NULL, - destination VARCHAR(128) NOT NULL, - setup_time TIMESTAMP WITH TIME ZONE NOT NULL, - answer_time TIMESTAMP WITH TIME ZONE NULL, - usage BIGINT NOT NULL, - extra_fields jsonb NOT NULL, - cost_source VARCHAR(64) NOT NULL, - cost NUMERIC(20,4) DEFAULT NULL, - cost_details jsonb, - extra_info text, - created_at TIMESTAMP WITH TIME ZONE, - updated_at TIMESTAMP WITH TIME ZONE NULL, - deleted_at TIMESTAMP WITH TIME ZONE NULL, - UNIQUE (cgrid, run_id) -); -; -DROP INDEX IF EXISTS deleted_at_cp_idx; -CREATE INDEX deleted_at_cp_idx ON cdrs (deleted_at); - - -DROP TABLE IF EXISTS session_costs; -CREATE TABLE session_costs ( - id SERIAL PRIMARY KEY, - cgrid VARCHAR(40) NOT NULL, - run_id VARCHAR(64) NOT NULL, - origin_host VARCHAR(64) NOT NULL, - origin_id VARCHAR(128) NOT NULL, - cost_source VARCHAR(64) NOT NULL, - usage BIGINT NOT NULL, - cost_details jsonb, - created_at TIMESTAMP WITH TIME ZONE, - deleted_at TIMESTAMP WITH TIME ZONE NULL, - UNIQUE (cgrid, run_id) -); -DROP INDEX IF EXISTS cgrid_sessionscost_idx; -CREATE INDEX cgrid_sessionscost_idx ON session_costs (cgrid, run_id); -DROP INDEX IF EXISTS origin_sessionscost_idx; -CREATE INDEX origin_sessionscost_idx ON session_costs (origin_host, origin_id); -DROP INDEX IF EXISTS run_origin_sessionscost_idx; -CREATE INDEX run_origin_sessionscost_idx ON session_costs (run_id, origin_id); -DROP INDEX IF EXISTS deleted_at_sessionscost_idx; -CREATE INDEX deleted_at_sessionscost_idx ON session_costs (deleted_at); diff --git a/data/docker/integration/scripts/postgres/create_db_with_users.sh b/data/docker/integration/scripts/postgres/create_db_with_users.sh deleted file mode 100755 index 484290ec1..000000000 --- a/data/docker/integration/scripts/postgres/create_db_with_users.sh +++ /dev/null @@ -1,9 +0,0 @@ - -# -# Sample db and users creation. Replace here with your own details -# - -sudo -u postgres dropdb -e cgrates -sudo -u postgres dropuser -e cgrates -sudo -u postgres psql -c "CREATE USER cgrates password 'CGRateS.org';" -sudo -u postgres createdb -e -O cgrates cgrates diff --git a/data/docker/integration/scripts/postgres/create_ers_db.sh b/data/docker/integration/scripts/postgres/create_ers_db.sh deleted file mode 100755 index c697fa9d5..000000000 --- a/data/docker/integration/scripts/postgres/create_ers_db.sh +++ /dev/null @@ -1,4 +0,0 @@ - -# extra DB for ees and ers -sudo -u postgres dropdb -e cgrates2 -sudo -u postgres createdb -e -O cgrates cgrates2 diff --git a/data/docker/integration/scripts/postgres/create_tariffplan_tables.sql b/data/docker/integration/scripts/postgres/create_tariffplan_tables.sql deleted file mode 100644 index cbc175e47..000000000 --- a/data/docker/integration/scripts/postgres/create_tariffplan_tables.sql +++ /dev/null @@ -1,477 +0,0 @@ --- --- Table structure for table `tp_timings` --- -DROP TABLE IF EXISTS tp_timings; -CREATE TABLE tp_timings ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - years VARCHAR(255) NOT NULL, - months VARCHAR(255) NOT NULL, - month_days VARCHAR(255) NOT NULL, - week_days VARCHAR(255) NOT NULL, - time VARCHAR(32) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag) -); -CREATE INDEX tptimings_tpid_idx ON tp_timings (tpid); -CREATE INDEX tptimings_idx ON tp_timings (tpid,tag); - --- --- Table structure for table `tp_destinations` --- - -DROP TABLE IF EXISTS tp_destinations; -CREATE TABLE tp_destinations ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - prefix VARCHAR(24) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, prefix) -); -CREATE INDEX tpdests_tpid_idx ON tp_destinations (tpid); -CREATE INDEX tpdests_idx ON tp_destinations (tpid,tag); - --- --- Table structure for table `tp_rates` --- - -DROP TABLE IF EXISTS tp_rates; -CREATE TABLE tp_rates ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - connect_fee NUMERIC(7,4) NOT NULL, - rate NUMERIC(10,4) NOT NULL, - rate_unit VARCHAR(16) NOT NULL, - rate_increment VARCHAR(16) NOT NULL, - group_interval_start VARCHAR(16) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, group_interval_start) -); -CREATE INDEX tprates_tpid_idx ON tp_rates (tpid); -CREATE INDEX tprates_idx ON tp_rates (tpid,tag); - --- --- Table structure for table `destination_rates` --- - -DROP TABLE IF EXISTS tp_destination_rates; -CREATE TABLE tp_destination_rates ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - destinations_tag VARCHAR(64) NOT NULL, - rates_tag VARCHAR(64) NOT NULL, - rounding_method VARCHAR(255) NOT NULL, - rounding_decimals SMALLINT NOT NULL, - max_cost NUMERIC(7,4) NOT NULL, - max_cost_strategy VARCHAR(16) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag , destinations_tag) -); -CREATE INDEX tpdestrates_tpid_idx ON tp_destination_rates (tpid); -CREATE INDEX tpdestrates_idx ON tp_destination_rates (tpid,tag); - --- --- Table structure for table `tp_rating_plans` --- - -DROP TABLE IF EXISTS tp_rating_plans; -CREATE TABLE tp_rating_plans ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - destrates_tag VARCHAR(64) NOT NULL, - timing_tag VARCHAR(64) NOT NULL, - weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, destrates_tag, timing_tag) -); -CREATE INDEX tpratingplans_tpid_idx ON tp_rating_plans (tpid); -CREATE INDEX tpratingplans_idx ON tp_rating_plans (tpid,tag); - - --- --- Table structure for table `tp_rate_profiles` --- - -DROP TABLE IF EXISTS tp_rating_profiles; -CREATE TABLE tp_rating_profiles ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - loadid VARCHAR(64) NOT NULL, - tenant VARCHAR(64) NOT NULL, - category VARCHAR(32) NOT NULL, - subject VARCHAR(64) NOT NULL, - activation_time VARCHAR(26) NOT NULL, - rating_plan_tag VARCHAR(64) NOT NULL, - fallback_subjects VARCHAR(64), - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, loadid, tenant, category, subject, activation_time) -); -CREATE INDEX tpratingprofiles_tpid_idx ON tp_rating_profiles (tpid); -CREATE INDEX tpratingprofiles_idx ON tp_rating_profiles (tpid,loadid,tenant,category,subject); - --- --- Table structure for table `tp_shared_groups` --- - -DROP TABLE IF EXISTS tp_shared_groups; -CREATE TABLE tp_shared_groups ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - account VARCHAR(64) NOT NULL, - strategy VARCHAR(24) NOT NULL, - rating_subject VARCHAR(24) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, account , strategy , rating_subject) -); -CREATE INDEX tpsharedgroups_tpid_idx ON tp_shared_groups (tpid); -CREATE INDEX tpsharedgroups_idx ON tp_shared_groups (tpid,tag); - --- --- Table structure for table `tp_actions` --- - -DROP TABLE IF EXISTS tp_actions; -CREATE TABLE tp_actions ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - action VARCHAR(24) NOT NULL, - extra_parameters VARCHAR(256) NOT NULL, - filters VARCHAR(256) NOT NULL, - balance_tag VARCHAR(64) NOT NULL, - balance_type VARCHAR(24) NOT NULL, - categories VARCHAR(32) NOT NULL, - destination_tags VARCHAR(64) NOT NULL, - rating_subject VARCHAR(64) NOT NULL, - shared_groups VARCHAR(64) NOT NULL, - expiry_time VARCHAR(26) NOT NULL, - timing_tags VARCHAR(128) NOT NULL, - units VARCHAR(256) NOT NULL, - balance_weight VARCHAR(10) NOT NULL, - balance_blocker VARCHAR(5) NOT NULL, - balance_disabled VARCHAR(5) NOT NULL, - weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, action, balance_tag, balance_type, expiry_time, timing_tags, destination_tags, shared_groups, balance_weight, weight) -); -CREATE INDEX tpactions_tpid_idx ON tp_actions (tpid); -CREATE INDEX tpactions_idx ON tp_actions (tpid,tag); - --- --- Table structure for table `tp_action_timings` --- - -DROP TABLE IF EXISTS tp_action_plans; -CREATE TABLE tp_action_plans ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - actions_tag VARCHAR(64) NOT NULL, - timing_tag VARCHAR(64) NOT NULL, - weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, actions_tag, timing_tag) -); -CREATE INDEX tpactionplans_tpid_idx ON tp_action_plans (tpid); -CREATE INDEX tpactionplans_idx ON tp_action_plans (tpid,tag); - --- --- Table structure for table tp_action_triggers --- - -DROP TABLE IF EXISTS tp_action_triggers; -CREATE TABLE tp_action_triggers ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tag VARCHAR(64) NOT NULL, - unique_id VARCHAR(64) NOT NULL, - threshold_type VARCHAR(64) NOT NULL, - threshold_value NUMERIC(20,4) NOT NULL, - recurrent BOOLEAN NOT NULL, - min_sleep VARCHAR(16) NOT NULL, - expiry_time VARCHAR(26) NOT NULL, - activation_time VARCHAR(26) NOT NULL, - balance_tag VARCHAR(64) NOT NULL, - balance_type VARCHAR(24) NOT NULL, - balance_categories VARCHAR(32) NOT NULL, - balance_destination_tags VARCHAR(64) NOT NULL, - balance_rating_subject VARCHAR(64) NOT NULL, - balance_shared_groups VARCHAR(64) NOT NULL, - balance_expiry_time VARCHAR(26) NOT NULL, - balance_timing_tags VARCHAR(128) NOT NULL, - balance_weight VARCHAR(10) NOT NULL, - balance_blocker VARCHAR(5) NOT NULL, - balance_disabled VARCHAR(5) NOT NULL, - actions_tag VARCHAR(64) NOT NULL, - weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, tag, balance_tag, balance_type, threshold_type, threshold_value, balance_destination_tags, actions_tag) -); -CREATE INDEX tpactiontrigers_tpid_idx ON tp_action_triggers (tpid); -CREATE INDEX tpactiontrigers_idx ON tp_action_triggers (tpid,tag); - --- --- Table structure for table tp_account_actions --- - -DROP TABLE IF EXISTS tp_account_actions; -CREATE TABLE tp_account_actions ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - loadid VARCHAR(64) NOT NULL, - tenant VARCHAR(64) NOT NULL, - account VARCHAR(64) NOT NULL, - action_plan_tag VARCHAR(64), - action_triggers_tag VARCHAR(64), - allow_negative BOOLEAN NOT NULL, - disabled BOOLEAN NOT NULL, - created_at TIMESTAMP WITH TIME ZONE, - UNIQUE (tpid, loadid, tenant, account) -); -CREATE INDEX tpaccountactions_tpid_idx ON tp_account_actions (tpid); -CREATE INDEX tpaccountactions_idx ON tp_account_actions (tpid,loadid,tenant,account); - - --- --- Table structure for table `tp_resources` --- - -DROP TABLE IF EXISTS tp_resources; -CREATE TABLE tp_resources ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant"varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "usage_ttl" varchar(32) NOT NULL, - "limit" varchar(64) NOT NULL, - "allocation_message" varchar(64) NOT NULL, - "blocker" BOOLEAN NOT NULL, - "stored" BOOLEAN NOT NULL, - "weight" NUMERIC(8,2) NOT NULL, - "threshold_ids" varchar(64) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE -); -CREATE INDEX tp_resources_idx ON tp_resources (tpid); -CREATE INDEX tp_resources_unique ON tp_resources ("tpid", "tenant", "id", "filter_ids"); - - --- --- Table structure for table `tp_stats` --- - -DROP TABLE IF EXISTS tp_stats; -CREATE TABLE tp_stats ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant"varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "queue_length" INTEGER NOT NULL, - "ttl" varchar(32) NOT NULL, - "min_items" INTEGER NOT NULL, - "metric_ids" VARCHAR(128) NOT NULL, - "metric_filter_ids" VARCHAR(128) NOT NULL, - "stored" BOOLEAN NOT NULL, - "blocker" BOOLEAN NOT NULL, - "weight" decimal(8,2) NOT NULL, - "threshold_ids" varchar(64) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE -); -CREATE INDEX tp_stats_idx ON tp_stats (tpid); -CREATE INDEX tp_stats_unique ON tp_stats ("tpid","tenant", "id", "filter_ids","metric_ids"); - --- --- Table structure for table `tp_threshold_cfgs` --- - -DROP TABLE IF EXISTS tp_thresholds; -CREATE TABLE tp_thresholds ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant"varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "max_hits" INTEGER NOT NULL, - "min_hits" INTEGER NOT NULL, - "min_sleep" varchar(16) NOT NULL, - "blocker" BOOLEAN NOT NULL, - "weight" decimal(8,2) NOT NULL, - "action_ids" varchar(64) NOT NULL, - "async" BOOLEAN NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE -); -CREATE INDEX tp_thresholds_idx ON tp_thresholds (tpid); -CREATE INDEX tp_thresholds_unique ON tp_thresholds ("tpid","tenant", "id","filter_ids","action_ids"); - --- --- Table structure for table `tp_filter` --- - -DROP TABLE IF EXISTS tp_filters; -CREATE TABLE tp_filters ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant" varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "type" varchar(16) NOT NULL, - "element" varchar(64) NOT NULL, - "values" varchar(256) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE -); - CREATE INDEX tp_filters_idx ON tp_filters (tpid); - CREATE INDEX tp_filters_unique ON tp_filters ("tpid","tenant", "id", "type", "element"); - --- --- Table structure for table `tp_routes` --- - -DROP TABLE IF EXISTS tp_routes; -CREATE TABLE tp_routes ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant"varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "sorting" varchar(32) NOT NULL, - "sorting_parameters" varchar(64) NOT NULL, - "route_id" varchar(32) NOT NULL, - "route_filter_ids" varchar(64) NOT NULL, - "route_account_ids" varchar(64) NOT NULL, - "route_ratingplan_ids" varchar(64) NOT NULL, - "route_resource_ids" varchar(64) NOT NULL, - "route_stat_ids" varchar(64) NOT NULL, - "route_weight" decimal(8,2) NOT NULL, - "route_blocker" BOOLEAN NOT NULL, - "route_parameters" varchar(64) NOT NULL, - "weight" decimal(8,2) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE -); -CREATE INDEX tp_routes_idx ON tp_routes (tpid); -CREATE INDEX tp_routes_unique ON tp_routes ("tpid", "tenant", "id", - "filter_ids","route_id","route_filter_ids","route_account_ids", - "route_ratingplan_ids","route_resource_ids","route_stat_ids"); - - -- - -- Table structure for table `tp_attributes` - -- - - DROP TABLE IF EXISTS tp_attributes; - CREATE TABLE tp_attributes ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant"varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "contexts" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "attribute_filter_ids" varchar(64) NOT NULL, - "path" varchar(64) NOT NULL, - "type" varchar(64) NOT NULL, - "value" varchar(64) NOT NULL, - "blocker" BOOLEAN NOT NULL, - "weight" decimal(8,2) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE - ); - CREATE INDEX tp_attributes_ids ON tp_attributes (tpid); - CREATE INDEX tp_attributes_unique ON tp_attributes ("tpid", "tenant", "id", - "filter_ids","path","value"); - - -- - -- Table structure for table `tp_chargers` - -- - - DROP TABLE IF EXISTS tp_chargers; - CREATE TABLE tp_chargers ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant"varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "run_id" varchar(64) NOT NULL, - "attribute_ids" varchar(64) NOT NULL, - "weight" decimal(8,2) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE - ); - CREATE INDEX tp_chargers_ids ON tp_chargers (tpid); - CREATE INDEX tp_chargers_unique ON tp_chargers ("tpid", "tenant", "id", - "filter_ids","run_id","attribute_ids"); - - -- - -- Table structure for table `tp_dispatchers` - -- - - DROP TABLE IF EXISTS tp_dispatcher_profiles; - CREATE TABLE tp_dispatcher_profiles ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant" varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "subsystems" varchar(64) NOT NULL, - "filter_ids" varchar(64) NOT NULL, - "activation_interval" varchar(64) NOT NULL, - "strategy" varchar(64) NOT NULL, - "strategy_parameters" varchar(64) NOT NULL, - "conn_id" varchar(64) NOT NULL, - "conn_filter_ids" varchar(64) NOT NULL, - "conn_weight" decimal(8,2) NOT NULL, - "conn_blocker" BOOLEAN NOT NULL, - "conn_parameters" varchar(64) NOT NULL, - "weight" decimal(8,2) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE - ); - CREATE INDEX tp_dispatcher_profiles_ids ON tp_dispatcher_profiles (tpid); - CREATE INDEX tp_dispatcher_profiles_unique ON tp_dispatcher_profiles ("tpid", "tenant", "id", - "filter_ids","strategy","conn_id","conn_filter_ids"); - --- --- Table structure for table `tp_dispatchers` --- - - DROP TABLE IF EXISTS tp_dispatcher_hosts; - CREATE TABLE tp_dispatcher_hosts ( - "pk" SERIAL PRIMARY KEY, - "tpid" varchar(64) NOT NULL, - "tenant" varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, - "address" varchar(64) NOT NULL, - "transport" varchar(64) NOT NULL, - "connect_attempts" INTEGER NOT NULL, - "reconnects" INTEGER NOT NULL, - "connect_timeout" varchar(64) NOT NULL, - "reply_timeout" varchar(64) NOT NULL, - "tls" BOOLEAN NOT NULL, - "client_key" varchar(64) NOT NULL, - "client_certificate" varchar(64) NOT NULL, - "ca_certificate" varchar(64) NOT NULL, - "created_at" TIMESTAMP WITH TIME ZONE - ); - CREATE INDEX tp_dispatchers_hosts_ids ON tp_dispatcher_hosts (tpid); - CREATE INDEX tp_dispatcher_hosts_unique ON tp_dispatcher_hosts ("tpid", "tenant", "id", - "address"); - - - --- --- Table structure for table `versions` --- - -DROP TABLE IF EXISTS versions; -CREATE TABLE versions ( - "id" SERIAL PRIMARY KEY, - "item" varchar(64) NOT NULL, - "version" INTEGER NOT NULL, - UNIQUE ("id","item") -); diff --git a/data/docker/integration/scripts/postgres/pg_cdr_migration.sql b/data/docker/integration/scripts/postgres/pg_cdr_migration.sql deleted file mode 100644 index 5f40cb6d0..000000000 --- a/data/docker/integration/scripts/postgres/pg_cdr_migration.sql +++ /dev/null @@ -1,42 +0,0 @@ -/* -This script will migrate CDRs from the old CGRateS tables to the new cdrs table -but it only migrate CDRs where the duration is > 0. -If you need CDRs also with duration is = 0 you can make the appropriate change in the line beginning WHERE cdrs_primary.usage - -Also the script will process 10,000 CDRs before committing to save system resources -especially in systems where they are millions of CDRs to be migrated -You can increase or lower the value of step in the line after BEGIN below. -*/ - -DO $$ -DECLARE - max_cdrs bigint; - start_id bigint; - end_id bigint; - step bigint; -BEGIN - /* You must change the step var to commit every step rows inserted */ - step := 10000; - start_id := 0; - end_id := start_id + step; - select max(id) INTO max_cdrs from rated_cdrs; - WHILE start_id <= max_cdrs - LOOP - --RAISE NOTICE '%', (to_char(start_id, '99999999') || '-' || to_char(end_id, '99999999')); - INSERT INTO - cdrs(cgrid,run_id,origin_host,source,origin_id,tor,request_type,tenant,category,account,subject,destination,setup_time,pdd,answer_time,usage,supplier,disconnect_cause,extra_fields,cost_source,cost,cost_details,extra_info, created_at, updated_at, deleted_at) - SELECT cdrs_primary.cgrid,rated_cdrs.runid as run_id,cdrs_primary.cdrhost as origin_host,cdrs_primary.cdrsource as source,cdrs_primary.accid as origin_id, cdrs_primary.tor,rated_cdrs.reqtype as request_type, rated_cdrs.tenant,rated_cdrs.category, rated_cdrs.account, rated_cdrs.subject, rated_cdrs.destination,rated_cdrs.setup_time,rated_cdrs.pdd,rated_cdrs.answer_time,rated_cdrs.usage,rated_cdrs.supplier,rated_cdrs.disconnect_cause,cdrs_extra.extra_fields,cost_details.cost_source,rated_cdrs.cost,cost_details.timespans as cost_details,rated_cdrs.extra_info,rated_cdrs.created_at,rated_cdrs.updated_at, rated_cdrs.deleted_at - FROM rated_cdrs - INNER JOIN cdrs_primary ON rated_cdrs.cgrid = cdrs_primary.cgrid - INNER JOIN cdrs_extra ON rated_cdrs.cgrid = cdrs_extra.cgrid - INNER JOIN cost_details ON rated_cdrs.cgrid = cost_details.cgrid - WHERE cdrs_primary.usage > '0' - AND not exists (select 1 from cdrs c where c.cgrid = cdrs_primary.cgrid) - AND rated_cdrs.id >= start_id - AND rated_cdrs.id < end_id - ; - start_id = start_id + step; - end_id = end_id + step; - END LOOP; -END -$$; diff --git a/data/docker/integration/scripts/postgres/setup_cgr_db.sh b/data/docker/integration/scripts/postgres/setup_cgr_db.sh deleted file mode 100755 index 66d011763..000000000 --- a/data/docker/integration/scripts/postgres/setup_cgr_db.sh +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env sh - - -user=$1 -if [ -z "$1" ]; then - user="cgrates" -fi - -host=$2 -if [ -z "$2" ]; then - host="localhost" -fi - -DIR="$(dirname "$(readlink -f "$0")")" - -"$DIR"/create_db_with_users.sh - -export PGPASSWORD="CGRateS.org" - -psql -U $user -h $host -d cgrates -f "$DIR"/create_cdrs_tables.sql -cdrt=$? -psql -U $user -h $host -d cgrates -f "$DIR"/create_tariffplan_tables.sql -tpt=$? - -if [ $cdrt = 0 ] && [ $tpt = 0 ]; then - echo "\n\t+++ CGR-DB successfully set-up! +++\n" - exit 0 -fi - -