internal override string Alter(ItemComparable target, InterItemCommunication communication)
        {
            StringBuilder alter = new StringBuilder();

            AddTypeModification(alter, target);
            AddNullableModification(alter, target);
            AddDefaultModification(alter, target);
            AddIdentityGenerationModification(alter, target);
            return(alter.ToString());
        }
        private void AddDefaultModification(StringBuilder alter, ItemComparable target)
        {
            var targetGoodType = target as Column;

            if (targetGoodType.DefautValue != "null" && DefautValue == "null")
            {
                alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} DROP DEFAULT;");
            }
            else if (targetGoodType.DefautValue != DefautValue)
            {
                alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} SET DEFAULT {DefautValue};");
            }
        }
        private void AddNullableModification(StringBuilder alter, ItemComparable target)
        {
            var targetGoodType = target as Column;

            if (IsNullable != targetGoodType.IsNullable)
            {
                if (IsNullable)
                {
                    alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} DROP NOT NULL;");
                }
                else
                {
                    alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} SET NOT NULL;");
                }
            }
        }
        private void AddIdentityGenerationModification(StringBuilder alter, ItemComparable target)
        {
            var targetGoodType = target as Column;

            if (targetGoodType.IdentityGeneration == "null" && IdentityGeneration != "null")
            {
                alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} ADD  GENERATED  {IdentityGeneration} AS IDENTITY;");
            }
            else if (targetGoodType.IdentityGeneration != IdentityGeneration)
            {
                alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} SET GENERATED  {IdentityGeneration};");
            }
            else if (targetGoodType.IdentityGeneration != "null" && IdentityGeneration == "null")
            {
                alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} DROP IDENTITY;");
            }
        }
        internal override string Alter(ItemComparable target, InterItemCommunication communication)
        {
            string alter = string.Empty;

            var optionsTarget = target.GenerateOptions();
            var options       = GenerateOptions();

            if (options != optionsTarget)
            {
                alter = $"CREATE ROLE {Name} {options};";
            }

            if (this["memberof"] != target["memberof"])
            {
                alter += GenerateMemberOfDifference(target);
            }
            return(alter);
        }
        private string GenerateMemberOfDifference(ItemComparable target)
        {
            StringBuilder difference = new StringBuilder();
            List <string> sourceList = GetRightsList(this["memberof"]);
            List <string> targetList = GetRightsList(target["memberof"]);

            sourceList
            .Where(x => !targetList.Any(y => x == y))
            .ToList()
            .ForEach(x => difference.AppendLine($"REVOKE {x} FROM {Name};"));

            targetList
            .Where(x => !sourceList.Any(y => x == y))
            .ToList()
            .ForEach(x => difference.AppendLine($"GRANT {x} TO {Name};"));

            return(difference.ToString());
        }
Exemple #7
0
        internal override string Alter(ItemComparable target, InterItemCommunication communication)
        {
            string alter          = "";
            var    goodTypeTarget = target as Index;

            if (Definition == "null")
            {
                return($"--Error on index definition {Key()}");
            }
            if (goodTypeTarget.Definition == "null")
            {
                return($"--Error on index definition {goodTypeTarget.Key()}");
            }
            alter  = Drop(communication);
            alter += ";" + Environment.NewLine;
            alter += Create(communication);

            return(alter);
        }
        private void AddTypeModification(StringBuilder alter, ItemComparable target)
        {
            var targetGoodType = target as Column;

            if (ElementType == target.ElementType)
            {
                if (ElementType == "character varying" && MaximumLength != targetGoodType.MaximumLength)
                {
                    if (MaximumLength < targetGoodType.MaximumLength)
                    {
                        alter.AppendLine("--!!! Truncation will occur !!!");
                    }
                    alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} TYPE {TypeStringFromElementType};");
                }
                //ELSE ???
            }
            else
            {
                alter.AppendLine($"ALTER TABLE {TableName} ALTER COLUMN {Name} TYPE {TypeStringFromElementType};");
            }
        }
Exemple #9
0
 internal override string Alter(ItemComparable target, InterItemCommunication communication)
 {
     return(Drop(communication) + ";" + Environment.NewLine + Create(communication));
 }
 internal virtual string Alter(ItemComparable target, InterItemCommunication communication)
 {
     throw new NotImplementedException();
 }