public void SchemaTests_SchemaNameEquality()
 {
     var schemaName = new SchemaName("namespace.name");
     var secondSchemaName = new SchemaName("namespace.name");
     var differentSchemaName = new SchemaName("different.name");
     Utilities.VerifyEquality(schemaName, secondSchemaName, differentSchemaName);
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="NamedEntityAttributes" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="aliases">The aliases.</param>
        /// <param name="doc">The doc.</param>
        public NamedEntityAttributes(SchemaName name, IEnumerable<string> aliases, string doc)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (aliases == null)
            {
                throw new ArgumentNullException("aliases");
            }

            this.Name = name;
            this.Aliases = new List<string>(aliases);
            this.Doc = string.IsNullOrEmpty(doc) ? string.Empty : doc;
        }
        /// <summary>
        /// Parses the record field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="parent">The parent schema.</param>
        /// <param name="namedSchemas">The named schemas.</param>
        /// <param name="position">The position.</param>
        /// <returns>
        /// Schema internal representation.
        /// </returns>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when <paramref name="field"/> is not valid or when sort order is not valid.</exception>
        private RecordField ParseRecordField(JObject field, NamedSchema parent, Dictionary<string, NamedSchema> namedSchemas, int position)
        {
            var name = field.RequiredProperty<string>(Token.Name);
            var doc = field.OptionalProperty<string>(Token.Doc);
            var order = field.OptionalProperty<string>(Token.Order);
            var aliases = this.GetAliases(field, parent.FullName);
            var fieldType = field[Token.Type];
            if (fieldType == null)
            {
                throw new SerializationException(
                    string.Format(CultureInfo.InvariantCulture, "Record field schema '{0}' has no type.", field));
            }

            TypeSchema type = this.Parse(fieldType, parent, namedSchemas);
            object defaultValue = null;
            bool hasDefaultValue = field[Token.Default] != null;
            if (hasDefaultValue)
            {
                var objectParser = new JsonObjectParser();
                defaultValue = objectParser.Parse(type, field[Token.Default].ToString());
            }

            var orderValue = SortOrder.Ascending;
            if (!string.IsNullOrEmpty(order))
            {
                if (!SortValue.ContainsKey(order.ToUpperInvariant()))
                {
                    throw new SerializationException(
                        string.Format(CultureInfo.InvariantCulture, "Invalid sort order of the field '{0}'.", order));
                }
                orderValue = SortValue[order.ToUpperInvariant()];
            }

            var fieldName = new SchemaName(name);
            var attributes = new NamedEntityAttributes(fieldName, aliases, doc);

            return new RecordField(attributes, type, orderValue, hasDefaultValue, defaultValue, null, position);
        }
        /// <summary>
        /// Parses a JSON object representing an Avro enumeration to a <see cref="Microsoft.Hadoop.Avro.Schema.EnumSchema"/>.
        /// </summary>
        /// <param name="enumeration">The JSON token that represents the enumeration.</param>
        /// <param name="parent">The parent schema.</param>
        /// <param name="namedSchemas">The named schemas.</param>
        /// <returns>
        /// Instance of <see cref="TypeSchema" /> containing IR of the enumeration.
        /// </returns>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when <paramref name="enumeration"/> contains invalid symbols.</exception>
        private TypeSchema ParseEnumType(JObject enumeration, NamedSchema parent, Dictionary<string, NamedSchema> namedSchemas)
        {
            var name = enumeration.RequiredProperty<string>(Token.Name);
            var nspace = this.GetNamespace(enumeration, parent, name);
            var enumName = new SchemaName(name, nspace);

            var doc = enumeration.OptionalProperty<string>(Token.Doc);
            var aliases = this.GetAliases(enumeration, enumName.Namespace);
            var attributes = new NamedEntityAttributes(enumName, aliases, doc);

            List<string> symbols = enumeration.OptionalArrayProperty(
                Token.Symbols,
                (symbol, index) =>
                {
                    if (symbol.Type != JTokenType.String)
                    {
                        throw new SerializationException(
                            string.Format(CultureInfo.InvariantCulture, "Expected an enum symbol of type string however the type of the symbol is '{0}'.", symbol.Type));
                    }
                    return (string)symbol;
                });

            Dictionary<string, string> customAttributes = enumeration.GetAttributesNotIn(StandardProperties.Enumeration);
            var result = new EnumSchema(attributes, typeof(AvroEnum), customAttributes);
            namedSchemas.Add(result.FullName, result);
            symbols.ForEach(result.AddSymbol);
            return result;
        }
        /// <summary>
        /// Parses the record type.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <param name="parent">The parent schema.</param>
        /// <param name="namedSchemas">The named schemas.</param>
        /// <returns>
        /// Schema internal representation.
        /// </returns>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when <paramref name="record"/> can not be parsed properly.</exception>
        private TypeSchema ParseRecordType(JObject record, NamedSchema parent, Dictionary<string, NamedSchema> namedSchemas)
        {
            var name = record.RequiredProperty<string>(Token.Name);
            var nspace = this.GetNamespace(record, parent, name);
            var recordName = new SchemaName(name, nspace);

            var doc = record.OptionalProperty<string>(Token.Doc);
            var aliases = this.GetAliases(record, recordName.Namespace);
            var attributes = new NamedEntityAttributes(recordName, aliases, doc);

            Dictionary<string, string> customAttributes = record.GetAttributesNotIn(StandardProperties.Record);
            var result = new RecordSchema(attributes, typeof(AvroRecord), customAttributes);
            namedSchemas.Add(result.FullName, result);

            List<RecordField> fields = record.OptionalArrayProperty(
                Token.Fields,
                (field, index) =>
                {
                    if (field.Type != JTokenType.Object)
                    {
                        throw new SerializationException(
                            string.Format(CultureInfo.InvariantCulture, "Property 'fields' has invalid value '{0}'.", field));
                    }
                    return this.ParseRecordField(field as JObject, result, namedSchemas, index);
                });

            fields.ForEach(result.AddField);
            return result;
        }
