Skip to content

Add created_at and created_by columns to series_sales table. #483

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

Closed
wants to merge 1 commit into from

Conversation

cssru
Copy link
Contributor

@cssru cssru commented Sep 28, 2016

Add created_at and created_by columns to series_sales table and fill them with default values.

Addressed to #469

@cssru cssru force-pushed the gh469_add_created_to_sales branch 4 times, most recently from 1b23161 to 68cdc99 Compare September 28, 2016 19:51
<constraints nullable="false" />
</column>
<column name="created_by" type="INTEGER"
defaultValueComputed="SELECT u.id FROM users u WHERE u.role = 'ADMIN'">
Copy link
Owner

@php-coder php-coder Sep 30, 2016

Choose a reason for hiding this comment

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

Here, we're fetching all admins instead of the first one.

<comment>Adds created_at and created_by columns to series_sales table and fills them with default data</comment>

<addColumn tableName="series_sales">
<column name="created_at" type="DATETIME" defaultValueComputed="${NOW}">
Copy link
Owner

@php-coder php-coder Sep 30, 2016

Choose a reason for hiding this comment

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

To make it compatible with MySQL < 5.6.6 let's do it in the 3 steps then: 1) create nullable field 2) execute update query 3) mark field as not null

Also put comment why we're doing this in a such way.

http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">

<changeSet id="add-creator-columns-to-series_sales_table" author="cssru" context="scheme">
<comment>Adds created_at and created_by columns to series_sales table and fills them with default data</comment>
Copy link
Owner

Choose a reason for hiding this comment

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

s/with default data/with default values/ or even remove this comment (because it obvious).

defaultValueComputed="SELECT u.id FROM users u WHERE u.role = 'ADMIN'">
<constraints nullable="false"
references="users(id)"
foreignKeyName="fk_series_sales_created_by" />
Copy link
Owner

Choose a reason for hiding this comment

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

It should have name fk_series_sales_user_id.

@cssru cssru force-pushed the gh469_add_created_to_sales branch from 68cdc99 to 743a303 Compare October 5, 2016 20:03
@coveralls
Copy link

Coverage Status

Coverage remained the same at 75.979% when pulling 15130c5 on cssru:gh469_add_created_to_sales into 68c79a7 on php-coder:master.

@cssru cssru force-pushed the gh469_add_created_to_sales branch from 15130c5 to 0052ddb Compare October 8, 2016 19:41
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0052ddb on cssru:gh469_add_created_to_sales into * on php-coder:master*.

http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">

<changeSet id="add-creator-columns-to-series_sales_table" author="cssru" context="scheme">
<comment>We use this way because of MySQL version supported by TravisCI (lower than 5.6.6)</comment>
Copy link
Owner

Choose a reason for hiding this comment

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

This should be a XML comment <!-- and --> instead of comment on changeSet.

Copy link
Owner

Choose a reason for hiding this comment

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

And let's update a comment because it's not about TravisCi's version but about my attempt to support a bit more versions of MySQL:

Since MySQL 5.6.5 it's possible to use `NOW()` as default value for a column but we're doing the same in 3 steps to support also old versions.

BTW, did you know that NOW() returns the same value during transaction? I didn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I didn't.

<update tableName="series_sales">
<column name="created_by"
type="INTEGER"
valueComputed="(SELECT u.id FROM users u WHERE u.role = 'ADMIN' LIMIT 1)" />
Copy link
Owner

Choose a reason for hiding this comment

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

ORDER by u.id is missing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@cssru cssru force-pushed the gh469_add_created_to_sales branch from 0052ddb to 1fe081e Compare October 10, 2016 20:11
@coveralls
Copy link

Coverage Status

Coverage remained the same at 75.979% when pulling 1fe081e on cssru:gh469_add_created_to_sales into 4945143 on php-coder:master.

@php-coder
Copy link
Owner

Merged in d55cd6c

@php-coder php-coder closed this Oct 10, 2016
@cssru cssru deleted the gh469_add_created_to_sales branch October 10, 2016 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants