More fixes for fresh_install. Don't create initial Groups in SQL

migrations, instead create them after DB is initialized
This commit is contained in:
Tim Donohue
2014-10-29 18:33:56 +00:00
parent 82016403d7
commit 9f4c030fed
5 changed files with 52 additions and 72 deletions

View File

@@ -1491,11 +1491,21 @@ public class Group extends DSpaceObject
* @throws AuthorizeException * @throws AuthorizeException
*/ */
public static void initDefaultGroupNames(Context context) throws SQLException, AuthorizeException { public static void initDefaultGroupNames(Context context) throws SQLException, AuthorizeException {
Group anonymousGroup = Group.find(context, 0); // Check for Anonymous group. If not found, create it
Group anonymousGroup = Group.find(context, ANONYMOUS_ID);
if(anonymousGroup==null)
{
anonymousGroup = Group.create(context);
}
anonymousGroup.setName("Anonymous"); anonymousGroup.setName("Anonymous");
anonymousGroup.update(); anonymousGroup.update();
Group adminGroup = Group.find(context, 1); // Check for Administrator group. If not found, create it
Group adminGroup = Group.find(context, ADMIN_ID);
if(adminGroup==null)
{
adminGroup = Group.create(context);
}
adminGroup.setName("Administrator"); adminGroup.setName("Administrator");
adminGroup.update(); adminGroup.update();
} }

View File

