Beispiel #1
0
        public ApplyCommand(
            ISchemaManager schemaManager,
            ILogger <ApplyCommand> logger)
            : base(CommandNames.Apply, Resources.ApplyCommandDescription)
        {
            AddOption(CommandOptions.ConnectionStringOption());
            AddOption(CommandOptions.ServerOption());
            AddOption(CommandOptions.VersionOption());
            AddOption(CommandOptions.NextOption());
            AddOption(CommandOptions.LatestOption());
            AddOption(CommandOptions.ForceOption());

            Handler = CommandHandler.Create(
                (string connectionString, Uri server, MutuallyExclusiveType type, bool force, CancellationToken token)
                => HandlerAsync(connectionString, server, type, force, token));

            Argument.AddValidator(symbol => RequiredOptionValidator.Validate(symbol, CommandOptions.ConnectionStringOption(), Resources.ConnectionStringRequiredValidation));
            Argument.AddValidator(symbol => RequiredOptionValidator.Validate(symbol, CommandOptions.ServerOption(), Resources.ServerRequiredValidation));
            Argument.AddValidator(symbol => MutuallyExclusiveOptionValidator.Validate(symbol, new List <Option> {
                CommandOptions.VersionOption(), CommandOptions.NextOption(), CommandOptions.LatestOption()
            }, Resources.MutuallyExclusiveValidation));

            EnsureArg.IsNotNull(logger, nameof(logger));
            EnsureArg.IsNotNull(schemaManager, nameof(schemaManager));

            _logger        = logger;
            _schemaManager = schemaManager;
        }
Beispiel #2
0
 public SetUpEventHandler(
     ISchemaBuilder schemaBuilder,
     ISchemaManager schemaManager)
 {
     _schemaBuilder = schemaBuilder;
     _schemaManager = schemaManager;
 }
Beispiel #3
0
 public FeatureEventHandler(
     ISchemaBuilder schemaBuilder,
     ISchemaManager schemaManager)
 {
     _schemaBuilder = schemaBuilder;
     _schemaManager = schemaManager;
 }
 public UIController(IConfiguration configuration,
                     IEnumerable <ILookupProvider> lookupProviders,
                     ISchemaManager schemaManager)
 {
     this.configuration   = configuration;
     this.schemaManager   = schemaManager;
     this.lookupProviders = lookupProviders.ToList();
 }
 public FullTextIndexCommand(
     ISchemaBuilder schemaBuilder,
     ISchemaManager schemaManager,
     ICacheManager cacheManager)
 {
     _schemaBuilder = schemaBuilder;
     _schemaManager = schemaManager;
     _cacheManager  = cacheManager;
 }
Beispiel #6
0
 public SetUpEventHandler(
     IDefaultRolesManager defaultRolesManager,
     ISchemaBuilder schemaBuilder,
     ISchemaManager schemaManager)
 {
     _defaultRolesManager = defaultRolesManager;
     _schemaBuilder       = schemaBuilder;
     _schemaManager       = schemaManager;
 }
Beispiel #7
0
 public SessionService(
     IConnectionStringService connectionStringService,
     ISchemaManager schemaManagerService,
     ISchemaTreeBuilder schemaTreeBuilder)
 {
     _connectionStringService = connectionStringService;
     _schemaManagerService    = schemaManagerService;
     _schemaTreeBuilder       = schemaTreeBuilder;
 }
Beispiel #8
0
        protected DbTable(DbSession session, ISchemaManager schemaManager,
                          object shardObject, object partitionObject, IShardStrategy shardStrategy)
            : base(session)
        {
            this.SchemaManager = schemaManager;

            this.ShardObject     = shardObject;
            this.PartitionObject = partitionObject;
            this.ShardStrategy   = shardStrategy;

            string tableName = this.EntityType.Name;

            if (this.SchemaManager != null)
            {
                this.Schema = this.SchemaManager.GetSchema <TEntity>();
                if (this.Schema != null)
                {
                    tableName = this.Schema.TableName;
                }
            }

            if (this.Schema == null)
            {
                this.Schema = SchemaParser.GetSchema <TEntity>();
                if (this.Schema != null)
                {
                    tableName = this.Schema.TableName;
                }
            }

            if (this.Schema == null)
            {
                throw new InvalidOperationException($"Cannot parse entity '{this.EntityType}'s schema.");
            }


            this.TableName = tableName;
            if (this.ShardStrategy != null)
            {
                string tableShardNo = this.ShardStrategy.GetTableShardNo(tableName, this.ShardObject);
                if (!string.IsNullOrWhiteSpace(tableShardNo))
                {
                    this.TableName += ("_" + tableShardNo.Trim());
                }

                string tablePartitionNo = this.ShardStrategy.GetTablePartitionNo(tableName, this.ShardObject, this.PartitionObject);
                if (!string.IsNullOrWhiteSpace(tablePartitionNo))
                {
                    this.TableName += ("_" + tablePartitionNo.Trim());
                }
            }


            this.QueryContext = new DbQueryContext(session);
            this.QueryContext.SetFrom <TEntity>(this);
        }
