null+****@clear*****
null+****@clear*****
2012年 8月 3日 (金) 17:22:55 JST
SHIMODA Hiroshi 2012-08-03 17:22:55 +0900 (Fri, 03 Aug 2012) New Revision: 154421275a0a4ee4e612b2c85a40676c9995d8fb https://github.com/groonga/gcs/commit/154421275a0a4ee4e612b2c85a40676c9995d8fb Log: Change naming rule of generated tabels Modified files: lib/database/domain.js lib/database/index-field.js test/api-batch.test.js test/batch-processor.test.js test/database-domain.test.js test/database-index-field.test.js test/fixture/companies/data-deleted.grn test/fixture/companies/data.grn test/fixture/companies/ddl-custom-id.grn test/fixture/companies/ddl.grn test/fixture/companies/delete.grn test/fixture/companies/synonyms.grn Modified: lib/database/domain.js (+17 -18) =================================================================== --- lib/database/domain.js 2012-08-03 16:17:25 +0900 (6d01661) +++ lib/database/domain.js 2012-08-03 17:22:55 +0900 (f0db8fc) @@ -1,3 +1,10 @@ +/** + * Naming rule of generated tables: + * main table: <domain name>_<domain id> + * index tables: <domain name>_<domain id>_index_<column name> + * meta tables: <domain name>_<domain id>_synonyms + */ + var nativeNroonga = require('nroonga'); var nroonga = require('../wrapped-nroonga'); var IndexField = require('./index-field').IndexField; @@ -11,13 +18,9 @@ var DEFAULT_ID = exports.DEFAULT_ID = Domain.DEFAULT_ID = '00000000000000000000000000'; -var DOMAIN_TABLE_PREFIX = - exports.DOMAIN_TABLE_PREFIX = - Domain.DOMAIN_TABLE_PREFIX = 'domain'; - -var REFERENCE_TABLE_PREFIX = - exports.REFERENCE_TABLE_PREFIX = - Domain.REFERENCE_TABLE_PREFIX = 'reference'; +var INDEX_SUFFIX = + exports.INDEX_SUFFIX = + Domain.INDEX_SUFFIX = 'index'; function assertValidDomainName(domain) { if (typeof domain != 'string') @@ -108,7 +111,7 @@ Domain.prototype = { if (this.context) { var tableName = Domain.toTableNamePart(this.name); var tables = this.context.tableListSync(); - var tableIdMatcher = new RegExp('^' + DOMAIN_TABLE_PREFIX + '_' + tableName + '_([^_]+)$'); + var tableIdMatcher = new RegExp('^' + tableName + '_([^_]+)$'); var id; if (tables.some(function(table) { var match = table.name.match(tableIdMatcher); @@ -136,25 +139,21 @@ Domain.prototype = { get tableName() { if (!this._tableName) { assertValidDomainName(this.name); - this._tableName = DOMAIN_TABLE_PREFIX + '_' + - Domain.toTableNamePart(this.name) + '_' + this.id; + this._tableName = Domain.toTableNamePart(this.name) + '_' + this.id; } return this._tableName; }, - get referenceTableBaseName() { - if (!this._referenceTableBaseName) - this._referenceTableBaseName = REFERENCE_TABLE_PREFIX + '_' + - Domain.toTableNamePart(this.name) + '_' + this.id; - return this._referenceTableBaseName; + get indexTableBaseName() { + return this.tableName + '_' + INDEX_SUFFIX + '_'; }, get termsTableName() { - return this.referenceTableBaseName + '_BigramTerms'; + return this.indexTableBaseName + '_BigramTerms'; }, get synonymTableName() { - return this.referenceTableBaseName + '_synonyms'; + return this.tableName + '_synonyms'; }, getIndexField: function(field) { @@ -330,7 +329,7 @@ Domain.getAll = function(context) { context = context && new nroonga.Context(context); var tables = context.tableListSync(); - var tableMatcher = new RegExp('^' + DOMAIN_TABLE_PREFIX + '_([^_]+)_([^_]+)$'); + var tableMatcher = new RegExp('^([^_]+)_([^_]+)$'); var domains = []; tables.forEach(function(table) { var match = table.name.match(tableMatcher); Modified: lib/database/index-field.js (+27 -24) =================================================================== --- lib/database/index-field.js 2012-08-03 16:17:25 +0900 (bb8d8cd) +++ lib/database/index-field.js 2012-08-03 17:22:55 +0900 (508150e) @@ -56,21 +56,17 @@ IndexField.prototype = { get columnName() { if (!this._columnName) { assertValidFieldName(this.name); - this._columnName = this.name; + this._columnName = IndexField.toColumnNamePart(this.name); } return this._columnName; }, get indexColumnName() { - if (!this._indexColumnName) - this._indexColumnName = this.domain.referenceTableBaseName + '_' + this.columnName; - return this._indexColumnName; + this.domain.indexTableBaseName + '_' + this.columnName; }, - get referenceTableName() { - if (!this._referenceTableName) - this._referenceTableName = this.domain.referenceTableBaseName + '_' + this.columnName; - return this._referenceTableName; + get indexTableName() { + this.domain.indexTableBaseName + '_' + this.columnName; }, - get referenceTableKeyType() { + get indexTableKeyType() { var type = this.type; switch (type) { case 'uint': @@ -79,7 +75,7 @@ IndexField.prototype = { return nroonga.ShortText; default: throw new Error('Unsupported index field type ' + type + - ' for reference table'); + ' for index table'); } }, fieldTypeToColumnType: function(fieldType) { @@ -89,7 +85,7 @@ IndexField.prototype = { case 'uint': return nroonga.UInt32; case 'literal': - return this.referenceTableName; + return this.indexTableName; default: throw new Error('Unsupported index field type ' + fieldType); } @@ -100,7 +96,7 @@ IndexField.prototype = { return 'text'; case nroonga.UInt32: return 'uint'; - case this.referenceTableName: + case this.indexTableName: return 'literal'; default: throw new Error('Unsupported column type ' + columnType); @@ -130,7 +126,7 @@ IndexField.prototype = { } else if (column.type == 'fix') { if (column.range == nroonga.UInt32) return this._type = 'uint'; - else if (column.range == this.referenceTableName) + else if (column.range == this.indexTableName) return this._type = 'literal'; } @@ -161,18 +157,18 @@ IndexField.prototype = { }, createSync: function() { - var referenceTableName = this.domain.termsTableName; + var indexTableName = this.domain.termsTableName; var type = this.type; var columnType = this.fieldTypeToColumnType(type); if (type == 'uint' || type == 'literal') { this.context.commandSync('table_create', { - name: this.referenceTableName, + name: this.indexTableName, flags: nroonga.TABLE_HASH_KEY, - key_type: this.referenceTableKeyType + key_type: this.indexTableKeyType }); - referenceTableName = this.referenceTableName; + indexTableName = this.indexTableName; } this.context.commandSync('column_create', { @@ -182,7 +178,7 @@ IndexField.prototype = { type: columnType }); this.context.commandSync('column_create', { - table: referenceTableName, + table: indexTableName, name: this.indexColumnName, flags: nroonga.INDEX_COLUMN_DEFAULT_FLAGS, type: this.domain.tableName, @@ -193,7 +189,7 @@ IndexField.prototype = { var type = this.type; if (type == 'uint' || type == 'literal') { this.context.commandSync('table_remove', { - name: this.referenceTableName + name: this.indexTableName }); } this.context.commandSync('column_remove', { @@ -206,19 +202,19 @@ IndexField.prototype = { var type = this.type; if (type == 'uint' || type == 'literal') { this.context.commandSync('column_remove', { - table: this.referenceTableName, + table: this.indexTableName, name: this.indexColumnName }); this.context.commandSync('table_remove', { - name: this.referenceTableName + name: this.indexTableName }); this.context.commandSync('table_create', { - name: this.referenceTableName, + name: this.indexTableName, flags: nroonga.TABLE_HASH_KEY, - key_type: this.referenceTableKeyType + key_type: this.indexTableKeyType }); this.context.commandSync('column_create', { - table: this.referenceTableName, + table: this.indexTableName, name: this.indexColumnName, flags: nroonga.INDEX_COLUMN_DEFAULT_FLAGS, type: this.domain.tableName, @@ -245,3 +241,10 @@ IndexField.prototype = { }; exports.IndexField = IndexField; + +IndexField.toColumnNamePart = function(fieldName) { + return fieldName; +}; +IndexField.toFieldName = function(columnNamePart) { + return columnNamePart; +}; Modified: test/api-batch.test.js (+2 -4) =================================================================== --- test/api-batch.test.js 2012-08-03 16:17:25 +0900 (121ad4c) +++ test/api-batch.test.js 2012-08-03 17:22:55 +0900 (a0e3e7f) @@ -49,8 +49,7 @@ suite('documents/batch API', function() { assert.deepEqual(response, expected); var dump = context.commandSync('dump', { - tables: Domain.DOMAIN_TABLE_PREFIX + - '_companies_00000000000000000000000000' + tables: 'companies_00000000000000000000000000' }); assert.equal(dump, schemeDump + '\n' + loadDump); @@ -86,8 +85,7 @@ suite('documents/batch API', function() { assert.deepEqual(response, expected); var dump = context.commandSync('dump', { - tables: Domain.DOMAIN_TABLE_PREFIX + - '_companies_00000000000000000000000000' + tables: 'companies_00000000000000000000000000' }); assert.equal(dump, schemeDump + '\n' + deletedLoadDump); Modified: test/batch-processor.test.js (+2 -4) =================================================================== --- test/batch-processor.test.js 2012-08-03 16:17:25 +0900 (7b8839f) +++ test/batch-processor.test.js 2012-08-03 17:22:55 +0900 (84a721c) @@ -53,8 +53,7 @@ suite('batch/processor/Processor (instance methods)', function() { }; assert.deepEqual(result, expected); var dump = context.commandSync('dump', { - tables: Domain.DOMAIN_TABLE_PREFIX + - '_companies_00000000000000000000000000' + tables: 'companies_00000000000000000000000000' }); assert.equal(dump, schemeDump + '\n' + loadDump); done(); @@ -81,8 +80,7 @@ suite('batch/processor/Processor (instance methods)', function() { }; assert.deepEqual(result, expected); var dump = context.commandSync('dump', { - tables: Domain.DOMAIN_TABLE_PREFIX + - '_companies_00000000000000000000000000' + tables: 'companies_00000000000000000000000000' }); assert.equal(dump, schemeDump + '\n' + deletedLoadDump); done(); Modified: test/database-domain.test.js (+2 -4) =================================================================== --- test/database-domain.test.js 2012-08-03 16:17:25 +0900 (a9e1810) +++ test/database-domain.test.js 2012-08-03 17:22:55 +0900 (37330b0) @@ -25,16 +25,14 @@ suite('database', function() { var domain = new Domain('valid'); domain.id = Domain.DEFAULT_ID; assert.equal(domain.tableName, - Domain.DOMAIN_TABLE_PREFIX + '_valid_' + - Domain.DEFAULT_ID); + 'valid_' + Domain.DEFAULT_ID); }); test('lower case and number', function() { var domain = new Domain('valid123'); domain.id = Domain.DEFAULT_ID; assert.equal(domain.tableName, - Domain.DOMAIN_TABLE_PREFIX + '_valid123_' + - Domain.DEFAULT_ID); + 'valid123_' + Domain.DEFAULT_ID); }); test('too short', function() { Modified: test/database-index-field.test.js (+13 -13) =================================================================== --- test/database-index-field.test.js 2012-08-03 16:17:25 +0900 (639b62e) +++ test/database-index-field.test.js 2012-08-03 17:22:55 +0900 (1240d40) @@ -64,15 +64,15 @@ suite('database', function() { test('indexColumnName', function() { var field = new IndexField('valid_123', domain); assert.equal(field.indexColumnName, - Domain.REFERENCE_TABLE_PREFIX + '_testdomain_' + - Domain.DEFAULT_ID + '_valid_123'); + 'testdomain_' + Domain.DEFAULT_ID + '_' + + Domain.INDEX_SUFFIX + '_valid_123'); }); - test('referenceTableName', function() { + test('indexTableName', function() { var field = new IndexField('valid_123', domain); - assert.equal(field.referenceTableName, - Domain.REFERENCE_TABLE_PREFIX + '_testdomain_' + - Domain.DEFAULT_ID + '_valid_123'); + assert.equal(field.indexTableName, + 'testdomain_' + Domain.DEFAULT_ID + '_' + + Domain.INDEX_SUFFIX + '_valid_123'); }); test('fieldTypeToColumnType (text)', function() { @@ -90,8 +90,8 @@ suite('database', function() { test('fieldTypeToColumnType (literal)', function() { var field = new IndexField('valid_123', domain); assert.equal(field.fieldTypeToColumnType('literal'), - Domain.REFERENCE_TABLE_PREFIX + '_testdomain_' + - Domain.DEFAULT_ID + '_valid_123'); + 'testdomain_' + Domain.DEFAULT_ID + '_' + + Domain.INDEX_SUFFIX + '_valid_123'); }); test('initial status (text)', function() { @@ -274,9 +274,9 @@ suite('database', function() { 'table_create ' + domain.termsTableName + ' ' + 'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' + '--default_tokenizer TokenBigram\n' + - 'table_create ' + field.referenceTableName + ' ' + + 'table_create ' + field.indexTableName + ' ' + 'TABLE_HASH_KEY UInt32\n' + - 'column_create ' + field.referenceTableName + ' ' + + 'column_create ' + field.indexTableName + ' ' + field.indexColumnName + ' ' + 'COLUMN_INDEX|WITH_POSITION ' + domain.tableName + ' ' + field.columnName; @@ -317,15 +317,15 @@ suite('database', function() { 'table_create ' + domain.termsTableName + ' ' + 'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' + '--default_tokenizer TokenBigram\n' + - 'table_create ' + field.referenceTableName + ' ' + + 'table_create ' + field.indexTableName + ' ' + 'TABLE_HASH_KEY ShortText\n' + - 'column_create ' + field.referenceTableName + ' ' + + 'column_create ' + field.indexTableName + ' ' + field.indexColumnName + ' ' + 'COLUMN_INDEX|WITH_POSITION ' + domain.tableName + ' ' + field.columnName + '\n' + 'column_create ' + domain.tableName + ' ' + field.columnName + ' COLUMN_SCALAR ' + - field.referenceTableName; + field.indexTableName; assert.equal(dump, expected); }); Modified: test/fixture/companies/data-deleted.grn (+1 -1) =================================================================== --- test/fixture/companies/data-deleted.grn 2012-08-03 16:17:25 +0900 (bc87a0c) +++ test/fixture/companies/data-deleted.grn 2012-08-03 17:22:55 +0900 (f322e7c) @@ -1,4 +1,4 @@ -load --table domain_companies_00000000000000000000000000 +load --table companies_00000000000000000000000000 [ ["_key","address","age","description","email_address","name","product"], ["id2","Sapporo, Hokkaido, Japan",2,"","info****@enish*****","Enishi Tech Inc.","groonga"], Modified: test/fixture/companies/data.grn (+1 -1) =================================================================== --- test/fixture/companies/data.grn 2012-08-03 16:17:25 +0900 (c990cb1) +++ test/fixture/companies/data.grn 2012-08-03 17:22:55 +0900 (db92a18) @@ -1,4 +1,4 @@ -load --table domain_companies_00000000000000000000000000 +load --table companies_00000000000000000000000000 [ ["_key","address","age","description","email_address","name","product"], ["id1","Shibuya, Tokyo, Japan",1,"","info****@razil*****","Brazil","groonga"], Modified: test/fixture/companies/ddl-custom-id.grn (+16 -16) =================================================================== --- test/fixture/companies/ddl-custom-id.grn 2012-08-03 16:17:25 +0900 (aaefe38) +++ test/fixture/companies/ddl-custom-id.grn 2012-08-03 17:22:55 +0900 (c3350b3) @@ -1,16 +1,16 @@ -table_create reference_companies_id0123_product TABLE_HASH_KEY ShortText -table_create reference_companies_id0123_age TABLE_HASH_KEY UInt32 -table_create reference_companies_id0123_BigramTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram -table_create domain_companies_id0123 TABLE_HASH_KEY ShortText -column_create domain_companies_id0123 address COLUMN_SCALAR ShortText -column_create domain_companies_id0123 age COLUMN_SCALAR UInt32 -column_create domain_companies_id0123 description COLUMN_SCALAR ShortText -column_create domain_companies_id0123 email_address COLUMN_SCALAR ShortText -column_create domain_companies_id0123 name COLUMN_SCALAR ShortText -column_create domain_companies_id0123 product COLUMN_SCALAR reference_companies_id0123_product -column_create reference_companies_id0123_BigramTerms companies_name COLUMN_INDEX|WITH_POSITION domain_companies_id0123 name -column_create reference_companies_id0123_BigramTerms companies_email_address COLUMN_INDEX|WITH_POSITION domain_companies_id0123 email_address -column_create reference_companies_id0123_BigramTerms companies_description COLUMN_INDEX|WITH_POSITION domain_companies_id0123 description -column_create reference_companies_id0123_BigramTerms companies_address COLUMN_INDEX|WITH_POSITION domain_companies_id0123 address -column_create reference_companies_id0123_age companies_age COLUMN_INDEX|WITH_POSITION domain_companies_id0123 age -column_create reference_companies_id0123_product companies_product COLUMN_INDEX|WITH_POSITION domain_companies_id0123 product +table_create companies_id0123_index_product TABLE_HASH_KEY ShortText +table_create companies_id0123_index_age TABLE_HASH_KEY UInt32 +table_create companies_id0123_index_BigramTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram +table_create companies_id0123 TABLE_HASH_KEY ShortText +column_create companies_id0123 address COLUMN_SCALAR ShortText +column_create companies_id0123 age COLUMN_SCALAR UInt32 +column_create companies_id0123 description COLUMN_SCALAR ShortText +column_create companies_id0123 email_address COLUMN_SCALAR ShortText +column_create companies_id0123 name COLUMN_SCALAR ShortText +column_create companies_id0123 product COLUMN_SCALAR companies_id0123_index_product +column_create companies_id0123_index_BigramTerms companies_name COLUMN_INDEX|WITH_POSITION companies_id0123 name +column_create companies_id0123_index_BigramTerms companies_email_address COLUMN_INDEX|WITH_POSITION companies_id0123 email_address +column_create companies_id0123_index_BigramTerms companies_description COLUMN_INDEX|WITH_POSITION companies_id0123 description +column_create companies_id0123_index_BigramTerms companies_address COLUMN_INDEX|WITH_POSITION companies_id0123 address +column_create companies_id0123_index_age companies_age COLUMN_INDEX|WITH_POSITION companies_id0123 age +column_create companies_id0123_index_product companies_product COLUMN_INDEX|WITH_POSITION companies_id0123 product Modified: test/fixture/companies/ddl.grn (+16 -16) =================================================================== --- test/fixture/companies/ddl.grn 2012-08-03 16:17:25 +0900 (ba3edb8) +++ test/fixture/companies/ddl.grn 2012-08-03 17:22:55 +0900 (4b05f42) @@ -1,16 +1,16 @@ -table_create reference_companies_00000000000000000000000000_product TABLE_HASH_KEY ShortText -table_create reference_companies_00000000000000000000000000_age TABLE_HASH_KEY UInt32 -table_create reference_companies_00000000000000000000000000_BigramTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram -table_create domain_companies_00000000000000000000000000 TABLE_HASH_KEY ShortText -column_create domain_companies_00000000000000000000000000 address COLUMN_SCALAR ShortText -column_create domain_companies_00000000000000000000000000 age COLUMN_SCALAR UInt32 -column_create domain_companies_00000000000000000000000000 description COLUMN_SCALAR ShortText -column_create domain_companies_00000000000000000000000000 email_address COLUMN_SCALAR ShortText -column_create domain_companies_00000000000000000000000000 name COLUMN_SCALAR ShortText -column_create domain_companies_00000000000000000000000000 product COLUMN_SCALAR reference_companies_00000000000000000000000000_product -column_create reference_companies_00000000000000000000000000_BigramTerms companies_name COLUMN_INDEX|WITH_POSITION domain_companies_00000000000000000000000000 name -column_create reference_companies_00000000000000000000000000_BigramTerms companies_email_address COLUMN_INDEX|WITH_POSITION domain_companies_00000000000000000000000000 email_address -column_create reference_companies_00000000000000000000000000_BigramTerms companies_description COLUMN_INDEX|WITH_POSITION domain_companies_00000000000000000000000000 description -column_create reference_companies_00000000000000000000000000_BigramTerms companies_address COLUMN_INDEX|WITH_POSITION domain_companies_00000000000000000000000000 address -column_create reference_companies_00000000000000000000000000_age companies_age COLUMN_INDEX|WITH_POSITION domain_companies_00000000000000000000000000 age -column_create reference_companies_00000000000000000000000000_product companies_product COLUMN_INDEX|WITH_POSITION domain_companies_00000000000000000000000000 product +table_create companies_00000000000000000000000000_index_product TABLE_HASH_KEY ShortText +table_create companies_00000000000000000000000000_index_age TABLE_HASH_KEY UInt32 +table_create companies_00000000000000000000000000_index_BigramTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram +table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText +column_create companies_00000000000000000000000000 address COLUMN_SCALAR ShortText +column_create companies_00000000000000000000000000 age COLUMN_SCALAR UInt32 +column_create companies_00000000000000000000000000 description COLUMN_SCALAR ShortText +column_create companies_00000000000000000000000000 email_address COLUMN_SCALAR ShortText +column_create companies_00000000000000000000000000 name COLUMN_SCALAR ShortText +column_create companies_00000000000000000000000000 product COLUMN_SCALAR companies_00000000000000000000000000_index_product +column_create companies_00000000000000000000000000_index_BigramTerms companies_name COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 name +column_create companies_00000000000000000000000000_index_BigramTerms companies_email_address COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 email_address +column_create companies_00000000000000000000000000_index_BigramTerms companies_description COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 description +column_create companies_00000000000000000000000000_index_BigramTerms companies_address COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 address +column_create companies_00000000000000000000000000_index_age companies_age COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 age +column_create companies_00000000000000000000000000_index_product companies_product COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 product Modified: test/fixture/companies/delete.grn (+1 -1) =================================================================== --- test/fixture/companies/delete.grn 2012-08-03 16:17:25 +0900 (42494b4) +++ test/fixture/companies/delete.grn 2012-08-03 17:22:55 +0900 (231c8d8) @@ -1 +1 @@ -delete --table domain_companies_00000000000000000000000000 --key id1 +delete --table companies_00000000000000000000000000 --key id1 Modified: test/fixture/companies/synonyms.grn (+3 -3) =================================================================== --- test/fixture/companies/synonyms.grn 2012-08-03 16:17:25 +0900 (1aaa468) +++ test/fixture/companies/synonyms.grn 2012-08-03 17:22:55 +0900 (64220d0) @@ -1,6 +1,6 @@ -table_create reference_companies_00000000000000000000000000_synonyms TABLE_HASH_KEY|KEY_NORMALIZE ShortText -column_create reference_companies_00000000000000000000000000_synonyms synonyms COLUMN_VECTOR ShortText -load --table reference_companies_00000000000000000000000000_synonyms +table_create companies_00000000000000000000000000_synonyms TABLE_HASH_KEY|KEY_NORMALIZE ShortText +column_create companies_00000000000000000000000000_synonyms synonyms COLUMN_VECTOR ShortText +load --table companies_00000000000000000000000000_synonyms [ ["_key","synonyms"], ["tokio",["tokyo"]], -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...Download