Example #6
0
        public void ToSchema(SchemaName schemaName)
        {
            this.Name = this.Name.OnSchema(schemaName);

            foreach (var item in TablesMList())
                item.ToSchema(schemaName);
        }
Example #7
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override int GetHashCode()
 {
     unchecked
     {
         return((ConnectionString.GetHashCode() * 397) ^ (ProviderName.GetHashCode() * 397) ^ SchemaName.GetHashCode());
     }
 }
Example #8
0
            SchemaName GetSchemaName(Type type)
            {
                var isPostgres = this.Schema.Settings.IsPostgres;

                return(new SchemaName(this.GetDatabaseName(type), GetSchemaNameName(type) ?? SchemaName.Default(isPostgres).Name, isPostgres));
            }
Example #9
0
 public static SqlPreCommand DropSchema(SchemaName schemaName)
 {
     return new SqlPreCommandSimple("DROP SCHEMA {0}".Formato(schemaName));
 }
Example #10
0
 public IRepository <T> GetRepository <T>(SchemaName schemaName = SchemaName.Core) where T : class
 {
     return(new XenatixRepository <T>(xenatixContext, schemaName));
 }
Example #11
0
 public static SqlPreCommand RenameForeignKey(SchemaName schema, string oldName, string newName)
 {
     return SP_RENAME(schema, oldName, newName, "OBJECT");
 }
        /// <summary>
        /// Loads the columns.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <param name="schemaName">Name of the schema.</param>
        /// <param name="conn">The conn.</param>
        /// <param name="nameAliases">The name aliases.</param>
        /// <param name="nameFormat">The name format.</param>
        /// <param name="names">The names.</param>
        protected void LoadColumns(Database schema, SchemaName schemaName, IDbConnection conn, INameAliases nameAliases, NameFormat nameFormat, Names names)
        {
            var columnRows = ReadColumns(conn, schemaName.DbName);

            foreach (var columnRow in columnRows)
            {
                var columnName = CreateColumnName(columnRow.ColumnName, columnRow.TableName, columnRow.TableSchema, nameAliases, nameFormat);
                names.AddColumn(columnRow.TableName, columnName);

                //find which table this column belongs to
                string fullColumnDbName = GetFullDbName(columnRow.TableName, columnRow.TableSchema);
                DbLinq.Schema.Dbml.Table tableSchema = schema.Tables.FirstOrDefault(tblSchema => fullColumnDbName == tblSchema.Name);
                if (tableSchema == null)
                {
                    WriteErrorLine("ERROR L46: Table '" + columnRow.TableName + "' not found for column " + columnRow.ColumnName);
                    continue;
                }
                var column = new Column();
                column.Name   = columnName.DbName;
                column.Member = columnName.PropertyName;
                column.DbType = columnRow.FullType;

                if (columnRow.PrimaryKey.HasValue)
                {
                    column.IsPrimaryKey = columnRow.PrimaryKey.Value;
                }

                bool?generated = (nameAliases != null) ? nameAliases.GetColumnGenerated(columnRow.ColumnName, columnRow.TableName, columnRow.TableSchema) : null;
                if (!generated.HasValue)
                {
                    generated = columnRow.Generated;
                }
                if (generated.HasValue)
                {
                    column.IsDbGenerated = generated.Value;
                }

                AutoSync?autoSync = (nameAliases != null) ? nameAliases.GetColumnAutoSync(columnRow.ColumnName, columnRow.TableName, columnRow.TableSchema) : null;
                if (autoSync.HasValue)
                {
                    column.AutoSync = autoSync.Value;
                }

                // the Expression can originate from two sources:
                // 1. DefaultValue
                // 2. Expression
                // we use any valid source (we can't have both)
                if (column.IsDbGenerated && columnRow.DefaultValue != null)
                {
                    column.Expression = columnRow.DefaultValue;
                }

                column.CanBeNull = columnRow.Nullable;

                string columnTypeAlias = nameAliases != null?nameAliases.GetColumnForcedType(columnRow.ColumnName, columnRow.TableName, columnRow.TableSchema) : null;

                var columnType = MapDbType(columnName.DbName, columnRow);

                var columnEnumType = columnType as EnumType;
                if (columnEnumType != null)
                {
                    var enumType = column.SetExtendedTypeAsEnumType();
                    enumType.Name = columnEnumType.Name;
                    foreach (KeyValuePair <string, int> enumValue in columnEnumType.EnumValues)
                    {
                        enumType[enumValue.Key] = enumValue.Value;
                    }
                }
                else if (columnTypeAlias != null)
                {
                    column.Type = columnTypeAlias;
                }
                else
                {
                    column.Type = columnType.ToString();
                }

                tableSchema.Type.Columns.Add(column);
            }
        }
Example #13
0
 /// <summary>
 /// Loads the constraints.
 /// </summary>
 /// <param name="schema">The schema.</param>
 /// <param name="schemaName">Name of the schema.</param>
 /// <param name="conn">The conn.</param>
 /// <param name="nameFormat">The name format.</param>
 /// <param name="names">The names.</param>
 protected abstract void LoadConstraints(Database schema, SchemaName schemaName, IDbConnection conn, NameFormat nameFormat, Names names);
Example #14
0
        public string GetQuery()
        {
            string          sql         = string.Empty;
            string          indexName   = IndexName.ToQuota();
            string          schemaName  = SchemaName.ToQuota();
            string          objectName  = ObjectName.ToQuota();
            string          partition   = IsPartitioned ? PartitionNumber.ToString() : "ALL";
            DataCompression compression = DataCompression;

            if (IsColumnstore)
            {
                if (FixType == IndexOp.RebuildColumnstore)
                {
                    compression = DataCompression.Columnstore;
                }

                if (FixType == IndexOp.RebuildColumnstoreArchive)
                {
                    compression = DataCompression.ColumnstoreArchive;
                }

                switch (FixType)
                {
                case IndexOp.Rebuild:
                case IndexOp.RebuildColumnstore:
                case IndexOp.RebuildColumnstoreArchive:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REBUILD PARTITION = {partition}\n    " +
                          $"WITH (DATA_COMPRESSION = {compression.ToDescription()}, MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.Reorganize:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REORGANIZE PARTITION = {partition};";
                    break;

                case IndexOp.ReorganizeCompressAllRowGroup:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REORGANIZE PARTITION = {partition}\n    " +
                          "WITH (COMPRESS_ALL_ROW_GROUPS = ON);";
                    break;
                }
            }
            else
            {
                if (FixType == IndexOp.RebuildPage)
                {
                    compression = DataCompression.Page;
                }
                else if (FixType == IndexOp.RebuildRow)
                {
                    compression = DataCompression.Row;
                }
                else if (FixType == IndexOp.RebuildNone)
                {
                    compression = DataCompression.None;
                }

                switch (FixType)
                {
                case IndexOp.CreateIndex:
                    bool isCreateOnline = Settings.ServerInfo.MajorVersion > Server.Sql2008 &&
                                          Settings.ServerInfo.IsOnlineRebuildAvailable &&
                                          Settings.Options.Online;

                    sql = $"CREATE NONCLUSTERED INDEX [{indexName}]\n" +
                          $"ON [{schemaName}].[{objectName}] ({IndexColumns})\n" +
                          (string.IsNullOrEmpty(IncludedColumns) ? "" : $"INCLUDE({IncludedColumns})\n") +
                          $"WITH (SORT_IN_TEMPDB = {(Settings.Options.SortInTempDb ? Options.ON : Options.OFF)}, " +
                          $"ONLINE = {(isCreateOnline ? Options.ON : Options.OFF)}, " +
                          (Settings.Options.FillFactor.IsBetween(1, 100)
                            ? $"FILLFACTOR = {Settings.Options.FillFactor}, "
                            : ""
                          ) +
                          (Settings.Options.DataCompression == Options.DEFAULT
                            ? ""
                            : $"DATA_COMPRESSION = {Settings.Options.DataCompression}, "
                          ) +
                          (Settings.Options.NoRecompute == Options.DEFAULT && !IsPartitioned
                            ? ""
                            : $"STATISTICS_NORECOMPUTE = {Settings.Options.NoRecompute}, "
                          ) +
                          $"MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.Rebuild:
                case IndexOp.RebuildPage:
                case IndexOp.RebuildRow:
                case IndexOp.RebuildNone:
                case IndexOp.RebuildOnline:
                case IndexOp.RebuildFillFactorZero:
                    if (IndexType == IndexType.Heap)
                    {
                        sql = $"ALTER TABLE [{schemaName}].[{objectName}] REBUILD PARTITION = {partition}\n    " +
                              $"WITH (DATA_COMPRESSION = {compression.ToDescription()}, MAXDOP = {Settings.Options.MaxDop});";
                    }
                    else
                    {
                        string onlineRebuild = "OFF";
                        if (FixType == IndexOp.RebuildOnline)
                        {
                            if (Settings.Options.WaitAtLowPriority && Settings.ServerInfo.MajorVersion >= Server.Sql2014)
                            {
                                onlineRebuild = $"ON (" +
                                                $"WAIT_AT_LOW_PRIORITY(MAX_DURATION = {Settings.Options.MaxDuration} MINUTES, " +
                                                $"ABORT_AFTER_WAIT = {Settings.Options.AbortAfterWait}))";
                            }
                            else
                            {
                                onlineRebuild = Options.ON;
                            }
                        }

                        sql = $"ALTER INDEX [{indexName}]\n    " +
                              $"ON [{schemaName}].[{objectName}] REBUILD PARTITION = {partition}\n    " +
                              $"WITH (SORT_IN_TEMPDB = {(Settings.Options.SortInTempDb ? Options.ON : Options.OFF)}, " +
                              $"ONLINE = {onlineRebuild}, " +
                              (Settings.Options.NoRecompute == Options.DEFAULT && !IsPartitioned
                            ? ""
                            : $"STATISTICS_NORECOMPUTE = {Settings.Options.NoRecompute}, "
                              ) +
                              (FixType == IndexOp.RebuildFillFactorZero
                            ? "FILLFACTOR = 100, "
                            : (Settings.Options.FillFactor.IsBetween(1, 100)
                                  ? $"FILLFACTOR = {Settings.Options.FillFactor}, "
                                  : ""
                               )
                              ) +
                              $"DATA_COMPRESSION = {compression.ToDescription()}, " +
                              $"MAXDOP = {Settings.Options.MaxDop});";
                    }
                    break;

                case IndexOp.Reorganize:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REORGANIZE PARTITION = {partition}\n    " +
                          $"WITH (LOB_COMPACTION = {(Settings.Options.LobCompaction ? Options.ON : Options.OFF)});";
                    break;

                case IndexOp.Disable:
                    sql = $"ALTER INDEX [{indexName}] ON [{schemaName}].[{objectName}] DISABLE;";
                    break;

                case IndexOp.Drop:
                    sql = $"DROP INDEX [{indexName}] ON [{schemaName}].[{objectName}];";
                    break;

                case IndexOp.UpdateStatsSample:
                case IndexOp.UpdateStatsResample:
                case IndexOp.UpdateStatsFull:
                    sql = $"UPDATE STATISTICS [{schemaName}].[{objectName}] [{indexName}]\n    " + (
                        FixType == IndexOp.UpdateStatsSample
                    ? $"WITH SAMPLE {Settings.Options.SampleStatsPercent} PERCENT;"
                    : (FixType == IndexOp.UpdateStatsFull ? "WITH FULLSCAN;" : "WITH RESAMPLE;")
                        );
                    break;
                }
            }

            return(sql);
        }
