SHIMODA Hiroshi
null+****@clear*****
Mon Aug 13 15:13:28 JST 2012
SHIMODA Hiroshi 2012-08-13 15:13:28 +0900 (Mon, 13 Aug 2012) New Revision: 19eb75aba5bc86b2f10d85cac908f9bafbda2988 https://github.com/groonga/gcs/commit/19eb75aba5bc86b2f10d85cac908f9bafbda2988 Log: Upgrade column from single to multiple values API Added files: test/fixture/companies/add-multiple-values.sdf.json Modified files: lib/batch/processor.js test/batch-processor.test.js Modified: lib/batch/processor.js (+5 -0) =================================================================== --- lib/batch/processor.js 2012-08-13 14:39:10 +0900 (0fdefb7) +++ lib/batch/processor.js 2012-08-13 15:13:28 +0900 (48ed258) @@ -99,6 +99,11 @@ Processor.prototype = { var record = { id: batch.id }; Object.keys(batch.fields).forEach(function(key) { record[key] = batch.fields[key]; + if (Array.isArray(batch.fields[key])) { + var field = this.domain.getIndexField(key); + if (!field.multipleValues) + field.upgradeToMultipleValuesSync(); + } }); this.domain.addRecordSync(record); results.adds++; Modified: test/batch-processor.test.js (+75 -4) =================================================================== --- test/batch-processor.test.js 2012-08-13 14:39:10 +0900 (36e366c) +++ test/batch-processor.test.js 2012-08-13 15:13:28 +0900 (a5dba4c) @@ -48,10 +48,15 @@ suite('batch/processor/Processor (instance methods)', function() { deletes: deletes }; assert.deepEqual(result, expected); - var dump = context.commandSync('dump', { - tables: 'companies_00000000000000000000000000' - }); - assert.equal(dump, expectedDump); + if (typeof expectedDump == 'string') { // grn dump + var actualGrnDump = context.commandSync('dump', { + tables: 'companies_00000000000000000000000000' + }); + assert.equal(actualGrnDump, expectedDump); + } else { + var actualDump = processor.domain.dumpSync(); + assert.deepEqual(actualDump, expectedDump); + } } test('load add-batches', function(done) { @@ -74,6 +79,72 @@ suite('batch/processor/Processor (instance methods)', function() { assertSuccess(result, 10, 0, schemeDump + '\n' + loadDump); }); + test('loadSync: auto migration to multiple values field', function() { + var batches = fs.readFileSync(__dirname + '/fixture/companies/add-multiple-values.sdf.json', 'UTF-8'); + batches = JSON.parse(batches); + var result = processor.loadSync(batches); + + var field = processor.domain.getIndexField('product'); + assert.isTrue(field.multipleValues); + + var dump = [ + { id: 'id1', + name: 'Brazil', + address: 'Shibuya, Tokyo, Japan', + email_address: 'info �� razil.jp', + age: 1, + product: ['moritapo','groonga'] }, + { id: 'id2', + name: 'Enishi Tech Inc.', + address: 'Sapporo, Hokkaido, Japan', + email_address: 'info �� enishi-tech.com', + age: 2, + product: ['nroonga','groonga'] }, + { id: 'id3' + name: 'ClearCode Inc.', + address: 'Hongo, Tokyo, Japan', + email_address: 'info �� clear-code.com', + age: 3, + product: ['cutter','groonga'] }, + { id: 'id4', + name: 'Anaheim Electronics', + address: 'Granada, Moon', + age: 4, + product: ['hi-zack','gundam'] }, + { id: 'id5', + name: 'Shinsei Industry', + address: 'Earth', + age: 5, + product: ['valkyrie'] }, + { type: 'add', + name: 'Omni Consumer Products', + address: 'Detroit and Delta City, Michigan, United States', + age: 6, + product: ['robocop'] }, + { id: 'id7', + name: 'Capsule Corporation', + address: ['West City'], + age: 7, + product: '[time machine'] }, + { id: 'id8', + name: 'Stark Industries', + address: 'United States', + age: 8, + product: ['iron man'] }, + { id: 'id9', + name: 'Umbrella Corporation', + address: 'Tokyo, Japan', + age: 9, + product: ['tyrant'] }, + { id: 'id10', + name: 'U.S. Robots and Mechanical Men', + address: 'New York, United States', + age: 10, + product: ['ndr114'] } + ]; + assertSuccess(result, 10, 0, dump); + }); + test('load delete-batches', function(done) { var batches = fs.readFileSync(__dirname + '/fixture/companies/add.sdf.json', 'UTF-8'); batches = JSON.parse(batches); Added: test/fixture/companies/add-multiple-values.sdf.json (+125 -0) 100644 =================================================================== --- /dev/null +++ test/fixture/companies/add-multiple-values.sdf.json 2012-08-13 15:13:28 +0900 (bb3e11b) @@ -0,0 +1,125 @@ +[ + { + "type": "add", + "id": "id1", + "version": 1, + "lang": "en", + "fields": { + "name": "Brazil", + "address": "Shibuya, Tokyo, Japan", + "email_address": "info �� razil.jp", + "age": 1, + "product": ["moritapo","groonga"] + } + }, + { + "type": "add", + "id": "id2", + "version": 1, + "lang": "en", + "fields": { + "name": "Enishi Tech Inc.", + "address": "Sapporo, Hokkaido, Japan", + "email_address": "info �� enishi-tech.com", + "age": 2, + "product": ["nroonga","groonga"] + } + }, + { + "type": "add", + "id": "id3", + "version": 1, + "lang": "en", + "fields": { + "name": "ClearCode Inc.", + "address": "Hongo, Tokyo, Japan", + "email_address": "info �� clear-code.com", + "age": 3, + "product": ["cutter","groonga"] + } + }, + { + "type": "add", + "id": "id4", + "version": 1, + "lang": "en", + "fields": { + "name": "Anaheim Electronics", + "address": "Granada, Moon", + "age": 4, + "product": ["hi-zack","gundam"] + } + }, + { + "type": "add", + "id": "id5", + "version": 1, + "lang": "en", + "fields": { + "name": "Shinsei Industry", + "address": "Earth", + "age": 5, + "product": "valkyrie" + } + }, + { + "type": "add", + "id": "id6", + "version": 1, + "lang": "en", + "fields": { + "name": "Omni Consumer Products", + "address": "Detroit and Delta City, Michigan, United States", + "age": 6, + "product": "robocop" + } + }, + { + "type": "add", + "id": "id7", + "version": 1, + "lang": "en", + "fields": { + "name": "Capsule Corporation", + "address": "West City", + "age": 7, + "product": "time machine" + } + }, + { + "type": "add", + "id": "id8", + "version": 1, + "lang": "en", + "fields": { + "name": "Stark Industries", + "address": "United States", + "age": 8, + "product": "iron man" + } + }, + { + "type": "add", + "id": "id9", + "version": 1, + "lang": "en", + "fields": { + "name": "Umbrella Corporation", + "address": "Tokyo, Japan", + "age": 9, + "product": "tyrant" + } + }, + { + "type": "add", + "id": "id10", + "version": 1, + "lang": "en", + "fields": { + "name": "U.S. Robots and Mechanical Men", + "address": "New York, United States", + "age": 10, + "product": ["ndr114","spd13"] + } + } +] -------------- next part -------------- HTML����������������������������...Download