mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-07-11 14:17:44 +02:00
2018-06-07 Fred Gleason <fredg@paravelsystems.com>
* Implemented show database status in rddbmgr(8).
This commit is contained in:
parent
f8b0970b7b
commit
b791ca8a04
@ -10914,8 +10914,7 @@
|
||||
'rdairplay/list_log.h' to display hard times to 1/10 second.
|
||||
* Modified the ButtonLog widget in 'rdairplay/loglinebox.cpp' and
|
||||
'rdairplay/loglinebox.h' to display hard times to 1/10 second.
|
||||
* Modified the Edit Event dialog in 'rdairplay/edit_event.cpp' and
|
||||
'rdairplay/edit_event.h' to display hard times to 1/10 second.
|
||||
* Modified the Edit Event dialog in 'rdairplay/edit_event.cpp' and 'rdairplay/edit_event.h' to display hard times to 1/10 second.
|
||||
* Modified the Edit Clock dialog in 'rdlogmanager/edit_clock.cpp'
|
||||
to display Start and End times to 1/10 second.
|
||||
* Modified the Edit Event Assignment dialog in
|
||||
@ -17018,3 +17017,5 @@
|
||||
new host with no exemplar.
|
||||
2018-06-05 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Implemented the '--modify' command in rddbmgr(8).
|
||||
2018-06-07 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Implemented show database status in rddbmgr(8).
|
||||
|
@ -32,8 +32,10 @@ sbin_PROGRAMS = rddbmgr
|
||||
dist_rddbmgr_SOURCES = check.cpp\
|
||||
create.cpp\
|
||||
modify.cpp\
|
||||
printstatus.cpp\
|
||||
rddbmgr.cpp rddbmgr.h\
|
||||
revertschema.cpp\
|
||||
schemamap.cpp\
|
||||
updateschema.cpp
|
||||
|
||||
rddbmgr_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
||||
|
@ -18,37 +18,17 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <dbversion.h>
|
||||
#include <rddb.h>
|
||||
|
||||
#include "rddbmgr.h"
|
||||
|
||||
bool MainObject::Modify(QString *err_msg,int set_schema,
|
||||
const QString &set_version) const
|
||||
bool MainObject::Modify(QString *err_msg,int set_schema) const
|
||||
{
|
||||
*err_msg="ok";
|
||||
|
||||
//
|
||||
// Determine Target Schema
|
||||
//
|
||||
if(set_schema>0) {
|
||||
if((set_schema<242)||(set_schema>RD_VERSION_DATABASE)) {
|
||||
*err_msg="unsupported schema";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(set_version.isEmpty()) {
|
||||
set_schema=RD_VERSION_DATABASE;
|
||||
}
|
||||
else {
|
||||
if((set_schema=GetVersionSchema(set_version))==0) {
|
||||
*err_msg="invalid/unsupported Rivendell version";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Update/Revert
|
||||
//
|
||||
@ -76,7 +56,7 @@ int MainObject::GetCurrentSchema() const
|
||||
int ret=0;
|
||||
|
||||
QString sql=QString("select DB from VERSION");
|
||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||
QSqlQuery *q=new QSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
ret=q->value(0).toInt();
|
||||
}
|
||||
@ -86,50 +66,3 @@ int MainObject::GetCurrentSchema() const
|
||||
}
|
||||
|
||||
|
||||
int MainObject::GetVersionSchema(const QString &ver) const
|
||||
{
|
||||
QString version=ver;
|
||||
bool ok=false;
|
||||
|
||||
//
|
||||
// Version -> Schema Map
|
||||
//
|
||||
std::map<QString,int> version_map;
|
||||
version_map["2.10"]=242;
|
||||
version_map["2.11"]=245;
|
||||
version_map["2.12"]=254;
|
||||
version_map["2.13"]=255;
|
||||
version_map["2.14"]=258;
|
||||
version_map["2.15"]=259;
|
||||
version_map["2.16"]=263;
|
||||
version_map["2.17"]=268;
|
||||
version_map["2.18"]=272;
|
||||
version_map["2.19"]=275;
|
||||
version_map["2.20"]=286;
|
||||
|
||||
//
|
||||
// Normalize String
|
||||
//
|
||||
if(version.left(1).lower()=="v") {
|
||||
version=version.right(version.length()-1);
|
||||
}
|
||||
QStringList f0=f0.split(".",version);
|
||||
if(f0.size()!=3) {
|
||||
return 0;
|
||||
}
|
||||
for(int i=0;i<3;i++) {
|
||||
f0[i].toInt(&ok);
|
||||
if(!ok) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Lookup Schema
|
||||
//
|
||||
if(version_map.count(f0[0]+"."+f0[1])==0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return version_map[f0[0]+"."+f0[1]];
|
||||
}
|
||||
|
52
utils/rddbmgr/printstatus.cpp
Normal file
52
utils/rddbmgr/printstatus.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
// printstatus.cpp
|
||||
//
|
||||
// Print the status of a database.
|
||||
//
|
||||
// (C) Copyright 2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rddb.h>
|
||||
|
||||
#include "rddbmgr.h"
|
||||
|
||||
bool MainObject::PrintStatus(QString *err_msg) const
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
int schema;
|
||||
|
||||
sql=QString("show tables");
|
||||
q=new RDSqlQuery(sql,false);
|
||||
if(!q->first()) {
|
||||
delete q;
|
||||
printf("empty database\n");
|
||||
return true;
|
||||
}
|
||||
delete q;
|
||||
|
||||
if((schema=GetCurrentSchema())<=0) {
|
||||
printf("not a Rivendell database!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
printf("Rivendell database, schema %d [%s]\n",schema,
|
||||
(const char *)GetSchemaVersion(schema));
|
||||
|
||||
*err_msg="ok";
|
||||
return true;
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
#include <qsqldatabase.h>
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include <dbversion.h>
|
||||
#include <rdcmd_switch.h>
|
||||
|
||||
#include "rddbmgr.h"
|
||||
@ -66,6 +67,8 @@ MainObject::MainObject(QObject *parent)
|
||||
db_mysql_collation=db_config->mysqlCollation();
|
||||
station_name=db_config->stationName();
|
||||
|
||||
InitializeSchemaMap();
|
||||
|
||||
//
|
||||
// Process Command Switches
|
||||
//
|
||||
@ -177,15 +180,32 @@ MainObject::MainObject(QObject *parent)
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
delete cmd;
|
||||
|
||||
//
|
||||
// Sanity Checks
|
||||
//
|
||||
if(db_command==MainObject::NoCommand) {
|
||||
if((cmd->keys()>0)&&(db_command==MainObject::NoCommand)) {
|
||||
fprintf(stderr,"rddbmgr: exactly one command must be specified\n");
|
||||
exit(1);
|
||||
}
|
||||
if(set_schema>0) {
|
||||
if((set_schema<242)||(set_schema>RD_VERSION_DATABASE)) {
|
||||
fprintf(stderr,"rddbmgr: unsupported schema\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(set_version.isEmpty()) {
|
||||
set_schema=RD_VERSION_DATABASE;
|
||||
}
|
||||
else {
|
||||
if((set_schema=GetVersionSchema(set_version))==0) {
|
||||
fprintf(stderr,"invalid/unsupported Rivendell version\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete cmd;
|
||||
|
||||
if(db_verbose) {
|
||||
fprintf(stderr,"Using DB Credentials:\n");
|
||||
@ -231,14 +251,17 @@ MainObject::MainObject(QObject *parent)
|
||||
break;
|
||||
|
||||
case MainObject::CreateCommand:
|
||||
ok=Create(station_name,generate_audio,&err_msg);
|
||||
if((ok=Create(station_name,generate_audio,&err_msg))) {
|
||||
ok=Modify(&err_msg,set_schema);
|
||||
}
|
||||
break;
|
||||
|
||||
case MainObject::ModifyCommand:
|
||||
ok=Modify(&err_msg,set_schema,set_version);
|
||||
ok=Modify(&err_msg,set_schema);
|
||||
break;
|
||||
|
||||
case MainObject::NoCommand:
|
||||
ok=PrintStatus(&err_msg);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,8 @@ class MainObject : public QObject
|
||||
//
|
||||
// modify.cpp
|
||||
//
|
||||
bool Modify(QString *err_msg,int set_schema,const QString &set_version) const;
|
||||
bool Modify(QString *err_msg,int set_schema) const;
|
||||
int GetCurrentSchema() const;
|
||||
int GetVersionSchema(const QString &ver) const;
|
||||
|
||||
//
|
||||
// updateschema.cpp
|
||||
@ -77,6 +76,17 @@ class MainObject : public QObject
|
||||
//
|
||||
bool RevertSchema(int cur_schema,int set_schema,QString *err_msg) const;
|
||||
|
||||
//
|
||||
// schemamap.cpp
|
||||
//
|
||||
void InitializeSchemaMap();
|
||||
int GetVersionSchema(const QString &ver) const;
|
||||
QString GetSchemaVersion(int schema) const;
|
||||
|
||||
//
|
||||
// printstatus.cpp
|
||||
//
|
||||
bool PrintStatus(QString *err_msg) const;
|
||||
|
||||
Command db_command;
|
||||
QString db_mysql_hostname;
|
||||
|
112
utils/rddbmgr/schemamap.cpp
Normal file
112
utils/rddbmgr/schemamap.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
// schemamap.cpp
|
||||
//
|
||||
// DB schema version <==> Rivendell version map
|
||||
//
|
||||
// (C) Copyright 2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include "rddbmgr.h"
|
||||
|
||||
//
|
||||
// Version -> Schema Map
|
||||
//
|
||||
std::map<QString,int> global_version_map;
|
||||
|
||||
void MainObject::InitializeSchemaMap() {
|
||||
global_version_map["1.0"]=159;
|
||||
global_version_map["1.1"]=162;
|
||||
global_version_map["1.2"]=169;
|
||||
global_version_map["1.3"]=173;
|
||||
global_version_map["1.4"]=177;
|
||||
global_version_map["1.5"]=179;
|
||||
global_version_map["1.6"]=182;
|
||||
global_version_map["1.7"]=186;
|
||||
global_version_map["2.0"]=202;
|
||||
global_version_map["2.1"]=205;
|
||||
global_version_map["2.2"]=207;
|
||||
global_version_map["2.3"]=213;
|
||||
global_version_map["2.4"]=216;
|
||||
global_version_map["2.5"]=220;
|
||||
global_version_map["2.6"]=224;
|
||||
global_version_map["2.7"]=231;
|
||||
global_version_map["2.8"]=234;
|
||||
global_version_map["2.9"]=239;
|
||||
global_version_map["2.10"]=242;
|
||||
global_version_map["2.11"]=245;
|
||||
global_version_map["2.12"]=254;
|
||||
global_version_map["2.13"]=255;
|
||||
global_version_map["2.14"]=258;
|
||||
global_version_map["2.15"]=259;
|
||||
global_version_map["2.16"]=263;
|
||||
global_version_map["2.17"]=268;
|
||||
global_version_map["2.18"]=272;
|
||||
global_version_map["2.19"]=275;
|
||||
global_version_map["2.20"]=286;
|
||||
}
|
||||
|
||||
|
||||
int MainObject::GetVersionSchema(const QString &ver) const
|
||||
{
|
||||
QString version=ver;
|
||||
bool ok=false;
|
||||
|
||||
//
|
||||
// Normalize String
|
||||
//
|
||||
if(version.left(1).lower()=="v") {
|
||||
version=version.right(version.length()-1);
|
||||
}
|
||||
QStringList f0=f0.split(".",version);
|
||||
if(f0.size()!=3) {
|
||||
return 0;
|
||||
}
|
||||
for(int i=0;i<3;i++) {
|
||||
f0[i].toInt(&ok);
|
||||
if(!ok) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Lookup Schema
|
||||
//
|
||||
if(global_version_map.count(f0[0]+"."+f0[1])==0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return global_version_map[f0[0]+"."+f0[1]];
|
||||
}
|
||||
|
||||
|
||||
QString MainObject::GetSchemaVersion(int schema) const
|
||||
{
|
||||
QString prev_version="_preproduction";
|
||||
|
||||
for(std::map<QString,int>::const_iterator it=global_version_map.begin();
|
||||
it!=global_version_map.end();it++) {
|
||||
if(it->second==schema) {
|
||||
return "v"+it->first+".x";
|
||||
}
|
||||
if(it->second>schema) {
|
||||
return tr("between")+" v"+prev_version+".x "+tr("and")+
|
||||
" v"+it->first+".x";
|
||||
}
|
||||
prev_version=it->first;
|
||||
}
|
||||
return QString("after")+" v"+prev_version+".x";
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user