Example #15
0
        public string GetQuery()
        {
            string sql           = string.Empty;
            string indexName     = IndexName.ToQuota();
            string objectName    = $"{SchemaName.ToQuota()}.{ObjectName.ToQuota()}";
            string fullIndexName = $"{indexName} ON {objectName}";
            string partition     = IsPartitioned ? PartitionNumber.ToString() : "ALL";

            if (IsColumnstore)
            {
                switch (FixType)
                {
                case IndexOp.REBUILD:
                case IndexOp.REBUILD_COLUMNSTORE:
                case IndexOp.REBUILD_COLUMNSTORE_ARCHIVE:
                    DataCompression compression = (FixType == IndexOp.REBUILD_COLUMNSTORE) ? DataCompression.COLUMNSTORE : DataCompression.COLUMNSTORE_ARCHIVE;
                    sql = $"ALTER INDEX {fullIndexName} REBUILD PARTITION = {partition}{Environment.NewLine}    " +
                          $"WITH (DATA_COMPRESSION = {(FixType == IndexOp.REBUILD ? DataCompression : compression)}, MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.REORGANIZE:
                case IndexOp.REORGANIZE_COMPRESS_ALL_ROW_GROUPS:
                    sql = $"ALTER INDEX {fullIndexName} REORGANIZE PARTITION = {partition}" +
                          $"{(FixType == IndexOp.REORGANIZE_COMPRESS_ALL_ROW_GROUPS ? $"{Environment.NewLine}    WITH (COMPRESS_ALL_ROW_GROUPS = ON)" : "")};";
                    break;
                }
            }
            else
            {
                switch (FixType)
                {
                case IndexOp.REBUILD:
                case IndexOp.REBUILD_ROW:
                case IndexOp.REBUILD_PAGE:
                case IndexOp.REBUILD_NONE:
                case IndexOp.REBUILD_ONLINE:
                case IndexOp.CREATE_INDEX:

                    DataCompression compression;
                    if (FixType == IndexOp.REBUILD_PAGE)
                    {
                        compression = DataCompression.PAGE;
                    }
                    else if (FixType == IndexOp.REBUILD_ROW)
                    {
                        compression = DataCompression.ROW;
                    }
                    else if (FixType == IndexOp.REBUILD_NONE)
                    {
                        compression = DataCompression.NONE;
                    }
                    else if (Settings.Options.DataCompression != DataCompression.DEFAULT && FixType != IndexOp.REBUILD)
                    {
                        compression = Settings.Options.DataCompression;
                    }
                    else
                    {
                        compression = DataCompression;
                    }

                    string onlineRebuild = "OFF";
                    if (FixType == IndexOp.REBUILD_ONLINE || (Settings.Options.Online && IsAllowOnlineRebuild))
                    {
                        if (Settings.Options.WaitAtLowPriority && Settings.ServerInfo.MajorVersion >= ServerVersion.Sql2014)
                        {
                            onlineRebuild = "ON (" +
                                            $"WAIT_AT_LOW_PRIORITY (MAX_DURATION = {Settings.Options.MaxDuration} MINUTES, " +
                                            $"ABORT_AFTER_WAIT = {Settings.Options.AbortAfterWait}))";
                        }
                        else
                        {
                            onlineRebuild = "ON";
                        }
                    }

                    string sqlHeader;
                    if (IndexType == IndexType.MISSING_INDEX)
                    {
                        sqlHeader = $"CREATE NONCLUSTERED INDEX {fullIndexName}{Environment.NewLine}    ({IndexColumns}){Environment.NewLine}    "
                                    + (string.IsNullOrEmpty(IncludedColumns) ? "" : $"INCLUDE ({IncludedColumns}){Environment.NewLine}    ");
                    }
                    else if (IndexType == IndexType.HEAP)
                    {
                        sqlHeader = $"ALTER TABLE {objectName} REBUILD PARTITION = {partition}{Environment.NewLine}    ";
                    }
                    else
                    {
                        sqlHeader = $"ALTER INDEX {fullIndexName} REBUILD PARTITION = {partition}{Environment.NewLine}    ";
                    }

                    sql = sqlHeader +
                          "WITH (" +
                          (IndexType == IndexType.HEAP
                      ? ""
                      : $"SORT_IN_TEMPDB = {Settings.Options.SortInTempDb.OnOff()}, ") +
                          (IsPartitioned || IndexType == IndexType.HEAP
                      ? ""
                      : $"PAD_INDEX = {Settings.Options.PadIndex.OnOff()}, ") +
                          (IsPartitioned || Settings.Options.FillFactor == 0
                      ? ""
                      : $"FILLFACTOR = {Settings.Options.FillFactor}, ") +
                          (IsPartitioned || Settings.Options.NoRecompute == NoRecompute.DEFAULT || IndexType == IndexType.HEAP
                      ? ""
                      : $"STATISTICS_NORECOMPUTE = {Settings.Options.NoRecompute}, ") +
                          (!IsAllowCompression
                      ? ""
                      : $"DATA_COMPRESSION = {compression}, ") +
                          $"ONLINE = {onlineRebuild}, " +
                          $"MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.REORGANIZE:
                    sql = $"ALTER INDEX {fullIndexName} REORGANIZE PARTITION = {partition}{Environment.NewLine}    " +
                          $"WITH (LOB_COMPACTION = {Settings.Options.LobCompaction.OnOff()});";
                    break;

                case IndexOp.DISABLE_INDEX:
                    sql = $"ALTER INDEX {fullIndexName} DISABLE;";
                    break;

                case IndexOp.DROP_INDEX:
                    sql = $"DROP INDEX {fullIndexName};";
                    break;

                case IndexOp.DROP_TABLE:
                    sql = $"DROP TABLE {objectName};";
                    break;

                case IndexOp.UPDATE_STATISTICS_SAMPLE:
                case IndexOp.UPDATE_STATISTICS_RESAMPLE:
                case IndexOp.UPDATE_STATISTICS_FULL:
                    sql = $"UPDATE STATISTICS {objectName} {indexName}{Environment.NewLine}    " + (
                        FixType == IndexOp.UPDATE_STATISTICS_SAMPLE
                    ? $"WITH SAMPLE {Settings.Options.SampleStatsPercent} PERCENT;"
                    : (FixType == IndexOp.UPDATE_STATISTICS_FULL ? "WITH FULLSCAN;" : "WITH RESAMPLE;")
                        );
                    break;
                }
            }

            return(sql);
        }