Beispiel #9
0
        private string GetSchemaName(ISchemaManager manager, Guid itemUid)
        {
            var schemaName = string.Empty;
            var schema     = manager.FindItemByUId(itemUid);

            if (schema != null)
            {
                schemaName = schema.Name;
            }
            return(schemaName);
        }
Beispiel #10
0
        internal void Initialize(bool master, ISchemaManager schemaManager,
                                 object shardObject, IShardStrategy shardStrategy, IConnectionManager connectionManager)
        {
            this.UsingMaster = master;

            this.SchemaManager = schemaManager;

            this.ShardObject       = shardObject;
            this.ShardStrategy     = shardStrategy;
            this.ConnectionManager = connectionManager;
        }
        private static void WarmupManager <TM, TS>(ISchemaManager schemaManager)
            where TM : ISchemaManager
            where TS : Schema, ISchemaManagerSchema <TS>
        {
            var typeSchemaManager  = (TM)schemaManager;
            var schemaManagerItems = typeSchemaManager.GetItems();

            foreach (SchemaManagerItem <TS> item in schemaManagerItems)
            {
                Schema instance = item.Instance;
            }
        }
Beispiel #12
0
 public SetUpEventHandler(
     IUserColorProvider userColorProvider,
     UserManager <User> userManager,
     RoleManager <Role> roleManager,
     ISchemaManager schemaManager,
     ISchemaBuilder schemaBuilder)
 {
     _userColorProvider = userColorProvider;
     _schemaBuilder     = schemaBuilder;
     _schemaManager     = schemaManager;
     _userManager       = userManager;
     _roleManager       = roleManager;
 }
Beispiel #13
0
 public SetUpEventHandler(
     ISchemaBuilder schemaBuilder,
     IDefaultRolesManager defaultRolesManager,
     UserManager <User> userManager,
     RoleManager <Role> roleManager,
     ISchemaManager schemaManager)
 {
     _schemaBuilder       = schemaBuilder;
     _defaultRolesManager = defaultRolesManager;
     _userManager         = userManager;
     _roleManager         = roleManager;
     _schemaManager       = schemaManager;
 }
Beispiel #14
0
 public UIController(IConfiguration configuration,
                     ILookupManager lookupManager,
                     ITypeResolver typeResolver,
                     ISchemaManager schemaManager,
                     ICubesEnvironment cubesEnvironment,
                     IServiceScopeFactory scopeFactory)
 {
     this.configuration    = configuration;
     this.schemaManager    = schemaManager;
     this.typeResolver     = typeResolver;
     this.lookupManager    = lookupManager;
     this.cubesEnvironment = cubesEnvironment;
     this.scopeFactory     = scopeFactory;
 }
Beispiel #15
0
        public AvailableCommand(ISchemaManager schemaManager)
            : base(CommandNames.Available, Resources.AvailableCommandDescription)
        {
            AddOption(CommandOptions.ServerOption());

            Handler = CommandHandler.Create(
                (InvocationContext context, Uri server, CancellationToken token)
                => HandlerAsync(context, server, token));

            Argument.AddValidator(symbol => RequiredOptionValidator.Validate(symbol, CommandOptions.ServerOption(), Resources.ServerRequiredValidation));

            EnsureArg.IsNotNull(schemaManager);

            _schemaManager = schemaManager;
        }
