mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Need a table to store data for all elections
Solution: Created the `elections` table with secondary_index `election_id`
This commit is contained in:
parent
b468504bfc
commit
e7dae7db72
@ -47,6 +47,7 @@ def create_indexes(conn, dbname):
|
|||||||
create_utxos_secondary_index(conn, dbname)
|
create_utxos_secondary_index(conn, dbname)
|
||||||
create_pre_commit_secondary_index(conn, dbname)
|
create_pre_commit_secondary_index(conn, dbname)
|
||||||
create_validators_secondary_index(conn, dbname)
|
create_validators_secondary_index(conn, dbname)
|
||||||
|
create_elections_secondary_index(conn, dbname)
|
||||||
|
|
||||||
|
|
||||||
@register_schema(LocalMongoDBConnection)
|
@register_schema(LocalMongoDBConnection)
|
||||||
@ -133,6 +134,11 @@ def create_validators_secondary_index(conn, dbname):
|
|||||||
conn.conn[dbname]['validators'].create_index('height',
|
conn.conn[dbname]['validators'].create_index('height',
|
||||||
name='height',
|
name='height',
|
||||||
unique=True,)
|
unique=True,)
|
||||||
conn.conn[dbname]['validators'].create_index('election_id',
|
|
||||||
|
|
||||||
|
def create_elections_secondary_index(conn, dbname):
|
||||||
|
logger.info('Create `elections` secondary index.')
|
||||||
|
|
||||||
|
conn.conn[dbname]['elections'].create_index('election_id',
|
||||||
name='election_id',
|
name='election_id',
|
||||||
unique=True,)
|
unique=True,)
|
||||||
|
|||||||
@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# Tables/collections that every backend database must create
|
# Tables/collections that every backend database must create
|
||||||
TABLES = ('transactions', 'blocks', 'assets', 'metadata',
|
TABLES = ('transactions', 'blocks', 'assets', 'metadata',
|
||||||
'validators', 'pre_commit', 'utxos')
|
'validators', 'elections', 'pre_commit', 'utxos')
|
||||||
|
|
||||||
VALID_LANGUAGES = ('danish', 'dutch', 'english', 'finnish', 'french', 'german',
|
VALID_LANGUAGES = ('danish', 'dutch', 'english', 'finnish', 'french', 'german',
|
||||||
'hungarian', 'italian', 'norwegian', 'portuguese', 'romanian',
|
'hungarian', 'italian', 'norwegian', 'portuguese', 'romanian',
|
||||||
|
|||||||
@ -24,7 +24,7 @@ def test_init_creates_db_tables_and_indexes():
|
|||||||
collection_names = conn.conn[dbname].collection_names()
|
collection_names = conn.conn[dbname].collection_names()
|
||||||
assert set(collection_names) == {
|
assert set(collection_names) == {
|
||||||
'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'pre_commit',
|
'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'pre_commit',
|
||||||
'validators'
|
'validators', 'elections'
|
||||||
}
|
}
|
||||||
|
|
||||||
indexes = conn.conn[dbname]['assets'].index_information().keys()
|
indexes = conn.conn[dbname]['assets'].index_information().keys()
|
||||||
@ -44,7 +44,10 @@ def test_init_creates_db_tables_and_indexes():
|
|||||||
assert set(indexes) == {'_id_', 'pre_commit_id'}
|
assert set(indexes) == {'_id_', 'pre_commit_id'}
|
||||||
|
|
||||||
indexes = conn.conn[dbname]['validators'].index_information().keys()
|
indexes = conn.conn[dbname]['validators'].index_information().keys()
|
||||||
assert set(indexes) == {'_id_', 'height', 'election_id'}
|
assert set(indexes) == {'_id_', 'height'}
|
||||||
|
|
||||||
|
indexes = conn.conn[dbname]['elections'].index_information().keys()
|
||||||
|
assert set(indexes) == {'_id_', 'election_id'}
|
||||||
|
|
||||||
|
|
||||||
def test_init_database_fails_if_db_exists():
|
def test_init_database_fails_if_db_exists():
|
||||||
@ -78,7 +81,7 @@ def test_create_tables():
|
|||||||
|
|
||||||
collection_names = conn.conn[dbname].collection_names()
|
collection_names = conn.conn[dbname].collection_names()
|
||||||
assert set(collection_names) == {
|
assert set(collection_names) == {
|
||||||
'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'validators',
|
'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'validators', 'elections',
|
||||||
'pre_commit'}
|
'pre_commit'}
|
||||||
|
|
||||||
|
|
||||||
@ -116,6 +119,10 @@ def test_create_secondary_indexes():
|
|||||||
assert index_info['utxo']['key'] == [('transaction_id', 1),
|
assert index_info['utxo']['key'] == [('transaction_id', 1),
|
||||||
('output_index', 1)]
|
('output_index', 1)]
|
||||||
|
|
||||||
|
indexes = conn.conn[dbname]['elections'].index_information()
|
||||||
|
assert set(indexes.keys()) == {'_id_', 'election_id'}
|
||||||
|
assert indexes['election_id']['unique']
|
||||||
|
|
||||||
indexes = conn.conn[dbname]['pre_commit'].index_information()
|
indexes = conn.conn[dbname]['pre_commit'].index_information()
|
||||||
assert set(indexes.keys()) == {'_id_', 'pre_commit_id'}
|
assert set(indexes.keys()) == {'_id_', 'pre_commit_id'}
|
||||||
assert indexes['pre_commit_id']['unique']
|
assert indexes['pre_commit_id']['unique']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user