Example #16
0
        public IDictionary <string, string> to_token_dictionary()
        {
            var tokens = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { nameof(AfterMigrationFolderName), AfterMigrationFolderName.to_string() },
                { nameof(AlterDatabaseFolderName), AlterDatabaseFolderName.to_string() },
                { nameof(Baseline), Baseline.to_string() },
                { nameof(BeforeMigrationFolderName), BeforeMigrationFolderName.to_string() },
                { nameof(CommandTimeout), CommandTimeout.to_string() },
                { nameof(CommandTimeoutAdmin), CommandTimeoutAdmin.to_string() },
                { nameof(ConfigurationFile), ConfigurationFile.to_string() },
                { nameof(ConnectionString), ConnectionString.to_string() },
                { nameof(ConnectionStringAdmin), ConnectionStringAdmin.to_string() },
                { nameof(CreateDatabaseCustomScript), CreateDatabaseCustomScript.to_string() },
                { nameof(DatabaseName), DatabaseName.to_string() },
                { nameof(DatabaseType), DatabaseType.to_string() },
                { nameof(Debug), Debug.to_string() },
                { nameof(DisableOutput), DisableOutput.to_string() },
                { nameof(DisableTokenReplacement), DisableTokenReplacement.to_string() },
                { nameof(DoNotAlterDatabase), DoNotAlterDatabase.to_string() },
                { nameof(DoNotCreateDatabase), DoNotCreateDatabase.to_string() },
                { nameof(DownFolderName), DownFolderName.to_string() },
                { nameof(Drop), Drop.to_string() },
                { nameof(DryRun), DryRun.to_string() },
#pragma warning disable 618
                { nameof(EnvironmentName), string.Join(",", EnvironmentNames) },
#pragma warning restore 618
                { nameof(EnvironmentNames), string.Join(",", EnvironmentNames) },
                { nameof(FunctionsFolderName), FunctionsFolderName.to_string() },
                { nameof(IndexesFolderName), IndexesFolderName.to_string() },
                { nameof(Initialize), Initialize.to_string() },
                { nameof(OutputPath), OutputPath.to_string() },
                { nameof(PermissionsFolderName), PermissionsFolderName.to_string() },
                { nameof(RecoveryMode), RecoveryMode.to_string() },
                { nameof(RepositoryPath), RepositoryPath.to_string() },
                { nameof(Restore), Restore.to_string() },
                { nameof(RestoreCustomOptions), RestoreCustomOptions.to_string() },
                { nameof(RestoreFromPath), RestoreFromPath.to_string() },
                { nameof(RestoreTimeout), RestoreTimeout.to_string() },
                { nameof(RunAfterCreateDatabaseFolderName), RunAfterCreateDatabaseFolderName.to_string() },
                { nameof(RunAfterOtherAnyTimeScriptsFolderName), RunAfterOtherAnyTimeScriptsFolderName.to_string() },
                { nameof(RunAllAnyTimeScripts), RunAllAnyTimeScripts.to_string() },
                { nameof(RunBeforeUpFolderName), RunBeforeUpFolderName.to_string() },
                { nameof(RunFirstAfterUpFolderName), RunFirstAfterUpFolderName.to_string() },
                { nameof(SchemaName), SchemaName.to_string() },
                { nameof(ScriptsRunErrorsTableName), ScriptsRunErrorsTableName.to_string() },
                { nameof(ScriptsRunTableName), ScriptsRunTableName.to_string() },
                { nameof(SearchAllSubdirectoriesInsteadOfTraverse), SearchAllSubdirectoriesInsteadOfTraverse.to_string() },
                { nameof(ServerName), ServerName.to_string() },
                { nameof(Silent), Silent.to_string() },
                { nameof(SprocsFolderName), SprocsFolderName.to_string() },
                { nameof(SqlFilesDirectory), SqlFilesDirectory.to_string() },
                { nameof(TriggersFolderName), TriggersFolderName.to_string() },
                { nameof(UpFolderName), UpFolderName.to_string() },
                { nameof(Version), Version.to_string() },
                { nameof(VersionFile), VersionFile.to_string() },
                { nameof(VersionTableName), VersionTableName.to_string() },
                { nameof(VersionXPath), VersionXPath.to_string() },
                { nameof(ViewsFolderName), ViewsFolderName.to_string() },
                { nameof(WarnAndIgnoreOnOneTimeScriptChanges), WarnAndIgnoreOnOneTimeScriptChanges.to_string() },
                { nameof(WarnOnOneTimeScriptChanges), WarnOnOneTimeScriptChanges.to_string() },
                { nameof(WithTransaction), WithTransaction.to_string() },
            };

            if (UserTokens != null)
            {
                foreach (var t in UserTokens)
                {
                    tokens[t.Key] = t.Value;
                }
            }

            return(tokens);
        }