Beispiel #16
0
        public CurrentCommand(ISchemaManager schemaManager)
            : base(CommandNames.Current, Resources.CurrentCommandDescription)
        {
            AddOption(CommandOptions.ServerOption());
            AddOption(CommandOptions.ConnectionStringOption());

            Handler = CommandHandler.Create(
                (InvocationContext context, Uri server, string connectionString, CancellationToken token)
                => HandlerAsync(context, connectionString, server, token));

            Argument.AddValidator(symbol => RequiredOptionValidator.Validate(symbol, CommandOptions.ConnectionStringOption(), Resources.ConnectionStringRequiredValidation));
            Argument.AddValidator(symbol => RequiredOptionValidator.Validate(symbol, CommandOptions.ServerOption(), Resources.ServerRequiredValidation));

            EnsureArg.IsNotNull(schemaManager, nameof(schemaManager));

            _schemaManager = schemaManager;
        }
        protected async Task ExecuteMigrationStep(IDbConnection connection, ISchemaManager targetManager, MigrationStep step, ObjectSchema targetSchema)
        {
            if (step.Action == MigrationAction.Alter)
            {
                throw new NotImplementedException($"Explicit alters are not supported");
            }

            if (step.TargetType == MigrationTarget.Object)
            {
                if (step.Action == MigrationAction.Create)
                {
                    await targetManager.CreateObject(connection, targetSchema);
                }
                else if (step.Action == MigrationAction.Drop)
                {
                    await targetManager.DeleteObject(connection, step.TargetName);
                }
            }
            else if (step.TargetType == MigrationTarget.Column)
            {
                if (step.Action == MigrationAction.Create)
                {
                    await targetManager.CreateColumn(connection, targetSchema.Name, targetSchema.Columns[step.TargetName]);
                }
                else if (step.Action == MigrationAction.Drop)
                {
                    await targetManager.DeleteColumn(connection, targetSchema.Name, step.TargetName);
                }
            }
            else if (step.TargetType == MigrationTarget.Index)
            {
                if (step.Action == MigrationAction.Create)
                {
                    await targetManager.CreateIndex(connection, targetSchema.Name, targetSchema.Indexes[step.TargetName]);
                }
                else if (step.Action == MigrationAction.Drop)
                {
                    await targetManager.DeleteIndex(connection, targetSchema.Name, step.TargetName);
                }
            }
            else
            {
                throw new NotImplementedException($"No implementation for migration step");
            }
        }
Beispiel #18
0
        public FabricDatabase(string databaseRoot, IDatabaseHelper databaseHelper = null,
                              IChangeSetHelper changeSetHelper = null, ISchemaManager schemaManager = null,
                              IVersionHelper versionHelper     = null)
        {
            DatabaseRoot = databaseRoot;

            if (Path.IsPathRooted(DatabaseRoot))
            {
                FullDataBaseRoot = DatabaseRoot;
            }
            else
            {
                var relativePathRoot = AppDomain.CurrentDomain.BaseDirectory;
                var relativePath     = Path.Combine(relativePathRoot, DatabaseRoot);
                FullDataBaseRoot = relativePath;
            }

            Resolver = new UnityContainer();
            Resolver.RegisterInstance(this);

            SerializerSettings = new JsonSerializerSettings {
                Converters = new List <JsonConverter> {
                    new DataPageSerializer(Resolver)
                },
                Formatting       = Formatting.Indented,
                ContractResolver =
                    new CamelCasePropertyNamesContractResolver()
            };

            Resolver.RegisterInstance(SerializerSettings);

            Resolver.RegisterInstanceOrDefault <IDatabaseHelper, FileSystemDatabaseHelper>(databaseHelper);
            Resolver.RegisterInstanceOrDefault <IChangeSetHelper, ChangeSetHelper>(changeSetHelper);
            Resolver.RegisterInstanceOrDefault <ISchemaManager, SchemaManager>(schemaManager);
            Resolver.RegisterInstanceOrDefault <IVersionHelper, VersionHelper>(versionHelper);
        }
 public CachedSchemaManager(ISchemaCache schemaCache, ISchemaManager impl)
 {
     this.Impl        = impl;
     this.SchemaCache = schemaCache;
 }
 public DevJokeConfiguration(ISchemaManager schemaManager)
     : base(schemaManager)
 {
 }
