-
-
Notifications
You must be signed in to change notification settings - Fork 28
fixing allowNull, onDelete, onChange, deferrable #13
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,10 @@ export class ModelBuilder extends Builder { | |
...col.dataType && { type: col.dataType }, | ||
...col.comment && { comment: col.comment }, | ||
...col.defaultValue && { defaultValue: col.defaultValue }, | ||
...col.onUpdate && { onUpdate: col.onUpdate }, | ||
...col.onDelete && { onDelete: col.onDelete }, | ||
// @TODO fix this by creating a typescript definition for model | ||
// ...col.references && { references: col.references as ModelAttributeColumnReferencesOptions }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably the following type must be imported? import { ModelAttributeColumnOptions, ModelAttributeColumnReferencesOptions } from 'sequelize'; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not about importing types. This is about reading references directly from postgres tables instead of taking it from file definition - this was just a try |
||
}; | ||
|
||
return props; | ||
|
@@ -179,6 +183,14 @@ export class ModelBuilder extends Builder { | |
'sequelize-typescript' | ||
)); | ||
|
||
generatedCode += '\n'; | ||
generatedCode += nodeToString(generateNamedImports( | ||
[ | ||
'Deferrable', | ||
], | ||
'sequelize' | ||
)); | ||
|
||
generatedCode += '\n'; | ||
|
||
// Named imports for associations | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { IndexType, IndexMethod, AbstractDataTypeConstructor } from 'sequelize'; | ||
import { Sequelize } from 'sequelize-typescript'; | ||
import { Deferrable } from 'sequelize/types/lib/deferrable'; | ||
import { IConfig } from '../config'; | ||
import { createConnection } from "../connection"; | ||
import { AssociationsParser, IAssociationsParsed, IAssociationMetadata } from './AssociationsParser' | ||
import { AssociationsParser, IAssociationMetadata } from './AssociationsParser' | ||
import { caseTransformer } from './utils'; | ||
import {parse} from "@typescript-eslint/parser"; | ||
|
||
export interface ITablesMetadata { | ||
[tableName: string]: ITableMetadata; | ||
|
@@ -22,6 +22,20 @@ export interface ITableMetadata { | |
comment?: string; | ||
} | ||
|
||
export enum CONSTRAINT_TYPES { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these types common to all the Dialects? export enum FOREIGN_KEY_CONSTRAINTS {
CASCADE = 'CASCADE',
SET_DEFAULT = 'SET DEFAULT',
SET_NULL = 'SET NULL',
RESTRICT = 'RESTRICT',
NO_ACTION = 'NO ACTION',
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know about other dialects, this is for postgresql. The keys are what is coming from postgresql already and then how it should be mapped so you can't change it |
||
c = 'CASCADE', | ||
d = 'SET DEFAULT', | ||
n = 'SET NULL', | ||
r = 'RESTRICT', | ||
a = 'NO ACTION', | ||
} | ||
|
||
export interface IColumnMetadataReference { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't need to create this interface, this type is already defined in /**
* References options for the column's attributes
*/
export interface ModelAttributeColumnReferencesOptions {
/**
* If this column references another table, provide it here as a Model, or a string
*/
model?: string | typeof Model;
/**
* The column of the foreign table that this column references
*/
key?: string;
/**
* When to check for the foreign key constraing
*
* PostgreSQL only
*/
deferrable?: Deferrable;
} |
||
model: string | null; | ||
key: string | null; | ||
deferrable: string | Deferrable | null; | ||
} | ||
|
||
export interface IColumnMetadata { | ||
name: string; // Model field name | ||
originName: string; // Database column name | ||
|
@@ -38,6 +52,9 @@ export interface IColumnMetadata { | |
indices?: IIndexMetadata[], | ||
comment?: string; | ||
defaultValue?: any; | ||
onDelete?: CONSTRAINT_TYPES; | ||
onUpdate?: CONSTRAINT_TYPES; | ||
references?: IColumnMetadataReference; | ||
} | ||
|
||
export interface IIndexMetadata { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant, it's the same as build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not
https://docs.npmjs.com/misc/scripts#description
This is needed so when you simply call npm install it will build the packages correctly, otherwise the build is not run. This is especially visible when you use the package using github path.