Update DB to version 22: Machine families, machine model separate from name.

This commit is contained in:
2018-04-29 02:02:33 +01:00
parent 349a941392
commit 736b98b754
21 changed files with 874 additions and 220 deletions

View File

@@ -49,123 +49,127 @@ namespace Cicm.Database
IDbCommand dbCmd = dbCon.CreateCommand();
Console.WriteLine("Creating table `admins`");
dbCmd.CommandText = V21.Admins;
dbCmd.CommandText = V22.Admins;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `browser_tests`");
dbCmd.CommandText = V21.BrowserTests;
dbCmd.CommandText = V22.BrowserTests;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `cicm_db`");
dbCmd.CommandText = V21.CicmDb;
dbCmd.CommandText = V22.CicmDb;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `companies`");
dbCmd.CommandText = V21.Companies;
dbCmd.CommandText = V22.Companies;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machine_families`");
dbCmd.CommandText = V22.MachineFamilies;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machines`");
dbCmd.CommandText = V21.Machines;
dbCmd.CommandText = V22.Machines;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`");
dbCmd.CommandText = V21.Forbidden;
dbCmd.CommandText = V22.Forbidden;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`");
dbCmd.CommandText = V21.Gpus;
dbCmd.CommandText = V22.Gpus;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`");
dbCmd.CommandText = V21.Logs;
dbCmd.CommandText = V22.Logs;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `money_donations`");
dbCmd.CommandText = V21.MoneyDonations;
dbCmd.CommandText = V22.MoneyDonations;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`");
dbCmd.CommandText = V21.News;
dbCmd.CommandText = V22.News;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`");
dbCmd.CommandText = V21.OwnedComputers;
dbCmd.CommandText = V22.OwnedComputers;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_consoles`");
dbCmd.CommandText = V21.OwnedConsoles;
dbCmd.CommandText = V22.OwnedConsoles;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_sets`");
dbCmd.CommandText = V21.InstructionSets;
dbCmd.CommandText = V22.InstructionSets;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions`");
dbCmd.CommandText = V21.InstructionSetExtensions;
dbCmd.CommandText = V22.InstructionSetExtensions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors`");
dbCmd.CommandText = V21.Processors;
dbCmd.CommandText = V22.Processors;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
dbCmd.CommandText = V21.InstructionSetExtensionsByProcessor;
dbCmd.CommandText = V22.InstructionSetExtensionsByProcessor;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_synths`");
dbCmd.CommandText = V21.SoundSynths;
dbCmd.CommandText = V22.SoundSynths;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `iso3166_1_numeric`");
dbCmd.CommandText = V21.Iso3166Numeric;
dbCmd.CommandText = V22.Iso3166Numeric;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Filling table `iso3166_1_numeric`");
dbCmd.CommandText = V21.Iso3166NumericValues;
dbCmd.CommandText = V22.Iso3166NumericValues;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `companies`");
dbCmd.CommandText = V21.CompaniesForeignKeys;
dbCmd.CommandText = V22.CompaniesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `machines`");
dbCmd.CommandText = V21.MachinesForeignKeys;
dbCmd.CommandText = V22.MachinesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_logos`");
dbCmd.CommandText = V21.CompanyLogos;
dbCmd.CommandText = V22.CompanyLogos;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_descriptions`");
dbCmd.CommandText = V21.CompanyDescriptions;
dbCmd.CommandText = V22.CompanyDescriptions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors_by_machine`");
dbCmd.CommandText = V21.ProcessorsByMachine;
dbCmd.CommandText = V22.ProcessorsByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus_by_machine`");
dbCmd.CommandText = V21.GpusByMachine;
dbCmd.CommandText = V22.GpusByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_by_machine`");
dbCmd.CommandText = V21.SoundByMachine;
dbCmd.CommandText = V22.SoundByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `memory_by_machine`");
dbCmd.CommandText = V21.MemoryByMachine;
dbCmd.CommandText = V22.MemoryByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions`");
dbCmd.CommandText = V21.Resolutions;
dbCmd.CommandText = V22.Resolutions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions_by_gpu`");
dbCmd.CommandText = V21.ResolutionsByGpu;
dbCmd.CommandText = V22.ResolutionsByGpu;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `storage_by_machine`");
dbCmd.CommandText = V21.StorageByMachine;
dbCmd.CommandText = V22.StorageByMachine;
dbCmd.ExecuteNonQuery();
return true;

View File

@@ -206,7 +206,7 @@ namespace Cicm.Database
public bool AddMachine(Machine entry, out long id)
{
#if DEBUG
Console.Write("Adding machine `{0}`...", entry.Model);
Console.Write("Adding machine `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMachine(entry);
@@ -214,7 +214,7 @@ namespace Cicm.Database
dbcmd.Transaction = trans;
const string SQL =
"INSERT INTO machines (company, introduced, model, type) VALUES (@company, @introduced, @model, @type)";
"INSERT INTO machines (company, introduced, name, type, model, family) VALUES (@company, @introduced, @name, @type, @model, @family)";
dbcmd.CommandText = SQL;
@@ -239,7 +239,7 @@ namespace Cicm.Database
public bool UpdateMachine(Machine entry)
{
#if DEBUG
Console.WriteLine("Updating machine `{0}`...", entry.Model);
Console.WriteLine("Updating machine `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMachine(entry);
@@ -247,7 +247,7 @@ namespace Cicm.Database
dbcmd.Transaction = trans;
string sql =
"UPDATE machines SET company = @company, introduced = @introduced, model = @model, type = @type " +
"UPDATE machines SET company = @company, introduced = @introduced, name = @name, type = @type, model = @model, family = @family " +
$"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
@@ -293,26 +293,36 @@ namespace Cicm.Database
IDbDataParameter param2 = dbcmd.CreateParameter();
IDbDataParameter param3 = dbcmd.CreateParameter();
IDbDataParameter param4 = dbcmd.CreateParameter();
IDbDataParameter param5 = dbcmd.CreateParameter();
IDbDataParameter param6 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@introduced";
param3.ParameterName = "@model";
param3.ParameterName = "@name";
param4.ParameterName = "@type";
param5.ParameterName = "@model";
param6.ParameterName = "@family";
param1.DbType = DbType.Int32;
param2.DbType = DbType.DateTime;
param3.DbType = DbType.String;
param4.DbType = DbType.Int32;
param5.DbType = DbType.String;
param6.DbType = DbType.Int32;
param1.Value = entry.Company;
param2.Value = entry.Introduced;
param3.Value = entry.Model;
param3.Value = entry.Name;
param4.Value = entry.Type;
param5.Value = entry.Model;
param6.Value = entry.Family == 0 ? (object)null : entry.Family;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
dbcmd.Parameters.Add(param3);
dbcmd.Parameters.Add(param4);
dbcmd.Parameters.Add(param5);
dbcmd.Parameters.Add(param6);
return dbcmd;
}
@@ -329,8 +339,10 @@ namespace Cicm.Database
Company = (int)dataRow["company"],
Introduced =
dataRow["introduced"] == DBNull.Value ? DateTime.MinValue : (DateTime)dataRow["introduced"],
Model = (string)dataRow["model"],
Type = (MachineType)dataRow["type"]
Name = (string)dataRow["name"],
Type = (MachineType)dataRow["type"],
Model = dataRow["model"] == DBNull.Value ? null : (string)dataRow["model"],
Family = dataRow["family"] == DBNull.Value ? 0 : (int)dataRow["family"]
};
entries.Add(entry);