@@ -25,24 +25,24 @@ import org.slf4j.LoggerFactory;
* any Database migration occurs. * any Database migration occurs.
* <P> * <P>
* The reason this runs BEFORE a migration is to ensure that any new * The reason this runs BEFORE a migration is to ensure that any new
* metadata fields are FIRST added to our registries, so that the * metadata fields are FIRST added to our registries, so that the
* migrations can make use of those new metadata fields, etc. * migrations can make use of those new metadata fields, etc.
* <P> * <P>
* However, there is one exception. If this is a "fresh install" of DSpace, * However, there is one exception. If this is a "fresh install" of DSpace,
* we'll need to wait until the necessary database tables are created. In * we'll need to wait until the necessary database tables are created. In
* that scenario we will load registries AFTER the initial migration. * that scenario we will load registries AFTER the initial migration.
* *
* @author Tim Donohue * @author Tim Donohue
*/ */
public class DatabaseRegistryUpdater implements FlywayCallback public class DatabaseRegistryUpdater implements FlywayCallback
{ {
/** logging category */ /** logging category */
private static final Logger log = LoggerFactory.getLogger(DatabaseRegistryUpdater.class); private static final Logger log = LoggerFactory.getLogger(DatabaseRegistryUpdater.class);
// Whether or not this is a fresh install of DSpace // Whether or not this is a fresh install of DSpace
// This determines whether to update registries PRE or POST migration // This determines whether to update registries PRE or POST migration
private boolean freshInstall = false; private boolean freshInstall = false;
/** /**
* Method to actually update our registries from latest configs * Method to actually update our registries from latest configs
*/ */
@@ -53,11 +53,11 @@ public class DatabaseRegistryUpdater implements FlywayCallback
{ {
context = new Context(); context = new Context();
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
String base = ConfigurationManager.getProperty("dspace.dir") String base = ConfigurationManager.getProperty("dspace.dir")
+ File.separator + "config" + File.separator + File.separator + "config" + File.separator
+ "registries" + File.separator; + "registries" + File.separator;
// Load updates to Bitstream format registry (if any) // Load updates to Bitstream format registry (if any)
log.info("Updating Bitstream Format Registry based on " + base + "bitstream-formats.xml"); log.info("Updating Bitstream Format Registry based on " + base + "bitstream-formats.xml");
RegistryLoader.loadBitstreamFormats(context, base + "bitstream-formats.xml"); RegistryLoader.loadBitstreamFormats(context, base + "bitstream-formats.xml");
@@ -96,91 +96,87 @@ public class DatabaseRegistryUpdater implements FlywayCallback
context.abort(); context.abort();
} }
} }
@Override @Override
public void afterClean(Connection connection) public void afterClean(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void afterEachMigrate(Connection connection, MigrationInfo info) public void afterEachMigrate(Connection connection, MigrationInfo info)
{ {
// If this is a fresh install, we must update registries AFTER the // do nothing
// initial migration runs (since the registry tables won't exist until
// the initial migration are performed)
if(freshInstall)
{
// As soon as the MetadataSchemaRegistry table exists, we can update the registries
if(DatabaseUtils.tableExists(connection, "MetadataSchemaRegistry"))
{
updateRegistries();
freshInstall = false;
}
}
} }
@Override @Override
public void afterInfo(Connection connection) public void afterInfo(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void afterInit(Connection connection) public void afterInit(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void afterMigrate(Connection connection) public void afterMigrate(Connection connection)
{ {
// do nothing // If this is a fresh install, we must update registries AFTER the
// initial migrations (since the registry tables won't exist until the
// initial migrations are performed)
if(freshInstall)
{
updateRegistries();
freshInstall = false;
}
} }
@Override @Override
public void afterRepair(Connection connection) public void afterRepair(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void afterValidate(Connection connection) public void afterValidate(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void beforeClean(Connection connection) public void beforeClean(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void beforeEachMigrate(Connection connection, MigrationInfo info) public void beforeEachMigrate(Connection connection, MigrationInfo info)
{ {
// do nothing // do nothing
} }
@Override @Override
public void beforeInfo(Connection connection) public void beforeInfo(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void beforeInit(Connection connection) public void beforeInit(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void beforeMigrate(Connection connection) public void beforeMigrate(Connection connection)
{ {
// Check if our MetadataSchemaRegistry table exists yet. // Check if our MetadataSchemaRegistry table exists yet.
// If it does NOT, then this is a fresh install & we'll need to // If it does NOT, then this is a fresh install & we'll need to
// updateRegistries() AFTER migration // updateRegistries() AFTER migration
if(DatabaseUtils.tableExists(connection, "MetadataSchemaRegistry")) if(DatabaseUtils.tableExists(connection, "MetadataSchemaRegistry"))
{ {
// Ensure registries are updated BEFORE a database migration (upgrade) // Ensure registries are updated BEFORE a database migration (upgrade)
@@ -195,17 +191,16 @@ public class DatabaseRegistryUpdater implements FlywayCallback
freshInstall = true; freshInstall = true;
} }
} }
@Override @Override
public void beforeRepair(Connection connection) public void beforeRepair(Connection connection)
{ {
// do nothing // do nothing
} }
@Override @Override
public void beforeValidate(Connection connection) public void beforeValidate(Connection connection)
{ {
// do nothing // do nothing
} }
} }

View File

@@ -16,7 +16,8 @@ CREATE SEQUENCE bitstreamformatregistry_seq;
CREATE SEQUENCE fileextension_seq; CREATE SEQUENCE fileextension_seq;
CREATE SEQUENCE bitstream_seq; CREATE SEQUENCE bitstream_seq;
CREATE SEQUENCE eperson_seq; CREATE SEQUENCE eperson_seq;
CREATE SEQUENCE epersongroup_seq START WITH 2; -- we reserve 0 and 1 -- start group sequence at 0, since Anonymous group = 0
CREATE SEQUENCE epersongroup_seq MINVALUE 0 START WITH 0;
CREATE SEQUENCE item_seq; CREATE SEQUENCE item_seq;
CREATE SEQUENCE bundle_seq; CREATE SEQUENCE bundle_seq;
CREATE SEQUENCE item2bundle_seq; CREATE SEQUENCE item2bundle_seq;
@@ -551,12 +552,3 @@ SELECT Communities2Item.community_id, ItemsByDateAccessioned.*
FROM ItemsByDateAccessioned, Communities2Item FROM ItemsByDateAccessioned, Communities2Item
WHERE ItemsByDateAccessioned.item_id = Communities2Item.item_id WHERE ItemsByDateAccessioned.item_id = Communities2Item.item_id
; ;
-------------------------------------------------------
-- Create 'special' groups, for anonymous access
-- and administrators
-------------------------------------------------------
-- We don't use getnextid() for 'anonymous' since the sequences start at '1'
INSERT INTO epersongroup VALUES(0, 'Anonymous');
INSERT INTO epersongroup VALUES(1, 'Administrator');

View File

@@ -16,8 +16,8 @@ CREATE SEQUENCE bitstreamformatregistry_seq;
CREATE SEQUENCE fileextension_seq; CREATE SEQUENCE fileextension_seq;
CREATE SEQUENCE bitstream_seq; CREATE SEQUENCE bitstream_seq;
CREATE SEQUENCE eperson_seq; CREATE SEQUENCE eperson_seq;
CREATE SEQUENCE epersongroup_seq START WITH 2; -- start group sequence at 0, since Anonymous group = 0
-- we reserve 0 and 1 CREATE SEQUENCE epersongroup_seq MINVALUE 0 START WITH 0;
CREATE SEQUENCE item_seq; CREATE SEQUENCE item_seq;
CREATE SEQUENCE bundle_seq; CREATE SEQUENCE bundle_seq;
CREATE SEQUENCE item2bundle_seq; CREATE SEQUENCE item2bundle_seq;
@@ -546,12 +546,3 @@ SELECT Communities2Item.community_id, ItemsByDateAccessioned.*
FROM ItemsByDateAccessioned, Communities2Item FROM ItemsByDateAccessioned, Communities2Item
WHERE ItemsByDateAccessioned.item_id = Communities2Item.item_id WHERE ItemsByDateAccessioned.item_id = Communities2Item.item_id
; ;
-------------------------------------------------------
-- Create 'special' groups, for anonymous access
-- and administrators
-------------------------------------------------------
-- We don't use getnextid() for 'anonymous' since the sequences start at '1'
INSERT INTO epersongroup VALUES(0, 'Anonymous');
INSERT INTO epersongroup VALUES(1, 'Administrator');

View File

@@ -54,7 +54,8 @@ CREATE SEQUENCE bitstreamformatregistry_seq;
CREATE SEQUENCE fileextension_seq; CREATE SEQUENCE fileextension_seq;
CREATE SEQUENCE bitstream_seq; CREATE SEQUENCE bitstream_seq;
CREATE SEQUENCE eperson_seq; CREATE SEQUENCE eperson_seq;
CREATE SEQUENCE epersongroup_seq; -- start group sequence at 0, since Anonymous group = 0
CREATE SEQUENCE epersongroup_seq MINVALUE 0 START WITH 0;
CREATE SEQUENCE item_seq; CREATE SEQUENCE item_seq;
CREATE SEQUENCE bundle_seq; CREATE SEQUENCE bundle_seq;
CREATE SEQUENCE item2bundle_seq; CREATE SEQUENCE item2bundle_seq;
@@ -563,12 +564,3 @@ SELECT Community2Item.community_id, ItemsByDateAccessioned.*
FROM ItemsByDateAccessioned, Community2Item FROM ItemsByDateAccessioned, Community2Item
WHERE ItemsByDateAccessioned.item_id = Community2Item.item_id WHERE ItemsByDateAccessioned.item_id = Community2Item.item_id
; ;
-------------------------------------------------------
-- Create 'special' groups, for anonymous access
-- and administrators
-------------------------------------------------------
-- We don't use getnextid() for 'anonymous' since the sequences start at '1'
INSERT INTO epersongroup VALUES(0, 'Anonymous');
INSERT INTO epersongroup VALUES(getnextid('epersongroup'), 'Administrator');