Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simplification Renderer->columnOptions output for datetime now #33

Merged
merged 6 commits into from Mar 10, 2022

Conversation

aquaminer
Copy link
Contributor

Before

            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => \Cycle\Database\Injection\Fragment::__set_state(array(
               'fragment' => 'now()',
               'parameters' =>
              array (
                ),
                ))
            ])

After

            ->addColumn('created_at', 'datetime', [
                'nullable' => false,
                'default'  => 'CURRENT_TIMESTAMP'
               )
            ])

CURRENT_TIMESTAMP will be translated for postgresql to now() in AbstractColumn (cycle/database)

@roxblnfk roxblnfk requested a review from msmakouz March 9, 2022 12:17
@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #33 (f631067) into 3.x (91f6f3e) will decrease coverage by 0.32%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x      #33      +/-   ##
============================================
- Coverage     95.91%   95.59%   -0.33%     
- Complexity      246      248       +2     
============================================
  Files            29       29              
  Lines           784      726      -58     
============================================
- Hits            752      694      -58     
  Misses           32       32              
Impacted Files Coverage Δ
src/Atomizer/Renderer.php 100.00% <100.00%> (ø)
src/Migrator.php 83.73% <0.00%> (-0.27%) ⬇️
src/Capsule.php 100.00% <0.00%> (ø)
src/FileRepository.php 100.00% <0.00%> (ø)
src/Operation/Column/Rename.php 100.00% <0.00%> (ø)
src/Operation/ForeignKey/Add.php 100.00% <0.00%> (ø)
src/Operation/ForeignKey/Drop.php 100.00% <0.00%> (ø)
src/Operation/ForeignKey/Alter.php 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91f6f3e...f631067. Read the comment docs.

@@ -401,6 +401,10 @@ private function columnOptions(Serializer $serializer, AbstractColumn $column):
$options['precision'] = $column->getPrecision();
}

if ($options['default'] == $column::DATETIME_NOW) {
Copy link
Member

Choose a reason for hiding this comment

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

I recommend adding a strict comparison here (===).

It might be worth adding a test with new functionality. What do you think? @roxblnfk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if use strict comparison here, before/after example don't be work (because Fragment does not converted to string).

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it is better to check the type, cast to the needed type, and compare? If it doesn't add a lot of code.

@aquaminer
Copy link
Contributor Author

i don't have ideas for testing this functionality. Poor test ⬆️

src/Atomizer/Renderer.php Outdated Show resolved Hide resolved
aquaminer and others added 2 commits March 10, 2022 17:06
Co-authored-by: Aleksei Gagarin <roxblnfk@ya.ru>
@roxblnfk roxblnfk added this to the 3.1.x milestone Mar 10, 2022
@roxblnfk roxblnfk merged commit a4269da into cycle:3.x Mar 10, 2022
@roxblnfk
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants