예제 #1
0
        private async static Task <Storage> InitNew()
        {
            var store         = new Storage();
            var initialSchema = SchemaVersion.Create();
            var result        = await store.UpgradeProcess(initialSchema);

            Function.Log("Applying initial store schema");

            var availableUpdates = DiscoverAvailableUpgrades(initialSchema).ToList();

            Function.Log("DiscoverAvailableUpgrades completed");
            Function.Log(String.Format("Store has {0} updates available", availableUpdates.Count));
            foreach (var update in availableUpdates)
            {
                Function.Log(String.Format("Upgrading to {0}", update.id));
                await store.UpgradeProcess(update);
            }

            if (result == UpgradeStatus.COMPLETED)
            {
                Function.Log("SQL is ready");
            }
            else if (result == UpgradeStatus.MISSING_SCHEMAS)
            {
                Function.Log("Missing schema");
            }
            else
            {
                Function.Log(String.Format("Schema upgrade failed as {0}", result));
            }
            Function.Log("InitStore completed version upgrade");


            return(store);
        }
예제 #2
0
        public static List <SchemaVersion> DiscoverAvailableUpgrades(SchemaVersion minSchema)
        {
            var path = Function.GetAssetPath("Schemas", true);

            Function.Log("Path Length " + path.Length);
            return(Directory
                   .EnumerateFiles(path, "*.sql", SearchOption.TopDirectoryOnly)
                   .Select(x => x.Substring(path.Length + 1).Replace(".sql", String.Empty)) //remove dir and .sql from name
                   .Where(x => x != "initial")
                   .Select(x => SchemaVersion.Create(x, new List <string>()
            {
                x
            }))
                   .Where(x => x.Version.CompareTo(minSchema.Version) > 0 && x.Version.CompareTo(Globals.SchemaVersion) <= 0) //only versions less than the global.schema
                   .ToList());
        }