Skip to content

Commit

Permalink
Fix issue #383
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorinwasher committed Sep 4, 2024
1 parent 69f3d55 commit ff4a432
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Set;

/**
* A data migrator to migrate from 1.0.0.14 to 1.0.0.16
* A data migrator to migrate from 1.0.0.14 to 1.0.0.17
*/
public class DataMigration9 extends DataMigration {
private final Properties configConversions = loadConfigConversions("/migration/config-migrations-9.properties");
Expand All @@ -44,6 +44,12 @@ public void run(@NotNull SQLDatabaseAPI database, StargateAPI stargateAPI) {
} catch (SQLException | IOException e) {
Stargate.log(e);
}

try {
new SQLDatabaseMigrator(database, tableNameConfiguration, "/migration/database/v-9", isInterServer).run();
} catch (SQLException | IOException e) {
Stargate.log(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS {InterPortalFlagRelation}
name,
network
)
ON UPDATE CASCADE,
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (flag) REFERENCES {Flag} (id)
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS {InterPortalPosition}
name,
network
)
ON UPDATE CASCADE,
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (positionType) REFERENCES {PositionType} (id)
);
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS {PortalFlagRelation}
name,
network
)
ON UPDATE CASCADE,
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (flag) REFERENCES {Flag} (id)
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS {PortalPosition}
name,
network
)
ON UPDATE CASCADE,
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (positionType) REFERENCES {PositionType} (id)
);
46 changes: 46 additions & 0 deletions src/main/resources/migration/database/v-9/inter_server/step0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Add a update on cascade constraint to the InterPortalPosition table
* This is the only way of doing it in sqlite (by recreating the table)
*/


CREATE TABLE IF NOT EXISTS {InterPortalPosition}1
(
portalName NVARCHAR (180) NOT NULL,
networkName NVARCHAR (180) NOT NULL,
xCoordinate INTEGER NOT NULL,
yCoordinate INTEGER NOT NULL,
zCoordinate INTEGER NOT NULL,
positionType INTEGER NOT NULL,
metaData TEXT,
pluginName VARCHAR(255) DEFAULT "Stargate",
PRIMARY KEY
(
portalName,
networkName,
xCoordinate,
yCoordinate,
zCoordinate
),
FOREIGN KEY
(
portalName,
networkName
)
REFERENCES {InterPortal}
(
name,
network
)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (positionType) REFERENCES {PositionType} (id)
);

INSERT INTO {InterPortalPosition}1 SELECT *
FROM
{InterPortalPosition};

DROP TABLE {InterPortalPosition};

ALTER TABLE {InterPortalPosition}1 RENAME TO {InterPortalPosition};
42 changes: 42 additions & 0 deletions src/main/resources/migration/database/v-9/inter_server/step1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Add a update on cascade constraint to the InterPortalFlagRelation table
* This is the only way of doing it in sqlite (by recreating the table)
*/

CREATE TABLE IF NOT EXISTS {InterPortalFlagRelation}1
(
name NVARCHAR (180) NOT NULL,
network NVARCHAR (180) NOT NULL,
flag INTEGER NOT NULL,
PRIMARY KEY
(
name,
network,
flag
),
FOREIGN KEY
(
name,
network
)
REFERENCES {InterPortal}
(
name,
network
)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (flag) REFERENCES {Flag} (id)
);

INSERT INTO {InterPortalFlagRelation}1 SELECT *
FROM
{InterPortalFlagRelation};

DROP VIEW {InterPortalView};

DROP TABLE {InterPortalFlagRelation};

ALTER TABLE {InterPortalFlagRelation}1 RENAME TO {InterPortalFlagRelation};

CREATE_VIEW_INTER_PORTAL;
45 changes: 45 additions & 0 deletions src/main/resources/migration/database/v-9/local/step0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Add a update on cascade constraint to the PortalPosition table
* This is the only way of doing it in sqlite (by recreating the table)
*/

CREATE TABLE IF NOT EXISTS {PortalPosition}1
(
portalName NVARCHAR (180) NOT NULL,
networkName NVARCHAR (180) NOT NULL,
xCoordinate INTEGER NOT NULL,
yCoordinate INTEGER NOT NULL,
zCoordinate INTEGER NOT NULL,
positionType INTEGER NOT NULL,
metaData TEXT,
pluginName VARCHAR(255) DEFAULT "Stargate",
PRIMARY KEY
(
portalName,
networkName,
xCoordinate,
yCoordinate,
zCoordinate
),
FOREIGN KEY
(
portalName,
networkName
)
REFERENCES {Portal}
(
name,
network
)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (positionType) REFERENCES {PositionType} (id)
);

INSERT INTO {PortalPosition}1 SELECT *
FROM
{PortalPosition};

DROP TABLE {PortalPosition};

