From 69fb4ee208daac549b6f271fd6140d745406984d Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 9 Jun 2008 22:01:21 +0000 Subject: migrations seem to not break anything at this point. Tomorrow I'll start trying to integrate them into sqlite to see if this works right for table migration. --- OpenSim/Data/Migration.cs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/Migration.cs b/OpenSim/Data/Migration.cs index 8487db8..b5f1a60 100644 --- a/OpenSim/Data/Migration.cs +++ b/OpenSim/Data/Migration.cs @@ -82,6 +82,8 @@ namespace OpenSim.Data _type = type; _conn = conn; _assem = assem; + + Initialize(); } private void Initialize() @@ -103,6 +105,7 @@ namespace OpenSim.Data public void Update() { int version = 0; + int newversion = 0; version = FindVersion(_type); List migrations = GetMigrationsAfter(version); @@ -112,7 +115,10 @@ namespace OpenSim.Data cmd.CommandText = m; cmd.ExecuteNonQuery(); } - UpdateVersion(_type, MaxVersion()); + + newversion = MaxVersion(); + if (newversion > version) + UpdateVersion(_type, newversion); } private int MaxVersion() @@ -126,9 +132,12 @@ namespace OpenSim.Data foreach (string s in names) { Match m = r.Match(s); - int MigrationVersion = int.Parse(m.Groups[1].ToString()); - if ( MigrationVersion > max ) - max = MigrationVersion; + if (m.Success) + { + int MigrationVersion = int.Parse(m.Groups[1].ToString()); + if ( MigrationVersion > max ) + max = MigrationVersion; + } } return max; } @@ -137,14 +146,18 @@ namespace OpenSim.Data { int version = 0; DbCommand cmd = _conn.CreateCommand(); - cmd.CommandText = "select version from migrations where name='" + type + "' limit 1"; - using (IDataReader reader = cmd.ExecuteReader()) - { - if (reader.Read()) + try { + cmd.CommandText = "select version from migrations where name='" + type + "' limit 1"; + using (IDataReader reader = cmd.ExecuteReader()) { - version = Convert.ToInt32(reader["version"]); + if (reader.Read()) + { + version = Convert.ToInt32(reader["version"]); + } + reader.Close(); } - reader.Close(); + } catch { + // Something went wrong, so we're version 0 } return version; } @@ -189,9 +202,8 @@ namespace OpenSim.Data // TODO: once this is working, get rid of this if (migrations.Count < 1) { - throw new Exception(string.Format("Resource '{0}' was not found", _type)); + m_log.InfoFormat("Resource '{0}' was not found", _type); } - return migrations; } } -- cgit v1.1