Add discover primary/foreign keys

This commit is contained in:
Raymond Feng 2013-05-13 22:04:02 -07:00
parent c15ff3cad0
commit e207628538
1 changed files with 49 additions and 0 deletions

View File

@ -426,6 +426,55 @@ Schema.prototype.discoverModelProperties = function (options, cb) {
}
};
/**
* Discover primary keys for a given owner/table
*
* Each primary key column description has the following columns:
* TABLE_SCHEM String => table schema (may be null)
* TABLE_NAME String => table name
* COLUMN_NAME String => column name
* KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
* PK_NAME String => primary key name (may be null)
*
* @param owner
* @param table
* @param cb
*/
Schema.prototype.discoverPrimaryKeys= function(owner, table, cb) {
this.freeze();
if (this.adapter.discoverPrimaryKeys) {
this.adapter.discoverPrimaryKeys(options, cb);
} else if (cb) {
cb();
}
}
/**
* Discover foreign keys for a given owner/table
*
* PKTABLE_SCHEM String => primary key table schema being imported (may be null)
* PKTABLE_NAME String => primary key table name being imported
* PKCOLUMN_NAME String => primary key column name being imported
* FKTABLE_CAT String => foreign key table catalog (may be null)
* FKTABLE_SCHEM String => foreign key table schema (may be null)
* FKTABLE_NAME String => foreign key table name
* FKCOLUMN_NAME String => foreign key column name
* KEY_SEQ short => sequence number within a foreign key( a value of 1 represents the first column of the foreign key, a value of 2 would represent the second column within the foreign key).
* FK_NAME String => foreign key name (may be null)
* PK_NAME String => primary key name (may be null)
*
* @param owner
* @param table
* @param cb
*/
Schema.prototype.discoverForeignKeys= function(owner, table, cb) {
this.freeze();
if (this.adapter.discoverForeignKeys) {
this.adapter.discoverForeignKeys(options, cb);
} else if (cb) {
cb();
}
}
/**
* Check whether migrations needed