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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/resources/liquibase/version/0.4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<include file="0.4/2016-08-18--unique_slug_in_collections.xml" relativeToChangelogFile="true" />
<include file="0.4/2016-08-22--series_sales.xml" relativeToChangelogFile="true" />
<include file="0.4/2016-08-27--fix_series_sales_price.xml" relativeToChangelogFile="true" />
<include file="0.4/2016-09-28--add_creator_data_to_series_sales.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">

<changeSet id="add-creator-columns-to-series_sales_table" author="cssru" context="scheme">
<!-- 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. -->
<addColumn tableName="series_sales">
<column name="created_at" type="DATETIME" />
<column name="created_by" type="INTEGER" />
</addColumn>

<update tableName="series_sales">
<column name="created_at" type="DATETIME" valueComputed="${NOW}" />
</update>

<update tableName="series_sales">
<column name="created_by"
type="INTEGER"
valueComputed="(SELECT id FROM users WHERE role = 'ADMIN' ORDER BY id LIMIT 1)" />
</update>

<addNotNullConstraint columnName="created_at" columnDataType="DATETIME" tableName="series_sales" />

<addNotNullConstraint columnName="created_by" columnDataType="INTEGER" tableName="series_sales" />

<addForeignKeyConstraint
baseColumnNames="created_by"
baseTableName="series_sales"
constraintName="fk_series_sales_users_id"
referencedColumnNames="id"
referencedTableName="users" />

</changeSet>

</databaseChangeLog>