Skip Menu |

This queue is for tickets about the DBIx-Class-Schema-Loader CPAN distribution.

Report information
The Basics
Id: 92300
Status: resolved
Priority: 0/
Queue: DBIx-Class-Schema-Loader

People
Owner: Nobody in particular
Requestors: des [...] des.no
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.07040



Subject: Omit variable data from signature comment
When generating source code with make_schema_at(), it would be nice to have an option to omit the version number and timestamp from the signature comment so that the only changes between consecutive runs are functional ones.
From: des [...] des.no
I may have accidentally created a patch. (I tried to follow the existing code style, particularly with respect to indentation. I noticed that there are a few lines in Base.pm which use tabs instead of spaces, but did not correct them.)
Subject: omit-version-timestamp.diff
--- a/DBIx/Class/Schema/Loader/Base.pm +++ b/DBIx/Class/Schema/Loader/Base.pm @@ -61,6 +61,8 @@ use_moose only_autoclean overwrite_modifications + omit_version + omit_timestamp relationship_attrs @@ -853,6 +855,14 @@ Again, you should be using version control on your schema classes. Be careful with this option. +=head2 omit_version + +Omit the package version from the signature comment. + +=head2 omit_timestamp + +Omit the creation timestamp from the signature comment. + =head2 custom_column_info Hook for adding extra attributes to the @@ -2013,8 +2023,8 @@ sub _sig_comment { my ($self, $version, $ts) = @_; return qq|\n\n# Created by DBIx::Class::Schema::Loader| - . qq| v| . $version - . q| @ | . $ts + . (defined($version) ? q| v| . $version : '') + . (defined($ts) ? q| @ | . $ts : '') . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|; } @@ -2132,8 +2142,8 @@ } $text .= $self->_sig_comment( - $self->version_to_dump, - POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) + $self->omit_version ? undef : $self->version_to_dump, + $self->omit_timestamp ? undef : POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) ); open(my $fh, '>:encoding(UTF-8)', $filename) @@ -2192,7 +2202,9 @@ $md5 = $2; # Pull out the version and timestamp from the line above - ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)\r?\Z/m; + ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader( v.*)?( @ .*)?\r?\Z/m; + $ver =~ s/^ v// if $ver; + $ts =~ s/^ @ // if $ts; $gen .= $pre_md5; croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n"
CC: undisclosed-recipients:;
Subject: Re: [rt.cpan.org #92300] Omit variable data from signature comment
Date: Sun, 26 Jan 2014 21:01:12 +0100
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
"Dag-Erling Smørgrav via RT" <bug-DBIx-Class-Schema-Loader@rt.cpan.org> writes: Show quoted text
> When generating source code with make_schema_at(), it would be nice to > have an option to omit the version number and timestamp from the > signature comment so that the only changes between consecutive runs > are functional ones.
Except for the schema class, it already skips updating the version, timestamp and checksum if that would have been the only change (i.e. there were no changes to the generated code). Is this not sufficient? https://metacpan.org/source/ILMARI/DBIx-Class-Schema-Loader-0.07039/lib/DBIx/Class/Schema/Loader/Base.pm#L2142 -- "The surreality of the universe tends towards a maximum" -- Skud's Law "Never formulate a law or axiom that you're not prepared to live with the consequences of." -- Skud's Meta-Law
Subject: Re: [rt.cpan.org #92300] Omit variable data from signature comment
Date: Mon, 27 Jan 2014 09:36:25 +0100
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Dag-Erling Smørgrav <des [...] des.no>
"Dagfinn Ilmari Mannsåker via RT" <bug-DBIx-Class-Schema-Loader@rt.cpan.org> writes: Show quoted text
> Except for the schema class, it already skips updating the version, > timestamp and checksum if that would have been the only change > (i.e. there were no changes to the generated code). Is this not > sufficient?
I want to skip the version and timestamp even when there *are* functional changes, so the output is 100% reproducable. DES -- Dag-Erling Smørgrav - des@des.no
CC: undisclosed-recipients:;
Subject: Re: [rt.cpan.org #92300] Omit variable data from signature comment
Date: Wed, 05 Feb 2014 23:22:14 +0100
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
"Dag-Erling Smørgrav via RT" <bug-DBIx-Class-Schema-Loader@rt.cpan.org> writes: Show quoted text
> I want to skip the version and timestamp even when there *are* > functional changes, so the output is 100% reproducable.
Fair enough, I can see the utility of that. However, the patch no longer applies to git master, and doesn't include any tests. Could you please rebase it onto master (or the 0.07039 release) and add some tests to t/23dumpmore.t? You can find the repository at git://git.shadowcat.co.uk/dbsrgits/DBIx-Class-Schema-Loader.git or, if you prefer github, https://github.com/dbsrgits/dbix-class-schema-loader/ -- "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen
From: des [...] des.no
Here's an updated patch. I'll submit the tests separately.
Subject: DBIx-Class-Schema-Loader-omit-version-timestamp.patch
diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index cbf72d8..e513dca 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -63,6 +63,8 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ overwrite_modifications dry_run generated_classes + omit_version + omit_timestamp relationship_attrs @@ -860,6 +862,14 @@ made to Loader-generated code. Again, you should be using version control on your schema classes. Be careful with this option. +=head2 omit_version + +Omit the package version from the signature comment. + +=head2 omit_timestamp + +Omit the creation timestamp from the signature comment. + =head2 custom_column_info Hook for adding extra attributes to the @@ -2031,8 +2041,8 @@ sub _dump_to_dir { sub _sig_comment { my ($self, $version, $ts) = @_; return qq|\n\n# Created by DBIx::Class::Schema::Loader| - . qq| v| . $version - . q| @ | . $ts + . (defined($version) ? q| v| . $version : '') + . (defined($ts) ? q| @ | . $ts : '') . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|; } @@ -2154,8 +2164,8 @@ sub _write_classfile { return if $self->dry_run; $text .= $self->_sig_comment( - $self->version_to_dump, - POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) + $self->omit_version ? undef : $self->version_to_dump, + $self->omit_timestamp ? undef : POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) ); open(my $fh, '>:encoding(UTF-8)', $filename) @@ -2214,7 +2224,9 @@ sub _parse_generated_file { $md5 = $2; # Pull out the version and timestamp from the line above - ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)\r?\Z/m; + ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader( v.*)?( @ .*)?\r?\Z/m; + $ver =~ s/^ v// if $ver; + $ts =~ s/^ @ // if $ts; $gen .= $pre_md5; croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n"
From: des [...] des.no
Here is an updated patch with tests for both options separately and together. The previous version broke the backcompat tests because the regexp used to extract the version and timestamp in _parse_generated_file() was sloppy. I tightened the regexp and the code now passes all tests. I have also verified that the unmodified code fails the added tests. See also http://blog.des.no/?s=on+testing - I should learn to take my own advice :)
Subject: DBIx-Class-Schema-Loader-omit-version-timestamp.patch
diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index cbf72d8..5fb8649 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -63,6 +63,8 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ overwrite_modifications dry_run generated_classes + omit_version + omit_timestamp relationship_attrs @@ -860,6 +862,14 @@ made to Loader-generated code. Again, you should be using version control on your schema classes. Be careful with this option. +=head2 omit_version + +Omit the package version from the signature comment. + +=head2 omit_timestamp + +Omit the creation timestamp from the signature comment. + =head2 custom_column_info Hook for adding extra attributes to the @@ -2031,8 +2041,8 @@ sub _dump_to_dir { sub _sig_comment { my ($self, $version, $ts) = @_; return qq|\n\n# Created by DBIx::Class::Schema::Loader| - . qq| v| . $version - . q| @ | . $ts + . (defined($version) ? q| v| . $version : '') + . (defined($ts) ? q| @ | . $ts : '') . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|; } @@ -2154,8 +2164,8 @@ sub _write_classfile { return if $self->dry_run; $text .= $self->_sig_comment( - $self->version_to_dump, - POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) + $self->omit_version ? undef : $self->version_to_dump, + $self->omit_timestamp ? undef : POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) ); open(my $fh, '>:encoding(UTF-8)', $filename) @@ -2214,7 +2224,9 @@ sub _parse_generated_file { $md5 = $2; # Pull out the version and timestamp from the line above - ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)\r?\Z/m; + ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader( v[\d.]+)?( @ [\d-]+ [\d:]+)?\r?\Z/m; + $ver =~ s/^ v// if $ver; + $ts =~ s/^ @ // if $ts; $gen .= $pre_md5; croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n" diff --git a/t/23dumpmore.t b/t/23dumpmore.t index 47364f5..dd52596 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -599,5 +599,46 @@ ok( !-e $schema_file, "dry-run doesn't create file for schema class" ); (my $schema_dir = $schema_file) =~ s/\.pm\z//; ok( !-e $schema_dir, "dry-run doesn't create subdirectory for schema namespace" ); +# test omit_version (RT#92300) +$t->dump_test( + classname => 'DBICTest::DumpMore::omit_version', + options => { + omit_version => 1, + }, + regexes => { + Foo => [ + qr/^\# Created by DBIx::Class::Schema::Loader @ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/m, + ], + }, +); + +# test omit_timestamp (RT#92300) +$t->dump_test( + classname => 'DBICTest::DumpMore::omit_timestamp', + options => { + omit_timestamp => 1, + }, + regexes => { + Foo => [ + qr/^\# Created by DBIx::Class::Schema::Loader v[\d.]+$/m, + ], + }, +); + +# test omit_version and omit_timestamp simultaneously (RT#92300) +$t->dump_test( + classname => 'DBICTest::DumpMore::omit_both', + options => { + omit_version => 1, + omit_timestamp => 1, + }, + # A positive regex here would match the top comment + neg_regexes => { + Foo => [ + qr/^\# Created by DBIx::Class::Schema::Loader.+$/m, + ], + }, +); + done_testing; # vim:et sts=4 sw=4 tw=0:
Thanks for the updated patch and tests. I've commited it to master (with a minor whitespace fix), and it'll be in the next release.
The fix is included in 0.07040, now available on CPAN.