예제 #1
0
        private void ProcessMigrations(IVersionMigrationHelper migrationHelper, string direction)
        {
            Version.TryParse(_options.RequestedApiVersion(migrationHelper.GetHttpContext()), out var requestedVersion);

            var currentVersion = Version.Parse(_options.CurrentApiVersion);

            if (requestedVersion == null || currentVersion.Equals(requestedVersion))
            {
                return;
            }

            var migrations = GetMigrations();

            if (direction == "up")
            {
                migrations = migrations.Reverse();
            }

            foreach (var migration in migrations)
            {
                if (!ShouldApply(requestedVersion, migration.GetVersionTag(), direction))
                {
                    continue;
                }

                if (direction == "up")
                {
                    migration.Up(migrationHelper);
                }
                else
                {
                    migration.Down(migrationHelper);
                }
            }
        }
        public void Up(IVersionMigrationHelper migrationHelper)
        {
            if (ShouldApply(migrationHelper.GetHttpContext()))
            {
                var user = migrationHelper.GetRequestBody <dynamic>();

                if (user.userId == null)
                {
                    user.userId = user.id;
                }

                migrationHelper.SetRequestBody(user);
            }
        }
        public void Down(IVersionMigrationHelper migrationHelper)
        {
            if (ShouldApply(migrationHelper.GetHttpContext()))
            {
                var user = migrationHelper.GetResponseBody <dynamic>();

                var oldFormat = new
                {
                    id = user.userId,
                    user.email,
                    user.name
                };

                migrationHelper.SetResponseBody(oldFormat);
            }
        }