Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Data;
using DotNetProjects.Migrator.Framework;
using NUnit.Framework;

namespace Migrator.Tests.Providers.PostgreSQL;

[TestFixture]
[Category("Postgre")]
public class PostgreSQLTransformationProvider_GetColumnContentSizeTests : PostgreSQLTransformationProviderTestBase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the file name be the same as the class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix that in the next PR.

{
[Test]
public void GetColumnContentSize_DefaultValues_Succeeds()
{
// Arrange
const string testTableName = "testtable";

const string stringColumnName = "stringcolumn";

Provider.AddTable(testTableName,
new Column(stringColumnName, DbType.String, 5000)
);

Provider.Insert(testTableName, [stringColumnName], [new string('A', 44)]);
Provider.Insert(testTableName, [stringColumnName], [new string('B', 444)]);
Provider.Insert(testTableName, [stringColumnName], [new string('C', 4444)]);

// Act
var columnContentSize = Provider.GetColumnContentSize(testTableName, stringColumnName);

// Assert
Assert.That(columnContentSize, Is.EqualTo(4444));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@
{
var oldColumn = GetColumnByName(table, column.Name);

var isUniqueSet = column.ColumnProperty.IsSet(ColumnProperty.Unique);

Check warning on line 175 in src/Migrator/Providers/Impl/PostgreSQL/PostgreSQLTransformationProvider.cs

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.Unique' is obsolete: 'Use method 'AddUniqueConstraint' instead. This is marked being obsolete since you cannot add a name for the constraint which makes it difficult to remove the constraint again.'

column.ColumnProperty = column.ColumnProperty.Clear(ColumnProperty.Unique);

Check warning on line 177 in src/Migrator/Providers/Impl/PostgreSQL/PostgreSQLTransformationProvider.cs

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.Unique' is obsolete: 'Use method 'AddUniqueConstraint' instead. This is marked being obsolete since you cannot add a name for the constraint which makes it difficult to remove the constraint again.'

var mapper = _dialect.GetAndMapColumnProperties(column);

Expand Down Expand Up @@ -249,6 +249,18 @@
return tables.ToArray();
}

public override int GetColumnContentSize(string table, string columnName)
{
var result = ExecuteScalar($"SELECT MAX(LENGTH({QuoteColumnNameIfRequired(columnName)})) FROM {QuoteTableNameIfRequired(table)}");

if (result == DBNull.Value)
{
return 0;
}

return Convert.ToInt32(result);
}

public override Column[] GetColumns(string table)
{
var stringBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ FROM sys.[indexes] Ind

if (!reader.IsDBNull(6))
{
idx.KeyColumns = (reader.GetString(6).Split(','));
idx.KeyColumns = reader.GetString(6).Split(',');
}
if (!reader.IsDBNull(7))
{
idx.IncludeColumns = (reader.GetString(7).Split(','));
idx.IncludeColumns = reader.GetString(7).Split(',');
}

retVal.Add(idx);
Expand All @@ -293,7 +293,7 @@ FROM sys.[indexes] Ind

public override int GetColumnContentSize(string table, string columnName)
{
var result = this.ExecuteScalar("SELECT MAX(LEN(" + this.QuoteColumnNameIfRequired(columnName) + ")) FROM " + this.QuoteTableNameIfRequired(table));
var result = ExecuteScalar("SELECT MAX(LEN(" + this.QuoteColumnNameIfRequired(columnName) + ")) FROM " + this.QuoteTableNameIfRequired(table));

if (result == DBNull.Value)
{
Expand Down
Loading