AR-Development / PersistentEmpires-OpenSourced

GNU Affero General Public License v3.0
4 stars 19 forks source link

DB Changes #63

Closed Heavybob closed 4 months ago

Heavybob commented 4 months ago

These changes alter the database to use proper primary keys for Players, Inventories, Factions, Castles, UpgradeableBuildings, StockpileMarkets and HorseMarkets. This is important to prevent adding duplicate entries properly.

These changes also include the addition of an UpdatedAt column to assist with debugging and general utility.

These changes have been tested on mysq8 but should work fine with mariadb too.

Heavybob commented 4 months ago

Inventories was not changed in this pull as it will require more changes.

Heavybob commented 4 months ago

ALTER TABLE Players DROP COLUMN Id;
ALTER TABLE Players ADD PRIMARY KEY (PlayerId);
ALTER TABLE Players ADD UpdatedAt DATETIME;
ALTER TABLE Players MODIFY COLUMN UpdatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

ALTER TABLE Inventories ADD UpdatedAt DATETIME;
ALTER TABLE Inventories MODIFY COLUMN UpdatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

ALTER TABLE Factions DROP COLUMN Id;
ALTER TABLE Factions ADD PRIMARY KEY (FactionIndex);

ALTER TABLE Castles DROP COLUMN Id;
ALTER TABLE Castles ADD PRIMARY KEY (CastleIndex);

ALTER TABLE UpgradeableBuildings DROP COLUMN Id;
ALTER TABLE UpgradeableBuildings ADD PRIMARY KEY (MissionObjectHash);
ALTER TABLE UpgradeableBuildings ADD UpdatedAt DATETIME;
ALTER TABLE UpgradeableBuildings MODIFY COLUMN UpdatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

ALTER TABLE StockpileMarkets DROP COLUMN Id;
ALTER TABLE StockpileMarkets ADD PRIMARY KEY (MissionObjectHash);
ALTER TABLE StockpileMarkets ADD UpdatedAt DATETIME;
ALTER TABLE StockpileMarkets MODIFY COLUMN UpdatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

ALTER TABLE HorseMarkets DROP COLUMN Id;
ALTER TABLE HorseMarkets ADD PRIMARY KEY (MissionObjectHash);
ALTER TABLE HorseMarkets ADD UpdatedAt DATETIME;
ALTER TABLE HorseMarkets MODIFY COLUMN UpdatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

ALTER TABLE Identifiers ADD UpdatedAt DATETIME;
ALTER TABLE Identifiers MODIFY COLUMN UpdatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;  ```