aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Migration.cs
diff options
context:
space:
mode:
authorSean Dague2008-06-09 22:01:21 +0000
committerSean Dague2008-06-09 22:01:21 +0000
commit69fb4ee208daac549b6f271fd6140d745406984d (patch)
tree4a952155b048d9831e2dc592a5e35520b65b059d /OpenSim/Data/Migration.cs
parentmove Migration support into OpenSim.Data, because it (diff)
downloadopensim-SC_OLD-69fb4ee208daac549b6f271fd6140d745406984d.zip
opensim-SC_OLD-69fb4ee208daac549b6f271fd6140d745406984d.tar.gz
opensim-SC_OLD-69fb4ee208daac549b6f271fd6140d745406984d.tar.bz2
opensim-SC_OLD-69fb4ee208daac549b6f271fd6140d745406984d.tar.xz
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.
Diffstat (limited to 'OpenSim/Data/Migration.cs')
-rw-r--r--OpenSim/Data/Migration.cs36
1 files changed, 24 insertions, 12 deletions
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
82 _type = type; 82 _type = type;
83 _conn = conn; 83 _conn = conn;
84 _assem = assem; 84 _assem = assem;
85
86 Initialize();
85 } 87 }
86 88
87 private void Initialize() 89 private void Initialize()
@@ -103,6 +105,7 @@ namespace OpenSim.Data
103 public void Update() 105 public void Update()
104 { 106 {
105 int version = 0; 107 int version = 0;
108 int newversion = 0;
106 version = FindVersion(_type); 109 version = FindVersion(_type);
107 110
108 List<string> migrations = GetMigrationsAfter(version); 111 List<string> migrations = GetMigrationsAfter(version);
@@ -112,7 +115,10 @@ namespace OpenSim.Data
112 cmd.CommandText = m; 115 cmd.CommandText = m;
113 cmd.ExecuteNonQuery(); 116 cmd.ExecuteNonQuery();
114 } 117 }
115 UpdateVersion(_type, MaxVersion()); 118
119 newversion = MaxVersion();
120 if (newversion > version)
121 UpdateVersion(_type, newversion);
116 } 122 }
117 123
118 private int MaxVersion() 124 private int MaxVersion()
@@ -126,9 +132,12 @@ namespace OpenSim.Data
126 foreach (string s in names) 132 foreach (string s in names)
127 { 133 {
128 Match m = r.Match(s); 134 Match m = r.Match(s);
129 int MigrationVersion = int.Parse(m.Groups[1].ToString()); 135 if (m.Success)
130 if ( MigrationVersion > max ) 136 {
131 max = MigrationVersion; 137 int MigrationVersion = int.Parse(m.Groups[1].ToString());
138 if ( MigrationVersion > max )
139 max = MigrationVersion;
140 }
132 } 141 }
133 return max; 142 return max;
134 } 143 }
@@ -137,14 +146,18 @@ namespace OpenSim.Data
137 { 146 {
138 int version = 0; 147 int version = 0;
139 DbCommand cmd = _conn.CreateCommand(); 148 DbCommand cmd = _conn.CreateCommand();
140 cmd.CommandText = "select version from migrations where name='" + type + "' limit 1"; 149 try {
141 using (IDataReader reader = cmd.ExecuteReader()) 150 cmd.CommandText = "select version from migrations where name='" + type + "' limit 1";
142 { 151 using (IDataReader reader = cmd.ExecuteReader())
143 if (reader.Read())
144 { 152 {
145 version = Convert.ToInt32(reader["version"]); 153 if (reader.Read())
154 {
155 version = Convert.ToInt32(reader["version"]);
156 }
157 reader.Close();
146 } 158 }
147 reader.Close(); 159 } catch {
160 // Something went wrong, so we're version 0
148 } 161 }
149 return version; 162 return version;
150 } 163 }
@@ -189,9 +202,8 @@ namespace OpenSim.Data
189 202
190 // TODO: once this is working, get rid of this 203 // TODO: once this is working, get rid of this
191 if (migrations.Count < 1) { 204 if (migrations.Count < 1) {
192 throw new Exception(string.Format("Resource '{0}' was not found", _type)); 205 m_log.InfoFormat("Resource '{0}' was not found", _type);
193 } 206 }
194
195 return migrations; 207 return migrations;
196 } 208 }
197 } 209 }