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

Add DB Schema #8

Merged
merged 56 commits into from
Nov 27, 2017
Merged

Add DB Schema #8

merged 56 commits into from
Nov 27, 2017

Conversation

kratsg
Copy link
Contributor

@kratsg kratsg commented Oct 25, 2017

2017-10-25T00:32:13.635925+00:00 app[api]: Deploy d76910e9 by user kratsg@gmail.com
2017-10-25T00:32:21.827208+00:00 app[web.1]: signsfive-api listening at http://[::]:54396
2017-10-25T00:32:21.989604+00:00 app[web.1]: Executing (default): SELECT 1+1 AS result
2017-10-25T00:32:21.999789+00:00 app[web.1]: {"name":"signsfive-api","hostname":"bb0310f8-0ef6-47f3-9534-c94b3fa172c9","pid":18,"level":30,"msg":"Database connection has been established successfully.","time":"2017-10-25T00:32:21.999Z","v":0}
2017-10-25T00:32:22.138772+00:00 heroku[web.1]: State changed from starting to up

we can definitely authenticate to the database correctly. This is a WIP and I should add the rest of the functionality soon.

@kratsg
Copy link
Contributor Author

kratsg commented Oct 25, 2017

Progress so far:

  • all models added
  • reorganized code to make database definition look cleaner

Next:

Copy link
Contributor

@meltedspork meltedspork left a comment

Choose a reason for hiding this comment

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

How do you feel that in new (maybe next?) PR that we could use babel here so we can use ES2015+?

