diff options
author | Sean Dague | 2008-06-09 22:20:28 +0000 |
---|---|---|
committer | Sean Dague | 2008-06-09 22:20:28 +0000 |
commit | c62f081380dffab4399b9089e781719e43afd7c1 (patch) | |
tree | d8c76f660076b64a6bafd849da42e4149404dfef | |
parent | migrations seem to not break anything at this point. (diff) | |
download | opensim-SC_OLD-c62f081380dffab4399b9089e781719e43afd7c1.zip opensim-SC_OLD-c62f081380dffab4399b9089e781719e43afd7c1.tar.gz opensim-SC_OLD-c62f081380dffab4399b9089e781719e43afd7c1.tar.bz2 opensim-SC_OLD-c62f081380dffab4399b9089e781719e43afd7c1.tar.xz |
actually create and populate the migrations table correctly.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/Migration.cs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/OpenSim/Data/Migration.cs b/OpenSim/Data/Migration.cs index b5f1a60..0417269 100644 --- a/OpenSim/Data/Migration.cs +++ b/OpenSim/Data/Migration.cs | |||
@@ -53,7 +53,7 @@ namespace OpenSim.Data | |||
53 | /// When a database driver starts up, it specifies a resource that | 53 | /// When a database driver starts up, it specifies a resource that |
54 | /// needs to be brought up to the current revision. For instance: | 54 | /// needs to be brought up to the current revision. For instance: |
55 | /// | 55 | /// |
56 | /// Migration um = new Migration(DbConnection, "Users"); | 56 | /// Migration um = new Migration(Assembly, DbConnection, "Users"); |
57 | /// um.Upgrade(); | 57 | /// um.Upgrade(); |
58 | /// | 58 | /// |
59 | /// This works out which version Users is at, and applies all the | 59 | /// This works out which version Users is at, and applies all the |
@@ -62,6 +62,10 @@ namespace OpenSim.Data | |||
62 | /// migration to be an incremental roll forward of the tables in | 62 | /// migration to be an incremental roll forward of the tables in |
63 | /// question. | 63 | /// question. |
64 | /// | 64 | /// |
65 | /// Assembly must be specifically passed in because otherwise you | ||
66 | /// get the assembly that Migration.cs is part of, and what you | ||
67 | /// really want is the assembly of your database class. | ||
68 | /// | ||
65 | /// </summary> | 69 | /// </summary> |
66 | 70 | ||
67 | public class Migration | 71 | public class Migration |
@@ -99,7 +103,7 @@ namespace OpenSim.Data | |||
99 | cmd.CommandText = _migrations_create; | 103 | cmd.CommandText = _migrations_create; |
100 | cmd.ExecuteNonQuery(); | 104 | cmd.ExecuteNonQuery(); |
101 | 105 | ||
102 | UpdateVersion("migrations", 1); | 106 | InsertVersion("migrations", 1); |
103 | } | 107 | } |
104 | 108 | ||
105 | public void Update() | 109 | public void Update() |
@@ -117,8 +121,13 @@ namespace OpenSim.Data | |||
117 | } | 121 | } |
118 | 122 | ||
119 | newversion = MaxVersion(); | 123 | newversion = MaxVersion(); |
120 | if (newversion > version) | 124 | if (newversion > version) { |
121 | UpdateVersion(_type, newversion); | 125 | if (version == 0) { |
126 | InsertVersion(_type, newversion); | ||
127 | } else { | ||
128 | UpdateVersion(_type, newversion); | ||
129 | } | ||
130 | } | ||
122 | } | 131 | } |
123 | 132 | ||
124 | private int MaxVersion() | 133 | private int MaxVersion() |
@@ -127,7 +136,7 @@ namespace OpenSim.Data | |||
127 | 136 | ||
128 | string[] names = _assem.GetManifestResourceNames(); | 137 | string[] names = _assem.GetManifestResourceNames(); |
129 | List<string> migrations = new List<string>(); | 138 | List<string> migrations = new List<string>(); |
130 | Regex r = new Regex(@"^(\d\d\d)_" + _type + @"\.sql"); | 139 | Regex r = new Regex(@"\.(\d\d\d)_" + _type + @"\.sql"); |
131 | 140 | ||
132 | foreach (string s in names) | 141 | foreach (string s in names) |
133 | { | 142 | { |
@@ -161,11 +170,20 @@ namespace OpenSim.Data | |||
161 | } | 170 | } |
162 | return version; | 171 | return version; |
163 | } | 172 | } |
173 | |||
174 | private void InsertVersion(string type, int version) | ||
175 | { | ||
176 | DbCommand cmd = _conn.CreateCommand(); | ||
177 | cmd.CommandText = "insert into migrations(name, version) values('" + type + "', " + version + ")"; | ||
178 | m_log.InfoFormat("Creating {0} at version {1}", type, version); | ||
179 | cmd.ExecuteNonQuery(); | ||
180 | } | ||
164 | 181 | ||
165 | private void UpdateVersion(string type, int version) | 182 | private void UpdateVersion(string type, int version) |
166 | { | 183 | { |
167 | DbCommand cmd = _conn.CreateCommand(); | 184 | DbCommand cmd = _conn.CreateCommand(); |
168 | cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'"; | 185 | cmd.CommandText = "update migrations set version=" + version + " where name='" + type + "'"; |
186 | m_log.InfoFormat("Updating {0} to version {1}", type, version); | ||
169 | cmd.ExecuteNonQuery(); | 187 | cmd.ExecuteNonQuery(); |
170 | } | 188 | } |
171 | 189 | ||
@@ -183,10 +201,9 @@ namespace OpenSim.Data | |||
183 | 201 | ||
184 | foreach (string s in names) | 202 | foreach (string s in names) |
185 | { | 203 | { |
186 | m_log.Info("MIGRATION: Resources: " + s); | 204 | Match m = r.Match(s); |
187 | if (s.EndsWith(_type + @"\.sql")) | 205 | if (m.Success) |
188 | { | 206 | { |
189 | Match m = r.Match(s); | ||
190 | m_log.Info("MIGRATION: Match: " + m.Groups[1].ToString()); | 207 | m_log.Info("MIGRATION: Match: " + m.Groups[1].ToString()); |
191 | int MigrationVersion = int.Parse(m.Groups[1].ToString()); | 208 | int MigrationVersion = int.Parse(m.Groups[1].ToString()); |
192 | using (Stream resource = _assem.GetManifestResourceStream(s)) | 209 | using (Stream resource = _assem.GetManifestResourceStream(s)) |