/// <summary>
        /// Parses COMMENT ON INDEX.
        /// </summary>
        private static void ParseIndex(Parser parser, PgDatabase database)
        {
            var indexName = parser.ParseIdentifier();

            var objectName = ParserUtils.GetObjectName(indexName);

            var schemaName = ParserUtils.GetSchemaName(indexName, database);

            if (database.SchemaIsIgnored(schemaName))
            {
                return;
            }

            PgSchema schema = database.GetSchema(schemaName);

            PgIndex index = schema.GetIndex(objectName);

            if (index == null)
            {
                PgConstraint primaryKey = schema.GetPrimaryKey(objectName);
                parser.Expect("IS");
                primaryKey.Comment = GetComment(parser);
                parser.Expect(";");
            }
            else
            {
                parser.Expect("IS");
                index.Comment = GetComment(parser);
                parser.Expect(";");
            }
        }
Esempio n. 2
0
        public static void AlterComments(TextWriter writer, PgSchema oldSchema, PgSchema newSchema, SearchPathHelper searchPathHelper)
        {
            if (oldSchema == null)
            {
                return;
            }

            foreach (var oldIndex in oldSchema.GetIndexes())
            {
                var newIndex = newSchema.GetIndex(oldIndex.Name);

                if (newIndex == null)
                {
                    continue;
                }

                if (oldIndex.Comment == null &&
                    newIndex.Comment != null ||
                    oldIndex.Comment != null &&
                    newIndex.Comment != null &&
                    !oldIndex.Comment.Equals(
                        newIndex.Comment))
                {
                    searchPathHelper.OutputSearchPath(writer);
                    writer.WriteLine();
                    writer.Write("COMMENT ON INDEX ");
                    writer.Write(PgDiffUtils.GetQuotedName(newIndex.Name));
                    writer.Write(" IS ");
                    writer.Write(newIndex.Comment);
                    writer.WriteLine(';');
                }
                else if (oldIndex.Comment != null && newIndex.Comment == null)
                {
                    searchPathHelper.OutputSearchPath(writer);
                    writer.WriteLine();
                    writer.Write("COMMENT ON INDEX ");
                    writer.Write(PgDiffUtils.GetQuotedName(newIndex.Name));
                    writer.WriteLine(" IS NULL;");
                }
            }
        }
        /// <summary>
        /// Outputs statements for index comments that have changed.
        /// </summary>
        public static void AlterComments(StreamWriter writer, [NullGuard.AllowNull] PgSchema oldSchema, PgSchema newSchema, SearchPathHelper searchPathHelper)
        {
            if (oldSchema == null)
            {
                return;
            }

            foreach (PgIndex oldIndex in oldSchema.Indexes)
            {
                PgIndex newIndex = newSchema.GetIndex(oldIndex.Name);

                if (newIndex == null)
                {
                    continue;
                }

                if ((oldIndex.Comment == null && newIndex.Comment != null) ||
                    (oldIndex.Comment != null &&
                     newIndex.Comment != null &&
                     !oldIndex.Comment.Equals(newIndex.Comment)))
                {
                    searchPathHelper.OutputSearchPath(writer);
                    writer.WriteLine();
                    writer.Write("COMMENT ON INDEX ");
                    writer.Write(PgDiffStringExtension.QuoteName(newIndex.Name));
                    writer.Write(" IS ");
                    writer.Write(newIndex.Comment);
                    writer.WriteLine(';');
                }
                else if (oldIndex.Comment != null && newIndex.Comment == null)
                {
                    searchPathHelper.OutputSearchPath(writer);
                    writer.WriteLine();
                    writer.Write("COMMENT ON INDEX ");
                    writer.Write(PgDiffStringExtension.QuoteName(newIndex.Name));
                    writer.WriteLine(" IS NULL;");
                }
            }
        }