ALTER TABLE {PortalPosition}1 RENAME TO {PortalPosition};
42 changes: 42 additions & 0 deletions src/main/resources/migration/database/v-9/local/step1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Add a update on cascade constraint to the InterPortalFlagRelation table
* This is the only way of doing it in sqlite (by recreating the table)
*/

CREATE TABLE IF NOT EXISTS {PortalFlagRelation}1
(
name NVARCHAR (180) NOT NULL,
network NVARCHAR (180) NOT NULL,
flag INTEGER NOT NULL,
PRIMARY KEY
(
name,
network,
flag
),
FOREIGN KEY
(
name,
network
)
REFERENCES {Portal}
(
name,
network
)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (flag) REFERENCES {Flag} (id)
);

INSERT INTO {PortalFlagRelation}1 SELECT *
FROM
{PortalFlagRelation};

DROP VIEW {PortalView};

DROP TABLE {PortalFlagRelation};

ALTER TABLE {PortalFlagRelation}1 RENAME TO {PortalFlagRelation};

CREATE_VIEW_PORTAL;
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

class SQLDatabaseMigratorTest {

private SQLDatabaseMigrator databaseMigrator;
private SQLDatabaseMigrator databaseMigrator7;
private SQLiteDatabase database;
private TableNameConfiguration nameConfiguration;
private static final File sqlDatabaseFile = new File("src/test/resources", "alpha-1_0_0_11.db");
private static final File oldSqlDatabaseFile = new File("src/test/resources", "alpha-1_0_0_11.old");
private SQLDatabaseMigrator databaseMigrator9;

@BeforeEach
void setUp() throws SQLException, IOException {
Expand All @@ -31,7 +32,8 @@ void setUp() throws SQLException, IOException {

database = new SQLiteDatabase(sqlDatabaseFile);
nameConfiguration = new TableNameConfiguration("", "");
databaseMigrator = new SQLDatabaseMigrator(database, nameConfiguration, "/migration/database/v-7", true);
databaseMigrator7 = new SQLDatabaseMigrator(database, nameConfiguration, "/migration/database/v-7", true);
databaseMigrator9 = new SQLDatabaseMigrator(database, nameConfiguration, "/migration/database/v-9", true);
}

@AfterEach
Expand All @@ -43,7 +45,8 @@ void tearDown() {
// CHECK IF THE UPDATE ON CASCADE OPTION IS THERE, BY LOOKING AT THE BEHAVIOR
@Test
void renamePortalPosition() throws SQLException, IOException {
databaseMigrator.run();
databaseMigrator7.run();
databaseMigrator9.run();
renamePortal(nameConfiguration.getPortalTableName());
try (Connection connection = database.getConnection()) {
SQLTestHelper.checkIfHasNot(nameConfiguration.getPortalPositionTableName(), "portal", "network",
Expand All @@ -54,7 +57,8 @@ void renamePortalPosition() throws SQLException, IOException {

@Test
void renameInterPortalPosition() throws SQLException, IOException {
databaseMigrator.run();
databaseMigrator7.run();
databaseMigrator9.run();
renamePortal(nameConfiguration.getInterPortalTableName());
try (Connection connection = database.getConnection()) {
SQLTestHelper.checkIfHasNot(nameConfiguration.getInterPortalPositionTableName(), "portal", "network",
Expand All @@ -66,7 +70,8 @@ void renameInterPortalPosition() throws SQLException, IOException {

@Test
void renamePortalFlag() throws SQLException, IOException {
databaseMigrator.run();
databaseMigrator7.run();
databaseMigrator9.run();
renamePortal(nameConfiguration.getPortalTableName());
try (Connection connection = database.getConnection()) {
SQLTestHelper.checkIfHasNot(nameConfiguration.getFlagRelationTableName(), "portal", "network", connection);
Expand All @@ -76,7 +81,8 @@ void renamePortalFlag() throws SQLException, IOException {

@Test
void renameInterPortalFlag() throws SQLException, IOException {
databaseMigrator.run();
databaseMigrator7.run();
databaseMigrator9.run();
renamePortal(nameConfiguration.getInterPortalTableName());
try (Connection connection = database.getConnection()) {
SQLTestHelper.checkIfHasNot(nameConfiguration.getInterFlagRelationTableName(), "portal", "network",
Expand All @@ -88,7 +94,8 @@ void renameInterPortalFlag() throws SQLException, IOException {

@Test
void portalPosition_checkPluginName() throws SQLException, IOException {
databaseMigrator.run();
databaseMigrator7.run();
databaseMigrator9.run();
try (Connection connection = database.getConnection()) {
SQLTestHelper.checkIfColumnIs(nameConfiguration.getPortalPositionTableName(), "pluginName", "portal", "network", "Stargate", connection);
}
Expand Down

0 comments on commit ff4a432

Please sign in to comment.