sebastienros / yessql

A .NET document database working on any RDBMS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The 'modify' keyword is not supported in postgres

hyzx86 opened this issue · comments

I don't understand what this code does. Why compare lengths?

builder.AppendFormat("alter table {0} modify column {1} ",
_dialect.QuoteForTableName(command.Name, _configuration.Schema),
_dialect.QuoteForColumnName(command.ColumnName)
);
var initLength = builder.Length;

#244 (comment)

         SchemaBuilder.AlterIndexTable<AuditTrailEventIndex>(table => table
                        .AlterColumn(nameof(AuditTrailEventIndex.CorrelationId),
                            column => column.WithType(typeof(string), 255)),
                    collection: AuditTrailEvent.Collection
                );
Error while running migration version 0 for 'EasyOC.AuditTrail'. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "modify"

POSITION: 42
   at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|221_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in /_/Dapper/SqlMapper.cs:line 2848
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in /_/Dapper/SqlMapper.cs:line 581
   at YesSql.Sql.SchemaBuilder.Execute(IEnumerable`1 statements)
   at YesSql.Sql.SchemaBuilder.AlterTable(String name, Action`1 table)
   at YesSql.Sql.SchemaBuilder.AlterIndexTable(Type indexType, Action`1 table, String collection)
   at EasyOC.AuditTrail.Migrations.UpdateAuditTrailMigrations.Create() in D:\SourceCodes\JZSoft\EasyOC.OrchardCore\EasyOC\src\Modules\EasyOC.AuditTrail\Migrations\UpdateAuditTrailMigrations.cs:line 30
  Exception data:
    Severity: ERROR
    SqlState: 42601
    MessageText: syntax error at or near "modify"
    Position: 42
    File: scan.l
    Line: 1133
    Routine: scanner_yyerror
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId)    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at OrchardCore.Data.Migration.DataMigrationManager.UpdateAsync(String featureId)

Use Alter Column instead

https://www.postgresql.org/docs/current/sql-altertable.html

Yes, This is the code I'm using now

image

This kind of problem seems very difficult to cover completely, can pass
Could you consider using other components to implement table structure migration?
For example:
https://github.com/fluentmigrator/fluentmigrator

My assumption based on the first comment

@hishamco
So you think modify should be changed to alter
but why are there two cases , alter and modify ?

@sebastienros Can you help me look at this problem? thanks!

Could you point to the two cases? Also, modify your PR according to Seb comment

Could you point to the two cases? Also, modify your PR according to Seb comment

Ok, but I've been very busy lately. Lots of concurrent projects ~ My work is already scheduled after May 10th ~

This unit test shouldn't be difficult, it'll just take a little bit of time

If you don't have a time I can create a PR instead

@hishamco Sure, I've closed my PR

Please leave it open until I create my PR or complete yours :)

Please leave it open until I create my PR or complete yours :)

it doesn't matter I only changed one word