From 6c1fce61473b8d3faf9ee4602b9d0a392f148b7c Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 11 Jun 2008 21:01:33 +0000 Subject: 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. --- OpenSim/Data/SQLite/SQLiteUserData.cs | 52 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'OpenSim/Data/SQLite/SQLiteUserData.cs') diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs index c9ef3c2..36ec9ea 100644 --- a/OpenSim/Data/SQLite/SQLiteUserData.cs +++ b/OpenSim/Data/SQLite/SQLiteUserData.cs @@ -72,12 +72,20 @@ namespace OpenSim.Data.SQLite connect = "URI=file:userprofiles.db,version=3"; SqliteConnection conn = new SqliteConnection(connect); - TestTables(conn); // This sucks, but It doesn't seem to work with the dataset Syncing :P g_conn = conn; g_conn.Open(); + Assembly assem = GetType().Assembly; + Migration m = new Migration(g_conn, assem, "UserStore"); + + // TODO: remove this after rev 6000 + TestTables(conn, m); + + m.Update(); + + ds = new DataSet(); da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn)); daf = new SqliteDataAdapter(new SqliteCommand(userFriendsSelect, conn)); @@ -824,7 +832,7 @@ namespace OpenSim.Data.SQLite conn.Close(); } - private static bool TestTables(SqliteConnection conn) + private static bool TestTables(SqliteConnection conn, Migration m) { SqliteCommand cmd = new SqliteCommand(userSelect, conn); SqliteCommand fcmd = new SqliteCommand(userFriendsSelect, conn); @@ -842,26 +850,32 @@ namespace OpenSim.Data.SQLite catch (SqliteSyntaxException) { m_log.Info("[USER DB]: SQLite Database doesn't exist... creating"); - InitDB(conn); - } - conn.Open(); - try - { - cmd = new SqliteCommand("select webLoginKey from users limit 1;", conn); - cmd.ExecuteNonQuery(); - } - catch (SqliteSyntaxException) - { - cmd = new SqliteCommand("alter table users add column webLoginKey text default '00000000-0000-0000-0000-000000000000';", conn); - cmd.ExecuteNonQuery(); - pDa.Fill(tmpDS, "users"); - } - finally - { - conn.Close(); + return false; } + if (m.Version == 0) + m.Version = 1; + return true; + + // conn.Open(); + // try + // { + // cmd = new SqliteCommand("select webLoginKey from users limit 1;", conn); + // cmd.ExecuteNonQuery(); + // } + // catch (SqliteSyntaxException) + // { + // cmd = new SqliteCommand("alter table users add column webLoginKey text default '00000000-0000-0000-0000-000000000000';", conn); + // cmd.ExecuteNonQuery(); + // pDa.Fill(tmpDS, "users"); + // } + // finally + // { + // conn.Close(); + // } + + // return true; } } } -- cgit v1.1