コード例 #1
0
        public static async Task <bool> CreateColumnAsync(this ITableTemplate template, Authentication authentication)
        {
            var columnName = RandomUtility.NextIdentifier();

            if (await template.ContainsAsync(columnName) == true)
            {
                return(false);
            }

            var column = await template.AddNewAsync(authentication);

            await column.SetNameAsync(authentication, columnName);

            if (template.PrimaryKey.Any() == false)
            {
                await column.SetIsKeyAsync(authentication, true);
            }
            else if (template.Count == 0 && RandomUtility.Within(10))
            {
                await column.SetIsKeyAsync(authentication, true);

                await column.SetIsUniqueAsync(authentication, RandomUtility.Within(75));
            }

            if (RandomUtility.Within(75) == true)
            {
                await column.SetTagsAsync(authentication, TagInfo.All);
            }
            else
            {
                await column.SetTagsAsync(authentication, tags.Random());
            }

            if (RandomUtility.Within(75) == true)
            {
                await column.SetDataTypeAsync(authentication, CremaDataTypeUtility.GetBaseTypeNames().Random());
            }
            else
            {
                await column.SetDataTypeAsync(authentication, template.SelectableTypes.Random());
            }

            if (RandomUtility.Within(25) == true)
            {
                await column.SetCommentAsync(authentication, RandomUtility.NextString());
            }

            if (CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == true)
            {
                await column.SetAutoIncrementAsync(authentication, RandomUtility.NextBoolean());
            }

            try
            {
                await template.EndNewAsync(authentication, column);
            }
            catch
            {
                return(false);
            }
            return(true);
        }