check in working migration code fore SQLite. This

is now using migrations instead of the old model to
create tables.  Tested for existing old tables, 
and for creating new ones.
This commit is contained in:
Sean Dague
2008-06-11 21:01:33 +00:00
parent 68b98aecab
commit 6c1fce6147
5 changed files with 260 additions and 198 deletions

View File

@@ -61,7 +61,12 @@ namespace OpenSim.Data.SQLite
conn.Open();
TestTables(conn);
Assembly assem = GetType().Assembly;
Migration m = new Migration(conn, assem, "InventoryStore");
// TODO: remove this line after changeset 6000
TestTables(conn, m);
m.Update();
SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
invItemsDa = new SqliteDataAdapter(itemsSelectCmd);
@@ -672,7 +677,7 @@ namespace OpenSim.Data.SQLite
scmd.ExecuteNonQuery();
}
private static bool TestTables(SqliteConnection conn)
private static bool TestTables(SqliteConnection conn, Migration m)
{
SqliteCommand invItemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
SqliteDataAdapter pDa = new SqliteDataAdapter(invItemsSelectCmd);
@@ -688,63 +693,68 @@ namespace OpenSim.Data.SQLite
catch (SqliteSyntaxException)
{
m_log.Info("[INVENTORY DB]: SQLite Database doesn't exist... creating");
InitDB(conn);
return false;
}
pDa.Fill(tmpDS, "inventoryitems");
sDa.Fill(tmpDS, "inventoryfolders");
if (m.Version == 0)
m.Version = 1;
// Very clumsy way of checking whether we need to upgrade the database table version and then updating. Only
// putting up with this because this code should be blown away soon by nhibernate...
conn.Open();
SqliteCommand cmd;
try
{
cmd = new SqliteCommand("select salePrice from inventoryitems limit 1;", conn);
cmd.ExecuteNonQuery();
}
catch (SqliteSyntaxException)
{
m_log.Info("[INVENTORY DB]: Upgrading sqlite inventory database to version 2");
cmd = new SqliteCommand("alter table inventoryitems add column salePrice integer default 99;", conn);
cmd.ExecuteNonQuery();
cmd = new SqliteCommand("alter table inventoryitems add column saleType integer default 0;", conn);
cmd.ExecuteNonQuery();
cmd = new SqliteCommand("alter table inventoryitems add column creationDate integer default 2000;", conn);
cmd.ExecuteNonQuery();
cmd = new SqliteCommand("alter table inventoryitems add column groupID varchar(255) default '00000000-0000-0000-0000-000000000000';", conn);
cmd.ExecuteNonQuery();
cmd = new SqliteCommand("alter table inventoryitems add column groupOwned integer default 0;", conn);
cmd.ExecuteNonQuery();
cmd = new SqliteCommand("alter table inventoryitems add column flags integer default 0;", conn);
cmd.ExecuteNonQuery();
pDa.Fill(tmpDS, "inventoryitems");
}
finally
{
conn.Close();
}
foreach (DataColumn col in createInventoryItemsTable().Columns)
{
if (! tmpDS.Tables["inventoryitems"].Columns.Contains(col.ColumnName))
{
m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
return false;
}
}
foreach (DataColumn col in createInventoryFoldersTable().Columns)
{
if (! tmpDS.Tables["inventoryfolders"].Columns.Contains(col.ColumnName))
{
m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
return false;
}
}
return true;
// pDa.Fill(tmpDS, "inventoryitems");
// sDa.Fill(tmpDS, "inventoryfolders");
// // Very clumsy way of checking whether we need to upgrade the database table version and then updating. Only
// // putting up with this because this code should be blown away soon by nhibernate...
// conn.Open();
// SqliteCommand cmd;
// try
// {
// cmd = new SqliteCommand("select salePrice from inventoryitems limit 1;", conn);
// cmd.ExecuteNonQuery();
// }
// catch (SqliteSyntaxException)
// {
// m_log.Info("[INVENTORY DB]: Upgrading sqlite inventory database to version 2");
// cmd = new SqliteCommand("alter table inventoryitems add column salePrice integer default 99;", conn);
// cmd.ExecuteNonQuery();
// cmd = new SqliteCommand("alter table inventoryitems add column saleType integer default 0;", conn);
// cmd.ExecuteNonQuery();
// cmd = new SqliteCommand("alter table inventoryitems add column creationDate integer default 2000;", conn);
// cmd.ExecuteNonQuery();
// cmd = new SqliteCommand("alter table inventoryitems add column groupID varchar(255) default '00000000-0000-0000-0000-000000000000';", conn);
// cmd.ExecuteNonQuery();
// cmd = new SqliteCommand("alter table inventoryitems add column groupOwned integer default 0;", conn);
// cmd.ExecuteNonQuery();
// cmd = new SqliteCommand("alter table inventoryitems add column flags integer default 0;", conn);
// cmd.ExecuteNonQuery();
// pDa.Fill(tmpDS, "inventoryitems");
// }
// finally
// {
// conn.Close();
// }
// foreach (DataColumn col in createInventoryItemsTable().Columns)
// {
// if (! tmpDS.Tables["inventoryitems"].Columns.Contains(col.ColumnName))
// {
// m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
// return false;
// }
// }
// foreach (DataColumn col in createInventoryFoldersTable().Columns)
// {
// if (! tmpDS.Tables["inventoryfolders"].Columns.Contains(col.ColumnName))
// {
// m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
// return false;
// }
// }
// return true;
}
}
}