View File

@@ -0,0 +1,326 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : MachineFamily.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage machine_families.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// 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, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
namespace Cicm.Database
{
public partial class Operations
{
/// <summary>
/// Gets all machine_families
/// </summary>
/// <param name="entries">All machine_families</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachineFamilies(out List<MachineFamily> entries)
{
#if DEBUG
Console.WriteLine("Getting all machine_families...");
#endif
try
{
const string SQL = "SELECT * from machine_families";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets all machine_families from specified company
/// </summary>
/// <param name="entries">All machine_families</param>
/// <param name="company">Company id</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachineFamilies(out List<MachineFamily> entries, int company)
{
#if DEBUG
Console.WriteLine("Getting all machine_families from company id {0}...", company);
#endif
try
{
string sql = $"SELECT * from machine_families WHERE company = '{company}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets the specified number of machine_families since the specified start
/// </summary>
/// <param name="entries">List of machine_families</param>
/// <param name="start">Start of query</param>
/// <param name="count">How many entries to retrieve</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMachineFamilies(out List<MachineFamily> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} machine_families from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM machine_families LIMIT {start}, {count}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets machine_families by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>MachineFamily with specified id, <c>null</c> if not found or error</returns>
public MachineFamily GetMachineFamily(int id)
{
#if DEBUG
Console.WriteLine("Getting machine_families with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from machine_families WHERE id = '{id}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
List<MachineFamily> entries = MachineFamiliesFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting machine_families.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Counts the number of machine_families in the database
/// </summary>
/// <returns>Entries in database</returns>
public long CountMachineFamilies()
{
#if DEBUG
Console.WriteLine("Counting machine_families...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM machine_families";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
catch { return 0; }
}
/// <summary>
/// Adds a new administrator to the database
/// </summary>
/// <param name="entry">Entry to add</param>
/// <param name="id">ID of added entry</param>
/// <returns><c>true</c> if added correctly, <c>false</c> otherwise</returns>
public bool AddMachineFamily(MachineFamily entry, out long id)
{
#if DEBUG
Console.Write("Adding machine_families `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMachineFamily(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL = "INSERT INTO machine_families (company, name) VALUES (@company, @name)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
Console.WriteLine(" id {0}", id);
#endif
return true;
}
/// <summary>
/// Updated a machine_families in the database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateMachineFamily(MachineFamily entry)
{
#if DEBUG
Console.WriteLine("Updating machine_families `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMachineFamily(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = "UPDATE machine_families SET company = @company, name = @name " + $"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
/// <summary>
/// Removes a machine_families from the database
/// </summary>
/// <param name="id">ID of entry to remove</param>
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
public bool RemoveMachineFamily(long id)
{
#if DEBUG
Console.WriteLine("Removing machine_families widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM machine_families WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandMachineFamily(MachineFamily entry)
{
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataParameter param1 = dbcmd.CreateParameter();
IDbDataParameter param2 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@name";
param1.DbType = DbType.Int32;
param2.DbType = DbType.String;
param1.Value = entry.Company;
param2.Value = entry.Name;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
return dbcmd;
}
static List<MachineFamily> MachineFamiliesFromDataTable(DataTable dataTable)
{
List<MachineFamily> entries = new List<MachineFamily>();
foreach(DataRow dataRow in dataTable.Rows)
{
MachineFamily entry = new MachineFamily
{
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Name = (string)dataRow["name"]
};
entries.Add(entry);
}
return entries;
}
}
}

View File

@@ -35,7 +35,7 @@ namespace Cicm.Database
public partial class Operations
{
/// <summary>Last known database version</summary>
const int DB_VERSION = 21;
const int DB_VERSION = 22;
/// <summary>The column with this value indicates there is no item of this type.</summary>
public const int DB_NONE = -1;
/// <summary>

View File

@@ -174,6 +174,11 @@ namespace Cicm.Database
UpdateDatabaseToV21();
break;
}
case 21:
{
UpdateDatabaseToV22();
break;
}
}
OptimizeDatabase();
@@ -2486,6 +2491,59 @@ namespace Cicm.Database
dbCmd.Dispose();
}
void UpdateDatabaseToV22()
{
Console.WriteLine("Updating database to version 22");
Console.WriteLine("Creating new table table `machine_families`");
IDbCommand dbCmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = V22.MachineFamilies;
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new columns to table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `machines` ADD COLUMN `family` INT DEFAULT NULL;\n" +
"ALTER TABLE `machines` CHANGE COLUMN `model` `name` VARCHAR(255) NOT NULL;\n" +
"ALTER TABLE `machines` DROP INDEX `idx_machines_model`;\n" +
"ALTER TABLE `machines` ADD COLUMN `model` VARCHAR(50) DEFAULT NULL;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new indexes to table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "CREATE INDEX `idx_machines_family` ON `machines` (`family`);\n" +
"CREATE INDEX `idx_machines_name` ON `machines` (`name`);\n" +
"CREATE INDEX `idx_machines_model` ON `machines` (`model`);";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new foreign keys to table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_family` (family) REFERENCES machine_families (`id`) ON UPDATE CASCADE";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Setting new database version to 22...");
dbCmd = dbCon.CreateCommand();
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('22')";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
void OptimizeDatabase()
{
IDbCommand dbCmd = dbCon.CreateCommand();

View File

@@ -37,12 +37,16 @@ namespace Cicm.Database.Schemas
{
/// <summary>Manufacturer's company ID</summary>
public int Company;
/// <summary>Machine family</summary>
public int Family;
/// <summary>ID</summary>
public int Id;
/// <summary>Introduction date, null if unknown, 1000 if prototype</summary>
public DateTime Introduced;
/// <summary>Model name</summary>
/// <summary>Machine model/SKU</summary>
public string Model;
/// <summary>Model name</summary>
public string Name;
/// <summary>Machine type</summary>
public MachineType Type;
}

View File

@@ -0,0 +1,43 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Computer.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// High level representation of a computer.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// 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, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace Cicm.Database.Schemas
{
/// <summary>Computer</summary>
public class MachineFamily
{
/// <summary>Manufacturer's company ID</summary>
public int Company;
/// <summary>ID</summary>
public int Id;
/// <summary>Model name</summary>
public string Name;
}
}

View File

@@ -41,7 +41,7 @@ namespace Cicm.Database.Schemas.Sql
"`version` int(11) NOT NULL,\n" +
"`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
"PRIMARY KEY (`id`));\n" +
"INSERT INTO cicm_db (version) VALUES ('20');";
"INSERT INTO cicm_db (version) VALUES ('21');";
public static readonly string Companies = V20.Companies;

View File

@@ -0,0 +1,125 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : V22.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains SQL queries to create the database version 7.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// 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, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace Cicm.Database.Schemas.Sql
{
public static class V22
{
public static readonly string Admins = V21.Admins;
public static readonly string BrowserTests = V21.BrowserTests;
public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" +
"`id` int(11) NOT NULL AUTO_INCREMENT,\n" +
"`version` int(11) NOT NULL,\n" +
"`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
"PRIMARY KEY (`id`));\n" +
"INSERT INTO cicm_db (version) VALUES ('22');";
public static readonly string Companies = V21.Companies;
public static readonly string Machines = "CREATE TABLE `machines` (\n" +
"`id` int(11) NOT NULL AUTO_INCREMENT,\n" +
"`company` int(11) NOT NULL DEFAULT '0',\n" +
"`name` varchar(255) NOT NULL,\n" +
"`type` int(11) NOT NULL DEFAULT '0',\n" +
"`introduced` datetime DEFAULT NULL,\n" +
"`family` int(11) DEFAULT NULL,\n" +
"`model` varchar(50) DEFAULT NULL,\n" +
"PRIMARY KEY (`id`),\n" +
"KEY `idx_machines_company` (`company`),\n" +
"KEY `idx_machines_type` (`type`),\n" +
"KEY `idx_machines_introduced` (`introduced`),\n" +
"KEY `idx_machines_family` (`family`),\n" +
"KEY `idx_machines_name` (`name`),\n" +
"KEY `idx_machines_model` (`model`));";
public static readonly string Forbidden = V21.Forbidden;
public static readonly string Gpus = V21.Gpus;
public static readonly string Logs = V21.Logs;
public static readonly string MoneyDonations = V21.MoneyDonations;
public static readonly string News = V21.News;
public static readonly string OwnedComputers = V21.OwnedComputers;
public static readonly string OwnedConsoles = V21.OwnedConsoles;
public static readonly string Processors = V21.Processors;
public static readonly string SoundSynths = V21.SoundSynths;
public static readonly string MachinesForeignKeys =
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;\n" +
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_family` (family) REFERENCES `machine_families` (`id`) ON UPDATE CASCADE;";
public static readonly string Iso3166Numeric = V21.Iso3166Numeric;
public static readonly string Iso3166NumericValues = V21.Iso3166NumericValues;
public static readonly string CompaniesForeignKeys = V21.CompaniesForeignKeys;
public static readonly string CompanyLogos = V21.CompanyLogos;
public static readonly string CompanyDescriptions = V21.CompanyDescriptions;
public static readonly string InstructionSets = V21.InstructionSets;
public static readonly string InstructionSetExtensions = V21.InstructionSetExtensions;
public static readonly string InstructionSetExtensionsByProcessor = V21.InstructionSetExtensionsByProcessor;
public static readonly string ProcessorsByMachine = V21.ProcessorsByMachine;
public static readonly string GpusByMachine = V21.GpusByMachine;
public static readonly string SoundByMachine = V21.SoundByMachine;
public static readonly string MemoryByMachine = V21.MemoryByMachine;
public static readonly string Resolutions = V21.Resolutions;
public static readonly string ResolutionsByGpu = V21.ResolutionsByGpu;
public static readonly string StorageByMachine = V21.StorageByMachine;
public static readonly string MachineFamilies = "CREATE TABLE `machine_families` (\n" +
"`id` INT NOT NULL AUTO_INCREMENT,\n" +
"`company` INT NOT NULL,\n" +
"`name` VARCHAR(255) NOT NULL,\n" +
"PRIMARY KEY (`id`),\n" +
"KEY `idx_machine_families_company` (`company`),\n" +
"KEY `idx_machine_families_name` (`name`),\n" +
"CONSTRAINT `fk_machine_families_company` FOREIGN KEY (`company`) REFERENCES `companies` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);";
}
}