Beispiel #21
0
 public CategoryConfiguration(ISchemaManager schemaManager)
     : base(schemaManager)
 {
 }
Beispiel #22
0
 public SQLServerDatabase(IConnectionManager connectionManager, IShardStrategy shardStrategy, ISchemaManager schemaManager)
     : base(connectionManager, shardStrategy, schemaManager)
 {
 }
        public async Task <SchemaMigrationPlan> PlanMigration(IDbConnection connection, ISchemaManager targetManager, ObjectSchema targetSchema, MigrationOptions options)
        {
            options = options ?? new MigrationOptions();

            // Whichever columns are mapped to SqlType, we let the manager decide the best choice
            foreach (var column in targetSchema.Columns.Values)
            {
                if (column.SqlType == null)
                {
                    column.SqlType = targetManager.MapColumnType(column.DotnetType);
                }
            }

            var report = new SchemaMigrationPlan()
            {
                Target = targetSchema,
            };

            report.Existing = await targetManager.GetSchema(connection, targetSchema.Name);

            if (report.Existing == null)
            {
                report.Steps.Add(new MigrationStep()
                {
                    TargetName = targetSchema.Name,
                    Action     = MigrationAction.Create,
                    TargetType = MigrationTarget.Object,
                });
                return(report);
            }


            if (options.ForceDropRecreate)
            {
                options.AssertTableDeleteAllowed(targetSchema.Name);
                report.Steps.Add(new MigrationStep()
                {
                    TargetName = targetSchema.Name,
                    Action     = MigrationAction.Drop,
                    TargetType = MigrationTarget.Object,
                });
                report.Steps.Add(new MigrationStep()
                {
                    TargetName = targetSchema.Name,
                    Action     = MigrationAction.Create,
                    TargetType = MigrationTarget.Object,
                });
                return(report);
            }

            var allColumnNames = report.Target.Columns.Keys.Union(report.Existing.Columns.Keys);

            foreach (var column in allColumnNames)
            {
                var targetColumn   = report.Target.Columns.ContainsKey(column) ? report.Target.Columns[column] : null;
                var existingColumn = report.Existing.Columns.ContainsKey(column) ? report.Existing.Columns[column] : null;

                PlanMigrateColumn(report, existingColumn, targetColumn, options);
            }

            var allIndexNames = report.Target.Indexes.Keys.Union(report.Existing.Indexes.Keys);

            foreach (var index in allIndexNames)
            {
                var targetIndex   = report.Target.Columns.ContainsKey(index) ? report.Target.Columns[index] : null;
                var existingIndex = report.Existing.Columns.ContainsKey(index) ? report.Existing.Columns[index] : null;

                PlanMigrateIndex(report, existingIndex, targetIndex, options);
            }

            return(report);
        }
 public async Task <SchemaMigrationPlan> ExecuteMigration(IDbConnection connection, ISchemaManager targetManager, SchemaMigrationPlan plan)
 {
     foreach (var step in plan.Steps)
     {
         await ExecuteMigrationStep(connection, targetManager, step, plan.Target);
     }
     return(plan);
 }
Beispiel #25
0
        public static async Task PlanAndMigrate(this ISchemaMigrator migrator, IDbConnection connection, ISchemaManager targetManager, ObjectSchema targetSchema, MigrationOptions options)
        {
            var plan = await migrator.PlanMigration(
                connection : connection,
                targetManager : targetManager,
                targetSchema : targetSchema,
                options : options
                );

            await migrator.ExecuteMigration(
                connection : connection,
                targetManager : targetManager,
                migrationPlan : plan
                );
        }
Beispiel #26
0
 internal SQLiteTable(SQLiteSession session, ISchemaManager schemaManager,
                      object shardObject, object partitionObject, IShardStrategy shardStrategy)
     : base(session, schemaManager, shardObject, partitionObject, shardStrategy)
 {
 }
Beispiel #27
0
        public AbstractDatabase(IConnectionManager connectionManager, IShardStrategy shardStrategy, ISchemaManager schemaManager)
        {
            AssertUtil.ArgumentNotNull(connectionManager, nameof(connectionManager));

            this.ConnectionManager = connectionManager;
            this.ShardStrategy     = shardStrategy;
            this.SchemaManager     = schemaManager;
        }