opencdms-dev / pyopencdms-old

⭐🐍 pyopencdms aims to build a common Python API on top of multiple Climate Data Management Systems (CDMS) that use different underlying database engines
MIT License
4 stars 6 forks source link

SQLAlchemy models for MCH #18

Closed faysal-ishtiaq closed 3 years ago

faysal-ishtiaq commented 3 years ago

I encountered an error while importing the tables into the database. In the DDL file on line 506, it was

CREATE TABLE Recepsping (
......
    Datee datetime NOT NULL default "0000-00-00 00:00:00",
......

I changed it to the following to solve the error

CREATE TABLE Recepsping (
......
    Datee datetime NOT NULL default "1901-01-01 00:00:00",
......
cla-bot[bot] commented 3 years ago

We require contributors to sign our Contributor License Agreement, and we don't have @faysal-ishtiaq on file. In order for us to review and merge your code, please contact @isedwards to get yourself added.

isedwards commented 3 years ago

Thank you @faysal-ishtiaq. MCH users are using MySQL 5.1 which allows the dummy dates by default as an alternative to NULL.

The NO_ZERO_DATE SQL Mode was added in MySQL 5.7.8.

Could you try:

  1. Dropping the database
  2. Setting NO_ZERO_DATE to False to allow the dummy default dates and restoring the schema
  3. Run sqlacodegen again and checking it doesn't have any problem with the dummy date
  4. Add a commit with this minor change
faysal-ishtiaq commented 3 years ago

Executing these commands resolved the issue with original DDL file.

mysql -h localhost -P 3306 --protocol tcp -D mch -u root -p
SET GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
exit;
mysql -h localhost -P 3306 --protocol tcp -D mch -u root -p < ./opencdms-test-data/schemas/mch/Create_MCH_English_basic_tables.sql

and from this package root

 sqlacodegen mysql+pymysql://root:root@localhost/mch > ./opencdms/models/mch/english.py

P.S: I used latest MySQL docker image

isedwards commented 3 years ago

@cla-bot check

cla-bot[bot] commented 3 years ago

The cla-bot has been summoned, and re-checked this pull request!

isedwards commented 3 years ago

Resolves #10