Navigation Menu

Skip to content

Commit

Permalink
Add domain ID to generated table name
Browse files Browse the repository at this point in the history
  • Loading branch information
piro committed Aug 1, 2012
1 parent 5029cde commit 479a3f9
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 99 deletions.
14 changes: 9 additions & 5 deletions lib/database/domain.js
Expand Up @@ -7,9 +7,9 @@ exports.MAXIMUM_DOMAIN_NAME_LENGTH = 28;
exports.INVALID_DOMAIN_NAME_CHARACTER_PATTERN = /[^\-a-z0-9]/g;
exports.INVALID_TABLE_NAME_CHARACTER_PATTERN = /[^_a-z0-9]/g;

var FAKE_DOMAIN_ID =
exports.FAKE_DOMAIN_ID =
Domain.FAKE_DOMAIN_ID = '00000000000000000000000000';
var DEFAULT_DOMAIN_ID =
exports.DEFAULT_DOMAIN_ID =
Domain.DEFAULT_DOMAIN_ID = '00000000000000000000000000';

function assertValidDomainName(domain) {
if (typeof domain != 'string')
Expand Down Expand Up @@ -88,7 +88,7 @@ Domain.prototype = {
get tableName() {
if (!this._tableName) {
assertValidDomainName(this.name);
this._tableName = this.name;
this._tableName = this.name + '_' + this.id;
}
return this._tableName;
},
Expand Down Expand Up @@ -122,8 +122,12 @@ Domain.prototype = {
},

get id() {
return FAKE_DOMAIN_ID;
return this._id || DEFAULT_DOMAIN_ID;
},
set id(value) {
return this._id = value;
},

get domainId() {
return this.id + '/' + this.name;
},
Expand Down
4 changes: 2 additions & 2 deletions test/api-batch.test.js
Expand Up @@ -47,7 +47,7 @@ suite('documents/batch API', function() {
assert.deepEqual(response, expected);

var dump = context.commandSync('dump', {
tables: 'companies'
tables: 'companies_00000000000000000000000000'
});
assert.equal(dump, schemeDump + '\n' + loadDump);

Expand Down Expand Up @@ -83,7 +83,7 @@ suite('documents/batch API', function() {
assert.deepEqual(response, expected);

var dump = context.commandSync('dump', {
tables: 'companies'
tables: 'companies_00000000000000000000000000'
});
assert.equal(dump, schemeDump + '\n' + deletedLoadDump);

Expand Down
88 changes: 44 additions & 44 deletions test/api-configuration.test.js
Expand Up @@ -236,8 +236,8 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expectedDump = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'table_create companies_BigramTerms ' +
var expectedDump = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram';
assert.equal(dump, expectedDump);
Expand All @@ -250,16 +250,16 @@ suite('Configuration API', function() {
Created: 'true',
Deleted: 'false',
DocService: {
Endpoint: 'doc-companies-' + Domain.FAKE_DOMAIN_ID + '.localhost'
Endpoint: 'doc-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
},
DomainId: Domain.FAKE_DOMAIN_ID + '/companies',
DomainId: Domain.DEFAULT_DOMAIN_ID + '/companies',
DomainName: 'companies',
NumSearchableDocs: '0',
RequiresIndexDocuments: 'false',
SearchInstanceCount: '0',
SearchPartitionCount: '0',
SearchService: {
Endpoint: 'search-companies-' + Domain.FAKE_DOMAIN_ID + '.localhost'
Endpoint: 'search-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
}
};
var status = response.body.CreateDomainResponse.CreateDomainResult.DomainStatus;
Expand Down Expand Up @@ -293,16 +293,16 @@ suite('Configuration API', function() {
Created: 'false',
Deleted: 'true',
DocService: {
Endpoint: 'doc-companies-' + Domain.FAKE_DOMAIN_ID + '.localhost'
Endpoint: 'doc-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
},
DomainId: Domain.FAKE_DOMAIN_ID + '/companies',
DomainId: Domain.DEFAULT_DOMAIN_ID + '/companies',
DomainName: 'companies',
NumSearchableDocs: '0',
RequiresIndexDocuments: 'false',
SearchInstanceCount: '0',
SearchPartitionCount: '0',
SearchService: {
Endpoint: 'search-companies-' + Domain.FAKE_DOMAIN_ID + '.localhost'
Endpoint: 'search-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
}
};
var status = response.body.DeleteDomainResponse.DeleteDomainResult.DomainStatus;
Expand All @@ -327,13 +327,13 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'column_create companies name COLUMN_SCALAR ShortText\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'column_create companies_00000000000000000000000000 name COLUMN_SCALAR ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram\n' +
'column_create companies_BigramTerms companies_name ' +
'COLUMN_INDEX|WITH_POSITION companies name';
'column_create companies_00000000000000000000000000_BigramTerms companies_00000000000000000000000000_name ' +
'COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 name';
assert.equal(dump, expected);

response = toParsedResponse(response);
Expand Down Expand Up @@ -371,15 +371,15 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'column_create companies age COLUMN_SCALAR UInt32\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'column_create companies_00000000000000000000000000 age COLUMN_SCALAR UInt32\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram\n' +
'table_create companies_age ' +
'table_create companies_00000000000000000000000000_age ' +
'TABLE_HASH_KEY UInt32\n' +
'column_create companies_age companies_age ' +
'COLUMN_INDEX|WITH_POSITION companies age';
'column_create companies_00000000000000000000000000_age companies_00000000000000000000000000_age ' +
'COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 age';
assert.equal(dump, expected);

response = toParsedResponse(response);
Expand Down Expand Up @@ -415,15 +415,15 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram\n' +
'table_create companies_member ' +
'table_create companies_00000000000000000000000000_member ' +
'TABLE_HASH_KEY ShortText\n' +
'column_create companies_member companies_member ' +
'COLUMN_INDEX|WITH_POSITION companies member\n' +
'column_create companies member COLUMN_SCALAR companies_member';
'column_create companies_00000000000000000000000000_member companies_00000000000000000000000000_member ' +
'COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 member\n' +
'column_create companies_00000000000000000000000000 member COLUMN_SCALAR companies_00000000000000000000000000_member';
assert.equal(dump, expected);

response = toParsedResponse(response);
Expand Down Expand Up @@ -464,8 +464,8 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram';
assert.equal(dump, expected);
Expand Down Expand Up @@ -496,8 +496,8 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram';
assert.equal(dump, expected);
Expand Down Expand Up @@ -528,8 +528,8 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram';
assert.equal(dump, expected);
Expand Down Expand Up @@ -562,17 +562,17 @@ suite('Configuration API', function() {
var dump = context.commandSync('dump', {
tables: 'companies'
});
var expected = 'table_create companies TABLE_HASH_KEY ShortText\n' +
'column_create companies age COLUMN_SCALAR UInt32\n' +
'column_create companies name COLUMN_SCALAR ShortText\n' +
'table_create companies_BigramTerms ' +
var expected = 'table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText\n' +
'column_create companies_00000000000000000000000000 age COLUMN_SCALAR UInt32\n' +
'column_create companies_00000000000000000000000000 name COLUMN_SCALAR ShortText\n' +
'table_create companies_00000000000000000000000000_BigramTerms ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram\n' +
'table_create companies_age TABLE_HASH_KEY UInt32\n' +
'column_create companies_age companies_age ' +
'COLUMN_INDEX|WITH_POSITION companies age\n' +
'column_create companies_BigramTerms companies_name ' +
'COLUMN_INDEX|WITH_POSITION companies name';
'table_create companies_00000000000000000000000000_age TABLE_HASH_KEY UInt32\n' +
'column_create companies_00000000000000000000000000_age companies_00000000000000000000000000_age ' +
'COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 age\n' +
'column_create companies_00000000000000000000000000_BigramTerms companies_00000000000000000000000000_name ' +
'COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 name';
assert.equal(dump, expected);

var expectedFieldNames = ['age', 'name'];
Expand Down Expand Up @@ -617,16 +617,16 @@ suite('Configuration API', function() {
})
.next(function(response) {
var dumpExpected =
'table_create companies_synonyms TABLE_HASH_KEY|KEY_NORMALIZE ShortText\n' +
'column_create companies_synonyms synonyms COLUMN_VECTOR ShortText\n' +
'load --table companies_synonyms\n' +
'table_create companies_00000000000000000000000000_synonyms TABLE_HASH_KEY|KEY_NORMALIZE ShortText\n' +
'column_create companies_00000000000000000000000000_synonyms synonyms COLUMN_VECTOR ShortText\n' +
'load --table companies_00000000000000000000000000_synonyms\n' +
'[\n' +
'["_key","synonyms"],\n' +
'["tokio",["tokyo"]],\n' +
'["dekkaido",["hokkaido"]]\n' +
']';
var dumpActual = context.commandSync('dump', {
tables: 'companies_synonyms'
tables: 'companies_00000000000000000000000000_synonyms'
});
assert.equal(dumpExpected, dumpActual);

Expand Down
4 changes: 2 additions & 2 deletions test/batch-processor.test.js
Expand Up @@ -52,7 +52,7 @@ suite('batch/processor/Processor (instance methods)', function() {
};
assert.deepEqual(result, expected);
var dump = context.commandSync('dump', {
tables: 'companies'
tables: 'companies_00000000000000000000000000'
});
assert.equal(dump, schemeDump + '\n' + loadDump);
done();
Expand All @@ -79,7 +79,7 @@ suite('batch/processor/Processor (instance methods)', function() {
};
assert.deepEqual(result, expected);
var dump = context.commandSync('dump', {
tables: 'companies'
tables: 'companies_00000000000000000000000000'
});
assert.equal(dump, schemeDump + '\n' + deletedLoadDump);
done();
Expand Down
34 changes: 17 additions & 17 deletions test/batch-translator.test.js
Expand Up @@ -25,7 +25,7 @@ suite('batch/translator/Translator (instance methods)', function() {
var expected = {
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batch['id'],
'name': batch['fields']['name'],
Expand All @@ -45,7 +45,7 @@ suite('batch/translator/Translator (instance methods)', function() {
var expected = {
command: 'delete',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
key: batch['id']
}
};
Expand All @@ -58,7 +58,7 @@ suite('batch/translator/Translator (instance methods)', function() {
var expected = {
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batch['id'],
'name': batch['fields']['name'],
Expand All @@ -78,7 +78,7 @@ suite('batch/translator/Translator (instance methods)', function() {
var expected = {
command: 'delete',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
key: batch['id']
}
};
Expand All @@ -92,7 +92,7 @@ suite('batch/translator/Translator (instance methods)', function() {
{
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batches[0]['id'],
'name': batches[0]['fields']['name'],
Expand All @@ -106,7 +106,7 @@ suite('batch/translator/Translator (instance methods)', function() {
{
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batches[1]['id'],
'name': batches[1]['fields']['name'],
Expand All @@ -120,7 +120,7 @@ suite('batch/translator/Translator (instance methods)', function() {
{
command: 'delete',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
key: batches[2]['id']
}
}
Expand All @@ -138,7 +138,7 @@ suite('batch/translator/Translator (class methods)', function() {
var command = {
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batch['id'],
'name': batch['fields']['name'],
Expand All @@ -147,7 +147,7 @@ suite('batch/translator/Translator (class methods)', function() {
}])
}
};
var expected = 'load --table test --values ' + command.options.values;
var expected = 'load --table test_00000000000000000000000000 --values ' + command.options.values;
var stringified = Translator.commandToString(command);
assert.equal(stringified, expected);
});
Expand All @@ -158,11 +158,11 @@ suite('batch/translator/Translator (class methods)', function() {
var command = {
command: 'delete',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
key: batch['id']
}
};
var expected = 'delete --table test --key ' + command.options.key;
var expected = 'delete --table test_00000000000000000000000000 --key ' + command.options.key;
var stringified = Translator.commandToString(command);
assert.equal(stringified, expected);
});
Expand All @@ -175,7 +175,7 @@ suite('batch/translator/Translator (class methods)', function() {
{
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batches[0]['id'],
'name': batches[0]['fields']['name'],
Expand All @@ -187,7 +187,7 @@ suite('batch/translator/Translator (class methods)', function() {
{
command: 'load',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
values: JSON.stringify([{
'_key': batches[1]['id'],
'name': batches[1]['fields']['name'],
Expand All @@ -199,15 +199,15 @@ suite('batch/translator/Translator (class methods)', function() {
{
command: 'delete',
options: {
table: 'test',
table: 'test_00000000000000000000000000',
key: batches[2]['id']
}
}
];
var expected = [
'load --table test --values ' + commands[0].options.values,
'load --table test --values ' + commands[1].options.values,
'delete --table test --key ' + commands[2].options.key
'load --table test_00000000000000000000000000 --values ' + commands[0].options.values,
'load --table test_00000000000000000000000000 --values ' + commands[1].options.values,
'delete --table test_00000000000000000000000000 --key ' + commands[2].options.key
].join('\n');
var stringified = Translator.commandsToString(commands);
assert.equal(stringified, expected);
Expand Down

0 comments on commit 479a3f9

Please sign in to comment.