Example #17
0
        private FixedSchema ParseFixedType(JObject type, NamedSchema parent)
        {
            var name = type.RequiredProperty<string>(Token.Name);
            var nspace = this.GetNamespace(type, parent, name);
            var fixedName = new SchemaName(name, nspace);

            var size = type.RequiredProperty<int>(Token.Size);
            if (size <= 0)
            {
                throw new SerializationException(
                    string.Format(CultureInfo.InvariantCulture, "Only positive size of fixed values allowed: '{0}'.", size));
            }

            var aliases = this.GetAliases(type, fixedName.Namespace);
            var attributes = new NamedEntityAttributes(fixedName, aliases, string.Empty);

            var customAttributes = type.GetAttributesNotIn(StandardProperties.Record);
            var result = new FixedSchema(attributes, size, typeof(byte[]), customAttributes);
            return result;
        }
Example #18
0
 public static SqlPreCommandSimple AlterSchema(ObjectName oldName, SchemaName schemaName)
 {
     return new SqlPreCommandSimple("ALTER SCHEMA {0} TRANSFER {1};".Formato(schemaName.Name.SqlEscape(), oldName));
 }
Example #19
0
 private static void SetSchemaNames(Schema schema)
 {
     foreach (var gr in schema.Tables.Values.GroupBy(a => GetSchemaName(a)))
     {
         if (gr.Key != null)
         {
             SchemaName sn = new SchemaName(null, gr.Key);
             foreach (var t in gr)
                 t.ToSchema(sn);
         }
     }
 }
Example #20
0
        public string testFullname(string s1, string s2)
        {
            var name = new SchemaName(s1, s2, null, null);

            return(name.Fullname);
        }
Example #21
0
 internal static SqlPreCommandSimple SP_RENAME(SchemaName schema, string oldName, string newName, string objectType)
 {
     return new SqlPreCommandSimple("EXEC {0}SP_RENAME '{1}' , '{2}'{3}".Formato(
         schema.IsDefault() ? null : schema.ToString() + ".",
         oldName,
         newName,
         objectType == null ? null : ", '{0}'".Formato(objectType)
         ));
 }
Example #22
0
 public static SqlPreCommand CreateSchema(SchemaName schemaName)
 {
     return new SqlPreCommandSimple("CREATE SCHEMA {0}".FormatWith(schemaName)) { GoAfter = true, GoBefore = true };
 }
Example #23
0
 public static SqlPreCommand CreateSchema(SchemaName schemaName)
 {
     return new SqlPreCommandSimple("CREATE SCHEMA {0}".Formato(schemaName));
 }
Example #24
0
 public static SqlPreCommand DropSchema(SchemaName schemaName)
 {
     return new SqlPreCommandSimple("DROP SCHEMA {0}".FormatWith(schemaName)) { GoAfter = true, GoBefore = true };
 }
 /// <summary>
 /// Gets the name of the schema.
 /// </summary>
 /// <param name="dbName">Name of the db.</param>
 /// <param name="extraction">The extraction.</param>
 /// <param name="nameFormat">The name format.</param>
 /// <returns></returns>
 public SchemaName GetSchemaName(string dbName, WordsExtraction extraction, NameFormat nameFormat)
 {
     var words = GetLanguageWords(nameFormat.Culture);
     var schemaName = new SchemaName { DbName = dbName };
     schemaName.NameWords = ExtractWords(words, dbName, extraction);
     schemaName.ClassName = Format(words, schemaName.NameWords, nameFormat.Case, Singularization.DontChange);
     return schemaName;
 }
 private NamedEntityAttributes GetNamedEntityAttributesFrom(Type type)
 {
     AvroContractResolver resolver = this.settings.Resolver;
     TypeSerializationInfo typeInfo = resolver.ResolveType(type);
     var name = new SchemaName(typeInfo.Name, typeInfo.Namespace);
     var aliases = typeInfo
         .Aliases
         .Select(alias => string.IsNullOrEmpty(name.Namespace) || alias.Contains(".") ? alias : name.Namespace + "." + alias)
         .ToList();
     return new NamedEntityAttributes(name, aliases, typeInfo.Doc);
 }