'use strict';
module.exports = (sequelize, DataTypes) => {
var Sign = sequelize.define('Sign', {
name: DataTypes.STRING,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need id in the sign model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sequelize will add this automatically when sync'ing the table (along with created/updated fields). We can be more explicit about this.

'use strict';
module.exports = (sequelize, DataTypes) => {
var Terminology = sequelize.define('Terminology', {
name: DataTypes.STRING,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need id in the terminology model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sequelize will add this automatically when sync'ing the table (along with created/updated fields). We can be more explicit about this.

'use strict';
module.exports = (sequelize, DataTypes) => {
var User = sequelize.define('User', {
email: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need id in the user model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sequelize will add this automatically when sync'ing the table (along with created/updated fields). We can be more explicit about this.

'use strict';
module.exports = (sequelize, DataTypes) => {
var Introspect = sequelize.define('Introspect', {
name: DataTypes.STRING,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need id in the introspect model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sequelize will add this automatically when sync'ing the table (along with created/updated fields). We can be more explicit about this.

@kratsg
Copy link
Contributor Author

kratsg commented Oct 25, 2017

How do you feel that in new (maybe next?) PR that we could use babel here so we can use ES2015+?

Sure. Most of the files were generated by the sequelize-cli which just didn't directly support ES2015+ out of the box. For now, just to make sure things worked, I just did everything here in vanilla javascript with the ulterior goal to migrate.

@meltedspork
Copy link
Contributor

Sure. Most of the files were generated by the sequelize-cli which just didn't directly support ES2015+ out of the box. For now, just to make sure things worked, I just did everything here in vanilla javascript with the ulterior goal to migrate.

That makes sense. We can keep everything vanilla JavaScript for sequelize

@kratsg
Copy link
Contributor Author

kratsg commented Nov 8, 2017

Tables:

  • Author
  • Sign
  • Regions
  • Source
  • Category
  • Gloss

Changes:

  • Remove introspection table
  • Add Regions
  • Rename Terminology to Gloss
  • Add Source

Relationship overview:

Source.B2M(Gloss, ...)
Gloss.B2M(Source, ...)
Source.B2M(Cat, ...)
Sign.B2M(Cat, ...)
Cat.B2M(Source, ...)
Sign.B2M(Gloss, ...)
Sign.B2M(Region, ...)
Cat.B2M(Sign, ...)
Gloss.B2M(Gloss, gloss1)
Gloss.B2M(Gloss, gloss2)
Regions.B2M(Sign, ...)
Author.hasMany(Sign, ...) [author ID added to sign table]
Regions.hasMany(Author, ...) [region ID added to author table]

Design overview:
img_5546

@meltedspork
Copy link
Contributor

meltedspork commented Nov 8, 2017

Lets fix the naming tables a bit with proper grammar -

Authors
Signs
Regions
Sources
Categories
Glosses

@kratsg
Copy link
Contributor Author

kratsg commented Nov 21, 2017

SQL generated so far, but I will encode this into a migration soon...

Database: signsfive_dev
+-----------------+
|     Tables      |
+-----------------+
| Authors         |
| Categories      |
| Glosses         |
| Regions         |
| SequelizeMeta   |
| Signs           |
| Sources         |
| category_sign   |
| category_source |
| gloss_gloss     |
| gloss_sign      |
| gloss_source    |
| region_sign     |
+-----------------+
Executing (default): CREATE TABLE IF NOT EXISTS `Regions` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `loc` POINT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `Regions` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `Authors`;
Executing (default): CREATE TABLE IF NOT EXISTS `Authors` (`id` INTEGER NOT NULL auto_increment , `email` VARCHAR(255), `username` VARCHAR(255), `auth0_id` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `RegionId` INTEGER, PRIMARY KEY (`id`), FOREIGN KEY (`RegionId`) REFERENCES `Regions` (`id`) ON DELETE SET NULL ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `Authors` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `Categories`;
Executing (default): CREATE TABLE IF NOT EXISTS `Categories` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `description` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `Categories` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `Glosses`;
Executing (default): CREATE TABLE IF NOT EXISTS `Glosses` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `description` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `Glosses` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `Signs`;
Executing (default): CREATE TABLE IF NOT EXISTS `Signs` (`id` INTEGER NOT NULL auto_increment , `giphy_id` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `AuthorId` INTEGER, PRIMARY KEY (`id`), FOREIGN KEY (`AuthorId`) REFERENCES `Authors` (`id`) ON DELETE SET NULL ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `Signs` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `Sources`;
Executing (default): CREATE TABLE IF NOT EXISTS `Sources` (`id` INTEGER NOT NULL auto_increment , `url` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `Sources` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `category_source`;
Executing (default): CREATE TABLE IF NOT EXISTS `category_source` (`createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `category_id` INTEGER , `source_id` INTEGER , PRIMARY KEY (`category_id`, `source_id`), FOREIGN KEY (`category_id`) REFERENCES `Categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`source_id`) REFERENCES `Sources` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `category_source` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `category_sign`;
Executing (default): CREATE TABLE IF NOT EXISTS `category_sign` (`createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `category_id` INTEGER , `sign_id` INTEGER , PRIMARY KEY (`category_id`, `sign_id`), FOREIGN KEY (`category_id`) REFERENCES `Categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`sign_id`) REFERENCES `Signs` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `category_sign` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `gloss_source`;
Executing (default): CREATE TABLE IF NOT EXISTS `gloss_source` (`createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `gloss_id` INTEGER , `source_id` INTEGER , PRIMARY KEY (`gloss_id`, `source_id`), FOREIGN KEY (`gloss_id`) REFERENCES `Glosses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`source_id`) REFERENCES `Sources` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `gloss_source` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `gloss_gloss`;
Executing (default): CREATE TABLE IF NOT EXISTS `gloss_gloss` (`createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `gloss_id` INTEGER , `alt_gloss_id` INTEGER , PRIMARY KEY (`gloss_id`, `alt_gloss_id`), FOREIGN KEY (`gloss_id`) REFERENCES `Glosses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`alt_gloss_id`) REFERENCES `Glosses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `gloss_gloss` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `region_sign`;
Executing (default): CREATE TABLE IF NOT EXISTS `region_sign` (`createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `region_id` INTEGER , `sign_id` INTEGER , PRIMARY KEY (`region_id`, `sign_id`), FOREIGN KEY (`region_id`) REFERENCES `Regions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`sign_id`) REFERENCES `Signs` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `region_sign` FROM `signsfive_dev`
Executing (default): DROP TABLE IF EXISTS `gloss_sign`;
Executing (default): CREATE TABLE IF NOT EXISTS `gloss_sign` (`createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `sign_id` INTEGER , `gloss_id` INTEGER , PRIMARY KEY (`sign_id`, `gloss_id`), FOREIGN KEY (`sign_id`) REFERENCES `Signs` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`gloss_id`) REFERENCES `Glosses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `gloss_sign` FROM `signsfive_dev`

@kratsg
Copy link
Contributor Author

kratsg commented Nov 21, 2017

signsfive_dev_schema

@kratsg
Copy link
Contributor Author

kratsg commented Nov 22, 2017

signsfive_dev_schema

@kratsg
Copy link
Contributor Author

kratsg commented Nov 22, 2017

To do:

  • determine if we should use scopes for sourcable models: gloss and sign. Could potentially combine into a single table with a foreign key that's joined on another table depending on the value of a column [see http://docs.sequelizejs.com/manual/tutorial/associations.html#scopes] -- see Understand scopes better for sequelize #12 for this.
  • fix up primary keys for relationship-relationship tables, specifically they should not have an id that's auto-incrementing, but a combined primary key -- fix up the migration here since we do not have a database yet.

@kratsg
Copy link
Contributor Author

kratsg commented Nov 23, 2017

signsfive_dev_schema

@kratsg kratsg changed the title WIP: Add DB Schema Add DB Schema Nov 23, 2017
@kratsg
Copy link
Contributor Author

kratsg commented Nov 23, 2017

@meltedspork time for you to look things over!

@meltedspork
Copy link
Contributor

SWEET!!!!

@kratsg
Copy link
Contributor Author

kratsg commented Nov 27, 2017

@meltedspork approved offline.

@kratsg kratsg merged commit aa9cb55 into master Nov 27, 2017
@kratsg kratsg deleted the add/dbSchema branch November 27, 2017 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants