mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-31 08:02:43 +02:00
2018-06-05 Fred Gleason <fredg@paravelsystems.com>
* Implemented the '--modify' command in rddbmgr(8).
This commit is contained in:
parent
7133d0f388
commit
f8b0970b7b
@ -17016,3 +17016,5 @@
|
||||
* Fixed a bug in 'RDStation::create()' that generated corrupt records
|
||||
in the 'AUDIO_INPUT' and 'AUDIO_OUTPUTS' tables when creating a
|
||||
new host with no exemplar.
|
||||
2018-06-05 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Implemented the '--modify' command in rddbmgr(8).
|
||||
|
15
lib/rddb.cpp
15
lib/rddb.cpp
@ -140,6 +140,21 @@ QVariant RDSqlQuery::run(const QString &sql,bool *ok)
|
||||
}
|
||||
|
||||
|
||||
bool RDSqlQuery::apply(const QString &sql,QString *err_msg)
|
||||
{
|
||||
bool ret=false;
|
||||
|
||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||
ret=q->isActive();
|
||||
if(!ret) {
|
||||
*err_msg="sql error: "+q->lastError().text()+" query: "+sql;
|
||||
}
|
||||
delete q;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int RDSqlQuery::rows(const QString &sql)
|
||||
{
|
||||
int ret=0;
|
||||
|
@ -50,6 +50,7 @@ class RDSqlQuery : public QSqlQuery
|
||||
public:
|
||||
RDSqlQuery(const QString &query=QString::null,bool reconnect=true);
|
||||
static QVariant run(const QString &sql,bool *ok=NULL);
|
||||
static bool apply(const QString &sql,QString *err_msg);
|
||||
static int rows(const QString &sql);
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,9 @@ sbin_PROGRAMS = rddbmgr
|
||||
dist_rddbmgr_SOURCES = check.cpp\
|
||||
create.cpp\
|
||||
modify.cpp\
|
||||
rddbmgr.cpp rddbmgr.h
|
||||
rddbmgr.cpp rddbmgr.h\
|
||||
revertschema.cpp\
|
||||
updateschema.cpp
|
||||
|
||||
rddbmgr_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,11 +18,118 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <dbversion.h>
|
||||
#include <rddb.h>
|
||||
|
||||
#include "rddbmgr.h"
|
||||
|
||||
bool MainObject::Modify(QString *err_msg,int set_schema,
|
||||
const QString &set_version) 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
|
||||
//
|
||||
int current_schema=GetCurrentSchema();
|
||||
if(current_schema==0) {
|
||||
*err_msg="unable to determine DB schema, aborting";
|
||||
return false;
|
||||
}
|
||||
if(current_schema>RD_VERSION_DATABASE) {
|
||||
*err_msg="unable to modify, unknown current schema";
|
||||
return false;
|
||||
}
|
||||
if(set_schema>current_schema) {
|
||||
return UpdateSchema(current_schema,set_schema,err_msg);
|
||||
}
|
||||
if(set_schema<current_schema) {
|
||||
return RevertSchema(current_schema,set_schema,err_msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int MainObject::GetCurrentSchema() const
|
||||
{
|
||||
int ret=0;
|
||||
|
||||
QString sql=QString("select DB from VERSION");
|
||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
ret=q->value(0).toInt();
|
||||
}
|
||||
delete q;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
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]];
|
||||
}
|
||||
|
@ -34,16 +34,50 @@ class MainObject : public QObject
|
||||
MainObject(QObject *parent=0);
|
||||
|
||||
private:
|
||||
//
|
||||
// check.cpp
|
||||
//
|
||||
bool Check(QString *err_msg) const;
|
||||
|
||||
//
|
||||
// create.cpp
|
||||
//
|
||||
bool Create(const QString &station_name,bool gen_audio,
|
||||
QString *err_msg) const;
|
||||
bool CreateNewDb(QString *err_msg) const;
|
||||
bool InititalizeNewDb(const QString &station_name,bool gen_audio,
|
||||
QString *err_msg) const;
|
||||
bool RunQuery(QString sql) const;
|
||||
void InsertImportFormats() const;
|
||||
bool InsertRDAirplayHotkeys(const QString &station_name) const;
|
||||
bool InsertImportFormats(QString *err_msg) const;
|
||||
bool InsertRDAirplayHotkeys(const QString &station_name,
|
||||
QString *err_msg) const;
|
||||
bool CreateReconciliationTable(const QString &svc_name,
|
||||
QString *err_msg) const;
|
||||
|
||||
//
|
||||
// modify.cpp
|
||||
//
|
||||
bool Modify(QString *err_msg,int set_schema,const QString &set_version) const;
|
||||
int GetCurrentSchema() const;
|
||||
int GetVersionSchema(const QString &ver) const;
|
||||
|
||||
//
|
||||
// updateschema.cpp
|
||||
//
|
||||
bool UpdateSchema(int cur_schema,int set_schema,QString *err_msg) const;
|
||||
void AverageCuts89(unsigned cartnum) const;
|
||||
void TotalMacros89(unsigned cartnum) const;
|
||||
void CreateAuxFieldsTable143(const QString &key_name) const;
|
||||
void CreateFeedLog151(const QString &key_name) const;
|
||||
bool UpdateLogTable186(const QString &table,QString *err_msg) const;
|
||||
bool ConvertTimeField186(const QString &table,const QString &field,
|
||||
QString *err_msg) const;
|
||||
|
||||
//
|
||||
// revertschema.cpp
|
||||
//
|
||||
bool RevertSchema(int cur_schema,int set_schema,QString *err_msg) const;
|
||||
|
||||
|
||||
Command db_command;
|
||||
QString db_mysql_hostname;
|
||||
QString db_mysql_loginname;
|
||||
|
1161
utils/rddbmgr/revertschema.cpp
Normal file
1161
utils/rddbmgr/revertschema.cpp
Normal file
File diff suppressed because it is too large
Load Diff
7409
utils/rddbmgr/updateschema.cpp
Normal file
7409
utils/rddbmgr/updateschema.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user