Example #27
0
 public void ToSchema(SchemaName schemaName)
 {
     this.Name = this.Name.OnSchema(schemaName);
 }
        /// <summary>
        /// Generates the record type schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="schemas">The schemas.</param>
        /// <param name="currentDepth">The current depth.</param>
        /// <returns>
        /// Instance of schema.
        /// </returns>
        private TypeSchema BuildRecordTypeSchema(Type type, Dictionary<string, NamedSchema> schemas, uint currentDepth)
        {
            if (type == typeof(DateTimeOffset))
            {
                return this.settings.UsePosixTime
                    ? (TypeSchema)new LongSchema(type)
                    : new StringSchema(type);
            }

            NamedSchema schema;
            if (schemas.TryGetValue(type.ToString(), out schema))
            {
                return schema;
            }

            if (type == typeof(Guid))
            {
                var recordName = new SchemaName(type.GetStrippedFullName());
                var attributes = new NamedEntityAttributes(recordName, new List<string>(), string.Empty);
                var result = new FixedSchema(attributes, 16, type);
                schemas.Add(type.ToString(), result);
                return result;
            }

            var attr = this.GetNamedEntityAttributesFrom(type);
            AvroContractResolver resolver = this.settings.Resolver;
            var record = new RecordSchema(
                attr,
                type);
            schemas.Add(type.ToString(), record);

            var members = resolver.ResolveMembers(type);
            this.AddRecordFields(members, schemas, currentDepth, record);
            return record;
        }