// // The ISchemaBackend interface // // Export the current schema to the backing directory, in a format that can // be read back later. public VxSchemaErrors Put(VxSchema schema, VxSchemaChecksums sums, VxPutOpts opts) { bool isbackup = (opts & VxPutOpts.IsBackup) != 0; DirectoryInfo dir = new DirectoryInfo(exportdir); dir.Create(); foreach (var p in schema) { if (!sums.ContainsKey(p.Key)) throw new ArgumentException("Missing checksum for " + p.Key); VxSchemaElement elem = p.Value; if (elem.text == null || elem.text == "") DropSchema(new string[] {elem.key}); else ExportToDisk(p.Value, sums[p.Key], isbackup); } // Writing schemas to disk doesn't give us any per-element errors. return new VxSchemaErrors(); }
// Helper method to load a given on-disk element's schema and checksums // into the container objects. // Throws an ArgumentException if the schema or sums already contains the // given key. static void AddFromFile(string path, string type, string name, VxSchema schema, VxSchemaChecksums sums) { string key = wv.fmt("{0}/{1}", type, name); // schema/sums.Add would throw an exception in this situation anyway, // but it's nice to provide a more helpful error message. if (schema != null && schema.ContainsKey(key)) throw new ArgumentException("Conflicting schema key: " + key); if (sums != null && sums.ContainsKey(key)) throw new ArgumentException("Conflicting sums key: " + key); VxSchemaChecksum sum; VxSchemaElement elem; ReadSchemaFile(path, type, name, out elem, out sum); if (schema != null && elem != null) schema.Add(key, elem); if (sums != null && sum != null) sums.Add(key, sum); }
public VxSchemaChecksums GetChecksums() { log.print("GetChecksums\n"); VxSchemaChecksums sums = new VxSchemaChecksums(); foreach (string type in ProcedureTypes) { try { if (type == "Procedure") { // Set up self test DbiExec("create procedure schemamatic_checksum_test " + "as print 'hello' "); } GetProcChecksums(sums, type, 0); if (type == "Procedure") { // Self-test the checksum feature. If mssql's checksum // algorithm changes, we don't want to pretend our checksum // list makes any sense! string test_csum = "Procedure/schemamatic_checksum_test"; ulong got_csum = 0; if (sums.ContainsKey(test_csum)) got_csum = sums[test_csum].checksums.First(); ulong want_csum = 0x173d6ee8; if (want_csum != got_csum) { throw new Exception(String.Format( "checksum_test_mismatch! {0} != {1}", got_csum, want_csum)); } sums.Remove(test_csum); } } finally { if (type == "Procedure") { DbiExec("drop procedure schemamatic_checksum_test"); } } GetProcChecksums(sums, type, 1); } // Do tables separately GetTableChecksums(sums); // Do indexes separately AddIndexChecksumsToTables(sums); // Do XML schema collections separately (FIXME: only if SQL2005) GetXmlSchemaChecksums(sums); return sums; }