Skip to content

init database? #416

Closed
Closed
@iamzifei

Description

@iamzifei

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions