Exemplo n.º 1
0
        public async Task <Node> GetHierarchyAsync(string connectionName)
        {
            var connectionEntry = await _connectionStringService.GetConnectionStringEntry(connectionName);

            var schema = await _schemaManagerService.GetSchema(connectionEntry.ProviderName, connectionEntry.ConnectionString);

            var connectionNode = _schemaTreeBuilder.BuildTree(schema);

            connectionNode.Name = connectionName;

            return(connectionNode);
        }
Exemplo n.º 2
0
        private async Task GetHierarchy(SessionModel session)
        {
            var schema = await _schemaManagerService.GetSchema(
                session.Driver.ProviderName,
                session.Connetion.ConnectionString);

            var connectionNode = _schemaTreeBuilder.BuildTree(schema);

            connectionNode.Name = session.SessionName;

            session.Schema = connectionNode;
        }
Exemplo n.º 3
0
 public IActionResult GetSchema(string schemaName)
 {
     return(Ok(schemaManager.GetSchema(schemaName)));
 }
        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);
        }