Exemplo n.º 1
0
        public void ScriptTableData(string fileName, string tableList)
        {
            var file     = DirectoryManager.GetDirectoryBaseFile(fileName);
            var scripter = new MigrationsScripter(_migrationsServer);

            scripter.ScriptDataToFile(file, tableList);
        }
Exemplo n.º 2
0
 public void UpdateDatabase(SchemaVersion version)
 {
     Console.WriteLine(
         "This is not suggested to be used as the methods might be newer, make sure you have the correct methods version checked out when not updating to the latest schema version.");
     DirectoryManager.GetUpdateScripts(GetVersion()).Where(v => v.Version <= version).ToList().ForEach(
         s => s.ApplyUpdate(this));
 }
Exemplo n.º 3
0
        public void MarkSchemaChangesWithLatestVersion()
        {
            var currentVersion = _migrationsServer.Database.Version;
            var updates        = DirectoryManager.GetUpdateScripts(currentVersion);

            updates.ForEach(u => _migrationsServer.Database.UpdateSchemaChangesTable(u.Version, u.UpdateFile.Name));
        }
Exemplo n.º 4
0
        private void ScriptObject(string directory, NamedSmoObject scriptObject)
        {
            var fileName = DirectoryManager.GetScriptFileName(scriptObject, directory);

            AppendDropScript(scriptObject, fileName);

            AppendCreateScript(scriptObject);

            var processor = new PostScriptProcessor(fileName);

            processor.Execute();
        }
Exemplo n.º 5
0
        private void ScriptBase(List <Urn> objects)
        {
            _server.Scripter.Options = CreateOptions();
            var fileName = DirectoryManager.GetFileCreateDatabase();

            _server.Scripter.Options.FileName     = fileName;
            _server.Scripter.Options.AppendToFile = false;
            _server.Scripter.Script(objects.ToArray());
            var processor = new PostScriptProcessor(fileName);

            processor.Execute();
        }
Exemplo n.º 6
0
 public void LoadSchema()
 {
     Console.WriteLine("Loading schema");
     using (var manager = new TransactionManager(_migrationsServer))
     {
         Console.WriteLine("Creating base");
         RunScript(DirectoryManager.GetFileCreateDatabase());
         Console.WriteLine("Creating methods");
         RunScript(DirectoryManager.GetFileCreateMethods());
         Console.WriteLine("Populating schema changes");
         RunScript(DirectoryManager.GetFileSchemaChanges());
         manager.CommitTransaction();
     }
 }
Exemplo n.º 7
0
        private void ScriptObjects(string subDirectory, IEnumerable <NamedSmoObject> objects, ScriptingOptions options = null)
        {
            var directory = DirectoryManager.GetDirectory(subDirectory);

            DirectoryManager.ClearDirectory(directory);
            if (objects.Count() == 0)
            {
                return;
            }
            DirectoryManager.EnsureDirectoryExists(directory);

            _server.Scripter.Options = options ?? CreateOptions();
            foreach (var scriptObject in objects)
            {
                ScriptObject(directory, scriptObject);
            }
        }
Exemplo n.º 8
0
        public void ScriptCreateDatabase()
        {
            Console.WriteLine("Scripting database schema {0}", _database.Name);

            DirectoryManager.EnsureDirectoryBaseExists();

            var watch = new Stopwatch();

            watch.Start();

            var baseUrns = GetBaseUrns();

            ScriptBase(baseUrns);
            PostScriptProcessor processor;

            Console.WriteLine("Done with base {0}", watch.Elapsed.TotalSeconds);

            var methodUrns = GetMethodUrns();

            Console.WriteLine("Done making dependency list {0}", watch.Elapsed.TotalSeconds);

            var methodsName = DirectoryManager.GetFileCreateMethods();

            if (File.Exists(methodsName))
            {
                File.Delete(methodsName);
            }
            if (methodUrns.Count() == 0)
            {
                Console.WriteLine("No methods to script");
            }
            else
            {
                var ordered = WalkMethodDependencies(baseUrns, methodUrns);
                Console.WriteLine("Done walking dependency list {0}", watch.Elapsed.TotalSeconds);

                ScriptMethods(methodsName, ordered);
                Console.WriteLine("Done scripting methods {0}", watch.Elapsed.TotalSeconds);
            }

            ScriptDataToFile(DirectoryManager.GetFileSchemaChanges(), "SchemaChanges");
        }
Exemplo n.º 9
0
        public void RunScript(string fileName)
        {
            var script = DirectoryManager.GetScript(fileName);

            _migrationsServer.Database.RunScript(script);
        }
Exemplo n.º 10
0
 public void UpdateDatabase()
 {
     DirectoryManager.GetUpdateScripts(GetVersion()).ForEach(s => s.ApplyUpdate(this));
     _migrationsServer.Database.DropMethods();
     CreateMethods();
 }
Exemplo n.º 11
0
 private void CreateMethods()
 {
     Console.WriteLine("Creating methods");
     RunScript(DirectoryManager.GetFileCreateMethods());
 }