Skip to content

Commit

Permalink
[FAB-4211] WIP: Allow zero date values MySQL
Browse files Browse the repository at this point in the history
SQL syntax errors seen while creating certificates
table on MySQL server. It is better use zero date
value as default for timestampcolumns rather than a
specific date. This in combination with database
documentation update will resolve this issue.

See [FAB-4211] for more info

Change-Id: I028bd0d3b4b13d7a953149faf40f7d786a45527e
Signed-off-by: Saad Karim <skarim@us.ibm.com>
  • Loading branch information
Saad Karim committed Jun 9, 2017
1 parent c9372be commit 037b407
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions docs/source/users-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,19 @@ The following sample may be added to the Fabric CA server configuration file in
order to connect to a MySQL database. Be sure to customize the various
values appropriately.

On MySQL 5.7.X, certain modes affect whether the server permits '0000-00-00' as a valid date.
It might be necessary to relax the modes that MySQL server uses. We want to allow
the server to be able to accept zero date values.

In my.cnf, find the configuration option *sql_mode* and remove *NO_ZERO_DATE* if present.
Restart MySQL server after making this change.

Please refer to the following MySQL documentation on different modes available
and select the appropriate settings for the specific version of MySQL that is
being used.

https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

::

db:
Expand Down Expand Up @@ -1546,16 +1559,6 @@ https://www.postgresql.org/docs/9.4/static/libpq-ssl.html
MySQL SSL Configuration
~~~~~~~~~~~~~~~~~~~~~~~

On MySQL 5.7.X, certain modes affect whether the server permits '0000-00-00' as a valid date.
It might be necessary to relax the modes that MySQL server uses. We want to allow
the server to be able to accept zero date values.

Please refer to the following MySQL documentation on different modes available
and select the appropriate settings for the specific version of MySQL that is
being used.

https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

**Basic instructions for configuring SSL on MySQL server:**

1. Open or create my.cnf file for the server. Add or uncomment the
Expand Down
2 changes: 1 addition & 1 deletion lib/dbutil/dbutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func createMySQLTables(datasource string, dbName string, db *sqlx.DB) error {
return fmt.Errorf("Error creating affiliations table: %s", err)
}
log.Debug("Created affiliations table")
if _, err := database.Exec("CREATE TABLE certificates (id VARCHAR(64), serial_number varbinary(128) NOT NULL, authority_key_identifier varbinary(128) NOT NULL, ca_label varbinary(128), status varbinary(128) NOT NULL, reason int, expiry timestamp DEFAULT '1970-01-01 00:00:01', revoked_at timestamp DEFAULT '1970-01-01 00:00:01', pem varbinary(4096) NOT NULL, PRIMARY KEY(serial_number, authority_key_identifier)) DEFAULT CHARSET=utf8 COLLATE utf8_bin"); err != nil {
if _, err := database.Exec("CREATE TABLE certificates (id VARCHAR(64), serial_number varbinary(128) NOT NULL, authority_key_identifier varbinary(128) NOT NULL, ca_label varbinary(128), status varbinary(128) NOT NULL, reason int, expiry timestamp DEFAULT 0, revoked_at timestamp DEFAULT 0, pem varbinary(4096) NOT NULL, PRIMARY KEY(serial_number, authority_key_identifier)) DEFAULT CHARSET=utf8 COLLATE utf8_bin"); err != nil {
return fmt.Errorf("Error creating certificates table: %s", err)
}
log.Debug("Created certificates table")
Expand Down

0 comments on commit 037b407

Please sign in to comment.