jjn1056 / DBIx-Class-Migration

Use DBIC::DeploymentHandler and DBIC::Fixtures together for a sane database versioning workflow
33 stars 41 forks source link

respect UTF8 #108

Closed KES777 closed 5 years ago

KES777 commented 6 years ago

If my Result/Table.pm looks like:

use utf8;
...
sub sqlt_deploy_hook {
        my( $self, $sqlt_table ) =  @_;

        my $sqlt =  $sqlt_table->schema;
        $sqlt->add_procedure(()
                ,name =>  'ch_saldo'
                ....
                ,extra =>  {()
                        ,returns =>  { type => 'VOID' }
                        ,definitions =>  [()
                                ,{ language  =>  'plpgsql'  }
                                ,{ attribute =>  'VOLATILE' }
                                ,{ quote => "\$\$\n",  body => <<'      FUNC' =~ s!^\t\t!  !grm  =~
                /*Только суммарный учёт по счёту*/
                DECLARE _YearFrom  smallint;
                DECLARE _YearTo    smallint;

When I run prepare command I get migration script with broken comments:

CREATE FUNCTION "ch_saldo" (in _DocDate DATE, in _Schet TBuhSchet, in _Suma TMoney)
 RETURNS VOID
 LANGUAGE plpgsql
 VOLATILE
 AS $$
  /*Только суммарный учёт по счёту*/
  DECLARE _YearFrom  smallint;/**/
  DECLARE _YearTo    smallint;/**/
KES777 commented 6 years ago

This happen only on project where Result classes use Moose. On project without Moose this does not happen.

KES777 commented 6 years ago

A few more information on this.

I set breakpoint at /DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm:500 when downgrade script is generated.

  >>500:   return [SQL::Translator::Diff::schema_diff(
    501:      $source_schema, $db,
    502:      $dest_schema,   $db,
    503:      { producer_args => $sqltargs }
    504:   )];

One interesting fact that same method from same file is different for $source_schema VS $dest_schema.

$dest_schema:

    ch_saldo => SQL::Translator::Schema::Procedure {
      _ERROR => ,
      comments => [
        ,
      ],
      extra => {
        definitions => [
          {
            language => plpgsql,
          },
          {
            attribute => VOLATILE,
          },
          {
            body =>   /*Только суммарный учёт по счёту*/
  DECLARE _YearFrom  smallint;/**/
  DECLARE _YearTo    smallint;/**/
  DECLARE _MonthFrom smallint;/**/
  DECLARE _MonthTo   smallint;/**/

$source_schema:

    ch_saldo => SQL::Translator::Schema::Procedure {
      _ERROR => ,
      comments => [
        ,
      ],
      extra => {
        definitions => [
          {
            language => plpgsql,
          },
          {
            attribute => VOLATILE,
          },
          {
            body =>   /*Только суммарный учёт по счёту*/
  DECLARE _YearFrom  smallint;/**/
  DECLARE _YearTo    smallint;/**/
  DECLARE _MonthFrom smallint;/**/
  DECLARE _MonthTo   smallint;/**/

As you can see $dest_schema is not UTF8 decoded

It is worth to mention that SQL added by sub sqlt_deploy_hook { called from App::Schema in both cases: for $source and $dest is both decoded correctly. All files: App::Schema and ::Result package both have use utf8 I use this patch which adds stored procedures: https://github.com/dbsrgits/sql-translator/issues/82

mohawk2 commented 5 years ago

This is a bug (which I agree, an actual bug) in either DBICDH or, more likely, SQLT. It needs reporting there. This module cannot fix it.