Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

feathers generate service vs sequelize model:create #286

Closed
mbt-olivier-o opened this issue Oct 23, 2017 · 7 comments
Closed

feathers generate service vs sequelize model:create #286

mbt-olivier-o opened this issue Oct 23, 2017 · 7 comments

Comments

@mbt-olivier-o
Copy link

In the context of using sequelize with feathers:
to create a model you can run

 sequelize model:create --name post --attributes title:string,content:text

a model file is created accordingly in the migration folder specified by a .sequelizerc

const path = require('path');

module.exports = {
  'config': path.resolve('migrations/config/config.js'),
  'migrations-path': path.resolve('migrations'),
  'seeders-path': path.resolve('migrations/seeders'),
  'models-path': path.resolve('migrations/models')
};

in this example you get : /migrations/models/post

Once the model is generated next step is to create a service

feathersjs generate service

another model is created under /src/models/post.model.js

Ideally, it would be nice when the generator is running it detects that a model is already there and either make a require of it or copy the table creation part and add any feathers specific.

@DesignByOnyx
Copy link
Contributor

DesignByOnyx commented Nov 22, 2017

You are mixing and matching generators. You are also using the migrations code from the feathers docs (I know, I wrote it ;)). You should not be using the sequelize generators for anything but migrations, and you should not be creating models in the migrations folder.

I recommend not mixing generators. Here's why:

  • Generators are merely a convenience - they're not perfect, and you are supposed to change the generated code to suit your needs. Generators cannot (and should not) check for code/files created by other generators.
  • Feathers models should all be stored in one place: src/models
  • The models path used by the migrations is path.resolve('migrations/models'). Have you looked in that folder? There shouldn't be any models in that folder. It loads all of the models from your application.
  • The feathers generators will generate a model for you and register it with your app. Your migrations script will automatically see this without you needing to do anything.

@mbt-olivier-o
Copy link
Author

mbt-olivier-o commented Nov 23, 2017

@DesignByOnyx , thanks for the clarification.
My goal is:

  • to create a migration file to be able to run any database update independently from the feathersjs server process
  • have a model file generated by feathers generate service command that matches the model described in the migration

According to the sequelize doc it doesn't seem to be possible to create a migration without generating a model. I'm trying to come up with a best practice solution.
Should one run

sequelize model:create --name post --attributes title:string,content:text 

then delete the model file generated by sequelize and then run the feathers generate service to get the model?
or is there a better way to achieve the described goal.

@daffl
Copy link
Member

daffl commented Dec 7, 2017

Sounds about right to me but maybe @DesignByOnyx can weight in again. I'm going to close this issue though since the generator will stay the way it is for the moment.

@daffl daffl closed this as completed Dec 7, 2017
@mkozjak
Copy link

mkozjak commented Dec 17, 2017

Maybe I'm missing something, but when we create a service via feathersjs' cli, we only get a text column in the database. Can we define columns when using the generator?

@daffl
Copy link
Member

daffl commented Dec 18, 2017

The generator is supposed to get you set up quickly but other than the initial model template and connection setup it will not do anything specific to the ORM/database you chose. In most ORMs adding columns is a line or two of code.

@mkozjak
Copy link

mkozjak commented Dec 18, 2017 via email

@huesoamz
Copy link

huesoamz commented Sep 4, 2019

But there is a way to to import all columns to the model? instead of only gettin a "text" column? I have a lot of tables with a lots of columns, there will be a mess write all on hand, instead of having a cli command like loopback have as "discover" there is something similar in feathersjs?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants