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

init database? #416

Closed
iamzifei opened this issue Jul 24, 2018 · 2 comments
Closed

init database? #416

iamzifei opened this issue Jul 24, 2018 · 2 comments

Comments

@iamzifei
Copy link

iamzifei commented Jul 24, 2018

Hi just trying to refactor a project using sequelize-typescript. the project has model defined in ts already such as the following:

import { BelongsToMany, Column, CreatedAt, DataType, HasMany, Model, PrimaryKey, Scopes, Table, UpdatedAt } from "sequelize-typescript";
import { AbstractLookupTableModel } from "./abstractLookupTableModel";
import { company } from "./company";
import { company_reference } from './company_reference';
import { company_state_rel } from "./company_state_rel";

@Table
export class state_code extends AbstractLookupTableModel<state_code> {

  @PrimaryKey
  @Column(DataType.TEXT)
  public state_id!: string;

  @Column(DataType.TEXT)
  public state_name!: string;

  @Column(DataType.TEXT)
  public country_code!: string;

  @BelongsToMany(() => company, () => company_state_rel)
  public companys?: company[];

  @HasMany(() => company_reference)
  public companyReferences!: company_reference[];

}

and I've add model as the following:

...
export const databaseConnection: Sequelize = new Sequelize({
  database: config.database,
  username: config.username,
  password: config.password,
  dialect: config.dialect,
  host: config.host,
  port: config.port,
});

databaseConnection.addModels(
  [
    // base table
    company,
    // detail tables
    company_detail, company_asic_detail, company_asic_detail_businessname, company_office_holder, company_insurance,
    company_bank_detail, company_reference, company_contact, company_project_history, company_project_history_images,
    company_ratings,
    // M-to-N relationships
    company_state_rel, company_trade_skill_rel, company_trade_experience_rel,

    company_trade_context_rel, company_reference_trade_context_rel, user_shortlist_company_rel,
    // 1-to-M relationships
    company_asic_notifications,
    // lookup tables
    state_code, trade_skill_code, trade_experience_code, trade_context_code, insurance_code,
    // user management
    app_user, ca_user, company_access, user_shortlist_detail,
    // job management
    job_run_history]);

databaseConnection.sync({);

however when running sequelize db:migrate I couldn't see the table get created in the database, is there anything wrong?

the package version is as following:

    "sequelize": "^3.17.3",
    "sequelize-cli": "^2.3.1",
    "sequelize-cli-typescript": "^3.2.0-c",
    "sequelize-typescript": "0.6.5",

after testing a couple of times the issue is sometimes happening. I run it again and it works, however after I drop all tables and re-run it again it didn't work...

@RobinBuschmann
Copy link
Member

Hey @iamzifei there are several discussions about migrations and sequelize-typescript https://github.com/RobinBuschmann/sequelize-typescript/issues?utf8=%E2%9C%93&q=migrations

Since I've never used the sequelize integrated implementation migration, for now I can only recommend using https://github.com/db-migrate/node-db-migrate

@RobinBuschmann
Copy link
Member

Closing this in favor of #328

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

No branches or pull requests

2 participants