Commit 9ad73a98 authored by Robert Butora's avatar Robert Butora
Browse files

vlkb-obscore: removes all deprecated tables, leaves only obscore-table

parent fb2a84d4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ class config

      std::string getFitsDir() const       {return m_settings.at(fits_dir);}

      std::string getDbUri(bool with_password = false) const {return m_settings.at(pg_uri);}
      std::string getDbUri(/*bool with_password = false*/) const {return m_settings.at(pg_uri);}
      std::string getDbSchema() const   {return m_settings.at(pg_schema);}

      std::string getObsCorePublisher() const {return m_settings.at(obscore_publisher);}
+0 −123
Original line number Diff line number Diff line
@@ -12,73 +12,6 @@ SqlSchema::SqlSchema()

void SqlSchema::reset(void)
{
   headersRow
      = {
         {headersColId::filename,   "filename   VARCHAR(4096)   NOT NULL"},
         {headersColId::hdunum,     "hdunum     INTEGER         NOT NULL"},
         {headersColId::pubdid,     "pubdid     VARCHAR(4096)   UNIQUE"},
         {headersColId::header,     "header     TEXT            NOT NULL"},
         {headersColId::survey_id,  "survey_id  INTEGER"},
         {headersColId::header_id,  "header_id  INTEGER         PRIMARY KEY"}
      };


   boundsgalRow
      = {
         {bgheader_id,  "header_id  INTEGER       PRIMARY KEY"},
         {lfrom,   "lon_from  DECIMAL(21,16) NOT NULL" },
         {lto,     "lon_to    DECIMAL(21,16) NOT NULL" },
         {lunit,   "lon_unit  VARCHAR(16)" },

         {bfrom,   "lat_from  DECIMAL(21,16) NOT NULL" },
         {bto,     "lat_to    DECIMAL(21,16) NOT NULL" },
         {bunit,   "lat_unit  VARCHAR(16)" },

         {vfrom,   "vel_from  DECIMAL(21,8)" },// FIXME check why 8 not 16
         {vto,     "vel_to    DECIMAL(21,8)" },
         {vunit,   "vel_unit  VARCHAR(16)" },
      };

   boundsicrsRow
      = {
         {biheader_id,  "header_id  INTEGER       PRIMARY KEY"},
         {rfrom,   "ra_from  DECIMAL(21,16) NOT NULL" },
         {rto,     "ra_to    DECIMAL(21,16) NOT NULL" },
         {runit,   "ra_unit  VARCHAR(16)" },

         {dfrom,   "dec_from  DECIMAL(21,16) NOT NULL" },
         {dto,     "dec_to    DECIMAL(21,16) NOT NULL" },
         {dunit,   "dec_unit  VARCHAR(16)" },
      };

   verticesgalRow
      = {
         {vgheader_id,  "header_id  INTEGER        PRIMARY KEY"},
         {p1lon, "p1_lon DECIMAL(21,16) NOT NULL"},
         {p1lat, "p1_lat DECIMAL(21,16) NOT NULL"},
         {p2lon, "p2_lon DECIMAL(21,16) NOT NULL"},
         {p2lat, "p2_lat DECIMAL(21,16) NOT NULL"},
         {p3lon, "p3_lon DECIMAL(21,16) NOT NULL"},
         {p3lat, "p3_lat DECIMAL(21,16) NOT NULL"},
         {p4lon, "p4_lon DECIMAL(21,16) NOT NULL"},
         {p4lat, "p4_lat DECIMAL(21,16) NOT NULL"}
      };

   verticesicrsRow
      = {
         {viheader_id,  "header_id  INTEGER           PRIMARY KEY"},
         {p1ra,  "p1_ra  DECIMAL(21,16) NOT NULL"},
         {p1dec, "p1_dec DECIMAL(21,16) NOT NULL"},
         {p2ra,  "p2_ra  DECIMAL(21,16) NOT NULL"},
         {p2dec, "p2_dec DECIMAL(21,16) NOT NULL"},
         {p3ra,  "p3_ra  DECIMAL(21,16) NOT NULL"},
         {p3dec, "p3_dec DECIMAL(21,16) NOT NULL"},
         {p4ra,  "p4_ra  DECIMAL(21,16) NOT NULL"},
         {p4dec, "p4_dec DECIMAL(21,16) NOT NULL"}
      };



   obscoreRow
      = {
         {dataproduct_type, "dataproduct_type   VARCHAR"},
@@ -132,13 +65,6 @@ void SqlSchema::reset(void)

void SqlSchema::initCols(void)
{
//   using namespace columns;

   m_columns[headers]         = "(" + headersRow.concat_val_first_word() + ")";
   m_columns[boundsgal]       = "(" + boundsgalRow.concat_val_first_word() + ")";
   m_columns[boundsicrs]      = "(" + boundsicrsRow.concat_val_first_word() + ")";
   m_columns[verticesgal]     = "(" + verticesgalRow.concat_val_first_word() + ")";
   m_columns[verticesicrs]    = "(" + verticesicrsRow.concat_val_first_word() + ")";
   m_columns[obscore]         = "(" + obscoreRow.concat_val_first_word() + ")";
};

@@ -146,13 +72,6 @@ void SqlSchema::initCols(void)

void SqlSchema::appendRow(void)
{
//   using namespace columns;

   m_values[headers]     += "(" + headersRow.concat_val_all()  + "),";
   m_values[boundsgal]   += "(" + boundsgalRow.concat_val_all()   + "),";
   m_values[boundsicrs]  += "(" + boundsicrsRow.concat_val_all()   + "),";
   m_values[verticesgal] += "(" + verticesgalRow.concat_val_all() + "),";
   m_values[verticesicrs] += "(" + verticesicrsRow.concat_val_all() + "),";
   m_values[obscore]     += "(" + obscoreRow.concat_val_all()  + "),";
};

@@ -166,45 +85,3 @@ string SqlSchema::skl(string str)
   return str.substr(0, str.size() - 1);
}



#if 0
vector<string> SqlSchema::concatedValues(void)
{
   vector<string> vVals;
   std::map<Tables, std::string>::const_iterator it = m_values.begin();
   while(it != m_values.end())
   {
      Tables t = it->first;
      string cmd =  it->second;

      vVals.push_back(cmd);
      it++;
   }
   return vVals;
}


vector<string> SqlSchema::map2vect(const map<SqlSchema::Tables, string>& amap)
{
   vector<string> vVals;
   std::map<SqlSchema::Tables, std::string>::const_iterator it = amap.begin();
   while(it != amap.end())
   {
      SqlSchema::Tables t = it->first;
      string cmd =  it->second;

      vVals.push_back(cmd);
      it++;
   }
   return vVals;
}

vector<string> SqlSchema::concatedColumns(void)
{
   return map2vect(m_columns);
}
#endif

+6 −28
Original line number Diff line number Diff line
@@ -25,15 +25,9 @@ class SqlSchema
      void initCols(void);
      void appendRow(void);


      // groups of columns

      enum class headersColId {header_id, filename, hdunum, pubdid, header, survey_id};
      enum boundsgalColId {bgheader_id, lfrom, lto, lunit, bfrom, bto, bunit, vfrom, vto, vunit};
      enum boundsicrsColId {biheader_id, rfrom, rto, runit, dfrom, dto, dunit};
      enum verticesgalColId {vgheader_id, p1lon, p1lat, p2lon, p2lat, p3lon, p3lat, p4lon, p4lat};
      enum verticesicrsColId {viheader_id, p1ra, p1dec, p2ra, p2dec, p3ra, p3dec, p4ra, p4dec};
      enum obscoreColId {dataproduct_type, calib_level,
      enum /* class */ obscoreColId {dataproduct_type, calib_level,
         obs_collection, obs_title, obs_id, obs_publisher_id,
         bib_reference, data_rights,
         access_url, access_format, access_estsize, target_name,
@@ -47,40 +41,24 @@ class SqlSchema
         proposal_id,
         policy, groups};

      colmap<headersColId,      std::string> headersRow;
      colmap<boundsgalColId,    std::string> boundsgalRow;
      colmap<boundsicrsColId,   std::string> boundsicrsRow;
      colmap<verticesgalColId,  std::string> verticesgalRow;
      colmap<verticesicrsColId, std::string> verticesicrsRow;
      colmap<obscoreColId, std::string> obscoreRow;


      // organize columns into tables

      enum Tables {headers,
         boundsgal, boundsicrs, verticesgal, verticesicrs,
         obscore};
      enum Tables { obscore };

      std::map<Tables, std::string> m_columns;
      std::map<Tables, std::string> m_values;

      // utils

      std::string eto_string(enum headersColId cid) {return headersRow[cid].substr(0, headersRow[cid].find(' ')); };
      std::string eto_string(enum boundsgalColId cid) {return boundsgalRow[cid].substr(0, boundsgalRow[cid].find(' ')); };

      std::string eto_string(enum Tables tid) {return tableNames[tid].substr(0, tableNames[tid].find(' ')); };
      std::string eto_string(enum Tables tid)
						{return tableNames[tid].substr(0, tableNames[tid].find(' ')); };

      void reset(void);
      std::string skl(std::string str);
      // skip last character
      std::string skl(std::string str); // skip last character

      std::map<Tables, std::string> tableNames{
         {headers , "headers"},
         {boundsgal, "cubeboundsgalactic"},
         {boundsicrs, "cubeboundsicrs"},
         {verticesgal, "verticesgalactic"},
         {verticesicrs, "verticesicrs"},
         {obscore, "obscore"},
      };

+1 −8
Original line number Diff line number Diff line
@@ -9,8 +9,7 @@ SqlSchema_CREATE::SqlSchema_CREATE(void)
   appendRow();
}

// skip first '(' and last ',' character
// FIXME this is no good
// skip first '(' and last ',' character; FIXME this is no good
string skfl(string str)
{
   return str.substr(1, str.size() - 2);
@@ -20,12 +19,6 @@ string skfl(string str)
vector<string> SqlSchema_CREATE::getCREATE(void)
{
   vector<string> vCREATE{
    /*  {"DROP TABLE IF EXISTS headers CASCADE; CREATE TABLE headers (" + skfl(m_values[headers])},
         {"DROP TABLE IF EXISTS cubeboundsgalactic CASCADE; CREATE TABLE cubeboundsgalactic (" + skfl(m_values[boundsgal])},
         {"DROP TABLE IF EXISTS cubeboundsicrs CASCADE; CREATE TABLE cubeboundsicrs (" + skfl(m_values[boundsicrs])},
         {"DROP TABLE IF EXISTS verticesgalactic CASCADE; CREATE TABLE verticesgalactic (" + skfl(m_values[verticesgal])},
         {"DROP TABLE IF EXISTS verticesicrs CASCADE; CREATE TABLE verticesicrs (" + skfl(m_values[verticesicrs])},
    */
         {"DROP TABLE IF EXISTS obscore CASCADE; CREATE TABLE obscore " + skl(m_values[obscore])},
   };
   return vCREATE;
+2 −20
Original line number Diff line number Diff line
@@ -18,28 +18,10 @@ vector<string> SqlSchema_DELETE::getCommand(int sid, const Survey& surv)
   string obsTitleStr = surv.getObsTitle();

   vector<string> vDELETE{
/*      {"DELETE FROM cubeboundsgalactic WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
      {"DELETE FROM cubeboundsicrs     WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
      {"DELETE FROM verticesgalactic   WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
      {"DELETE FROM verticesicrs       WHERE header_id IN (SELECT header_id FROM headers WHERE survey_id = " + sidStr + ")"},
      {"DELETE FROM headers            WHERE survey_id = " + sidStr},
*/
      {"DELETE FROM obscore WHERE obs_collection = \'" + obsCollStr + "\' AND obs_title = \'" + obsTitleStr +  "\'"},
      {"DELETE FROM obscore WHERE obs_collection = \'" + obsCollStr
                             + "\' AND obs_title = \'" + obsTitleStr +  "\'"},
   };
   return vDELETE;
}

/* NOTE:
obscore handled separately
obscore_vlkb handled separately

static relative to for-cycle: sid & tabName[headers]

for(tableName : tableNames)
{
   cmdString = "DELETE FROM " + tableName + " WHERE header_id IN (SELECT header_id FROM " + tabName[headers] + " WHERE survey_id = " + to_string(sid) + ")"
   vCmd.push_back(cmdString);
}

*/
Loading