Make RateProfiles storable in MySQL and Postgres

This commit is contained in:
arberkatellari
2025-11-14 11:39:07 +02:00
committed by Dan Christian Bogos
parent a559563810
commit da41db3f56
13 changed files with 502 additions and 40 deletions

View File

@@ -10,11 +10,11 @@
"db_conns": {
"*default": {
"db_type": "*internal",
"opts":{
"internalDBDumpInterval": "500ms",
"internalDBRewriteInterval": "500ms",
"internalDBFileSizeLimit": "4k"
}
"opts":{
"internalDBDumpInterval": "500ms",
"internalDBRewriteInterval": "500ms",
"internalDBFileSizeLimit": "4k"
}
}
},
"items":{

View File

@@ -27,7 +27,8 @@
}
},
"items": {
"*cdrs": {"limit": -1, "ttl": "", "static_ttl": false, "remote":false, "replicate":false, "dbConn": "StorDB"}
"*cdrs": {"limit": -1, "ttl": "", "static_ttl": false, "remote":false, "replicate":false, "dbConn": "StorDB"},
"*rate_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "remote":false, "replicate":false, "dbConn": "StorDB"}
}
},

View File

@@ -0,0 +1,46 @@
{
"general": {
"node_id": "id",
},
"logger": {
"level": 7
},
"db": {
"db_conns": {
"*default": {
"db_type": "redis",
"db_host": "127.0.0.1",
"db_port": 6379,
"db_name": "10",
"db_user": "cgrates"
},
"StorDB": {
"db_type": "postgres",
"db_host": "127.0.0.1",
"db_port": 5432,
"db_name": "cgrates",
"db_user": "cgrates",
"db_password": "CGRateS.org"
}
},
"items": {
"*cdrs": {"limit": -1, "ttl": "", "static_ttl": false, "remote":false, "replicate":false, "dbConn": "StorDB"},
"*rate_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "remote":false, "replicate":false, "dbConn": "StorDB"}
}
},
"rates": {
"enabled": true,
"prefix_indexed_fields": ["*req.Destination"],
"exists_indexed_fields": ["*req.Destination"],
"rate_prefix_indexed_fields": ["*req.Destination"]
},
"admins": {
"enabled": true
}
}

View File

@@ -0,0 +1,45 @@
{
"general": {
"node_id": "id",
},
"logger": {
"level": 7
},
"db": {
"db_conns": {
"*default": {
"db_type": "redis",
"db_host": "127.0.0.1",
"db_port": 6379,
"db_name": "10",
"db_user": "cgrates"
},
"StorDB": {
"db_type": "mysql",
"db_host": "127.0.0.1",
"db_port": 3306,
"db_name": "cgrates",
"db_user": "cgrates",
"db_password": "CGRateS.org"
}
},
"items": {
"*cdrs": {"limit": -1, "ttl": "", "static_ttl": false, "remote":false, "replicate":false, "dbConn": "StorDB"}
}
},
"rates": {
"enabled": true,
"prefix_indexed_fields": ["*req.Destination"],
"exists_indexed_fields": ["*req.Destination"],
"rate_prefix_indexed_fields": ["*req.Destination"]
},
"admins": {
"enabled": true
}
}

View File

@@ -154,4 +154,26 @@ CREATE TABLE route_profiles (
PRIMARY KEY (`pk`),
UNIQUE KEY unique_tenant_id (`tenant`, `id`)
);
CREATE UNIQUE INDEX route_profiles_idx ON route_profiles (`id`);
CREATE UNIQUE INDEX route_profiles_idx ON route_profiles (`id`);
DROP TABLE IF EXISTS rates;
DROP TABLE IF EXISTS rate_profiles;
CREATE TABLE rate_profiles (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tenant` VARCHAR(40) NOT NULL,
`id` VARCHAR(64) NOT NULL,
`rate_profile` JSON NOT NULL,
PRIMARY KEY (`pk`),
UNIQUE KEY unique_tenant_id (`tenant`, `id`)
);
CREATE UNIQUE INDEX rate_profiles_idx ON rate_profiles (`id`);
CREATE TABLE rates (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`tenant` VARCHAR(40) NOT NULL,
`id` VARCHAR(64) NOT NULL,
`rate` JSON NOT NULL,
`rate_profile_id` VARCHAR(64) NOT NULL,
PRIMARY KEY (`pk`),
UNIQUE KEY unique_tenant_id_rate_profile_id (`tenant`, `id`, `rate_profile_id`),
FOREIGN KEY (rate_profile_id) REFERENCES rate_profiles (id)
);

View File

@@ -152,3 +152,24 @@ CREATE TABLE route_profiles (
UNIQUE (tenant, id)
);
CREATE UNIQUE INDEX route_profiles_idx ON route_profiles ("id");
DROP TABLE IF EXISTS rates;
DROP TABLE IF EXISTS rate_profiles;
CREATE TABLE rate_profiles (
pk SERIAL PRIMARY KEY,
tenant VARCHAR(40) NOT NULL,
id VARCHAR(64) NOT NULL,
rate_profile JSONB NOT NULL,
UNIQUE (tenant, id)
);
CREATE UNIQUE INDEX rate_profiles_idx ON rate_profiles ("id");
CREATE TABLE rates (
pk SERIAL PRIMARY KEY,
tenant VARCHAR(40) NOT NULL,
id VARCHAR(64) NOT NULL,
rate JSONB NOT NULL,
rate_profile_id VARCHAR(64) NOT NULL,
UNIQUE (tenant, id, rate_profile_id),
FOREIGN KEY (rate_profile_id) REFERENCES rate_profiles (id)
);