Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ee668bc
wip: cassandra templates
Oct 20, 2020
192ed6d
feat: add reusable include for generic fieldResolvers
Oct 20, 2020
50c7507
feat: cassandra support
Oct 26, 2020
2c98d8f
refactor: change cassandra-fieldMutations include name to be consistent
Oct 26, 2020
2359b95
feat: cassandra support
Oct 26, 2020
57b946f
refactor: use Connection for to_one fieldResolvers
Nov 2, 2020
db632b6
chore: add to_one fieldResolver include
Nov 2, 2020
e4814ac
wip: cassandra-integration
Nov 2, 2020
ba00de2
feat: add cassandra files for docker
Nov 3, 2020
785c22e
fix: correctly call readAllCursor in DDM
Nov 3, 2020
b7da2d8
refactor: export cassandra model / adpater class directly and use gen…
Nov 3, 2020
f6273cd
wip: cassandra integration tests
Nov 10, 2020
fc038a9
Merge branch 'master' into issue34-cassandra
Nov 19, 2020
8f73641
wip: cassandra integration tests
Nov 19, 2020
4b7d9a5
feat: separate cassandra integration test files
Nov 20, 2020
8b60672
add 2 cassandra models (instant/incident)
Nov 20, 2020
7fef338
fix: cassandra migrations use getConnection for the Client
Nov 20, 2020
5c47648
fix: cassnadra adapter + model templates#
Nov 20, 2020
afdd9ee
feat: cassandra integration tests
Nov 23, 2020
518ae23
feat: models for cassandra integration tests
Nov 23, 2020
424c4ab
wip: cassandra integration template fixes
Nov 23, 2020
a253f6e
fix: get only editable Attributes for add and update
Nov 25, 2020
b44186e
feat: add foreignKey Array types to migrations
Nov 25, 2020
002f0b2
feat: cassandra foreignKey add/remove fieldMutation
Nov 25, 2020
8ca065f
feat: cassandra foreignKey Array resolver field mutation
Nov 25, 2020
1d292a6
fix: cassandra foreign Key arrays
Nov 26, 2020
fe384e4
feat: wip: cassandra array types
Nov 30, 2020
56dbcf0
chore: delete unused toy/walrus cassandra models
Dec 1, 2020
98d02e9
feat: cassandra DateTime -> timestamp
Dec 1, 2020
fe8f45c
feat: cassandra fK-Array + array-type integration tests
Dec 1, 2020
679ca07
chore: cassandra-adapter add/update use prepared statements (same as …
Dec 1, 2020
eb70803
fix: fieldResolver fK-Array check for isArray and length to avoid null
Dec 1, 2020
d0af486
feat: cassandra array-type integration tests
Dec 2, 2020
86ccf02
fix: enclose table names and column names in double qoutes to enable …
Dec 2, 2020
386fe4a
chore: cassandra operatorse: _in -> in, cont -> contains
Dec 8, 2020
c72718e
feat: add search permissions to editor role
Dec 8, 2020
8814a4b
fix: to_one assoc holdsForeignKey, use Connection and return the node
Dec 8, 2020
8995cc4
fix: fix unit tests broken by cassandra implementation so far
Dec 8, 2020
425d4ec
feat: use normal schema/resolver for cassandra models
Dec 9, 2020
780f7df
fix: cassandra ddm use pagination.first not limit
Dec 9, 2020
6b8221d
fix: bulkAssociation enclose tablename to support uppercase
Dec 9, 2020
8766742
fix: cassandra integration-test use 'contains' instead of 'cont'
Dec 9, 2020
e4f8ea8
feat: wip: add cassandra unit tests
Dec 9, 2020
e585c72
Merge branch 'master' into issue34-cassandra
Dec 10, 2020
9c63ed2
feat: add missing cassanda unit tests
Dec 10, 2020
63b6607
fix: JSDOC add benignErrorReporter
Dec 10, 2020
97debf7
feat: add cassandra integration tests to default test run
Dec 10, 2020
150a38b
fix: connection type fieldResolver return empty edges and pageInfo if…
coeit Jan 5, 2021
ebd4d57
remove cassandra paginationInput and pageInfo
coeit Jan 20, 2021
863a64d
feat: support for mongodb
wunderbarr Mar 8, 2021
62e4c62
feat: mongodb integration
wunderbarr Mar 16, 2021
02d4d68
fix: unit test for resolvers (issue 176: empty foreign key array)
wunderbarr Mar 17, 2021
e097805
test: add unit tests for mongodb
wunderbarr Mar 17, 2021
12d965f
test: basic CRUD operations
wunderbarr Mar 19, 2021
024ed1b
test: add integration tests for mongodb and set class name into lower…
wunderbarr Mar 24, 2021
af0128e
Merge branch 'master' into issue34-cassandra
coeit Mar 25, 2021
f920845
fix: store adapter data by using model name instead of adapter name
wunderbarr Mar 25, 2021
f09911c
Merge branch 'issue34-cassandra' into mongodb
wunderbarr Mar 26, 2021
9a5c6ce
refactor: delete schema file for cassandra
wunderbarr Mar 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,540 changes: 968 additions & 572 deletions funks.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions lib/generators-aux.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@

/**
* Get the default database key of a given model.
* @param {string} dataModel data model definition object
*/
exports.getModelDatabase = function (dataModel) {

// Sanity check: storageType is a required property, but database
// should be set only for supported storage types.
const validStorage = {
'sql': 'default-sql',
'sql-adapter': 'default-sql',
}
sql: "default-sql",
"sql-adapter": "default-sql",
cassandra: "default-cassandra",
"cassandra-adapter": "default-cassandra",
mongodb: "default-mongodb",
"mongodb-adapter": "default-mongodb",
};

const storageType = dataModel.storageType.toLowerCase();

const defaultDb = validStorage[storageType];

return dataModel.database || defaultDb || '';

}
return dataModel.database || defaultDb || "";
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"graphql-server-model-codegen": "index.js"
},
"scripts": {
"test-unit": "mocha ./test/mocha_unit_test.js",
"test-unit": "mocha ./test/mocha_unit.test.js",
"test-integration": "bash ./test/testenv_cli.sh"
},
"author": "Science-DB team",
Expand Down
5 changes: 5 additions & 0 deletions test/integration_test_misc/Dockerfile.cassandra
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM cassandra:3.11.6

RUN mkdir -p /home/cassandra/.cassandra && chown -R cassandra /home/cassandra

CMD ["cassandra", "-f"]
7 changes: 7 additions & 0 deletions test/integration_test_misc/animal.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
animal_id,animal_name,category,age,weight,health,birthday,personality
1,Sally1,Dog,3,5.5,true,2017-10-03T10:15:30Z,energetic;enthusiastic
2,Sally2,Dog,3,5.5,true,2017-10-03T10:15:30Z,energetic;enthusiastic
3,Milka1,Cat,2,3.5,true,2017-10-03T10:15:30Z,cute;optimistic
4,Milka2,Cat,2,3.5,true,2017-10-03T10:15:30Z,cute;optimistic
5,Lily1,Pig,1,10.5,true,2017-10-03T10:15:30Z,forgetful;funny
6,Lily2,Pig,1,10.5,true,2017-10-03T10:15:30Z,forgetful;funny
1 change: 1 addition & 0 deletions test/integration_test_misc/cassandra-keyspace.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE KEYSPACE IF NOT EXISTS sciencedb WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};
16 changes: 16 additions & 0 deletions test/integration_test_misc/data_models_storage_config1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,21 @@
"database": "sciencedb_development",
"host": "gql_postgres1",
"dialect": "postgres"
},
"default-mongodb": {
"storageType": "mongodb",
"username": "sciencedb",
"password": "sciencedb",
"database": "sciencedb_development",
"host": "gql_mongodb1",
"port": "27017"
},
"default-cassandra": {
"storageType": "cassandra",
"username": "cassandra",
"password": "cassandra",
"keyspace": "sciencedb",
"host": "cassandra1",
"port": "9042"
}
}
31 changes: 31 additions & 0 deletions test/integration_test_misc/docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,41 @@ services:
networks:
- instance1

gql_mongodb1:
image: mongo
container_name: mongodb1
environment:
- MONGO_INITDB_ROOT_USERNAME=sciencedb
- MONGO_INITDB_ROOT_PASSWORD=sciencedb
- MONGO_INITDB_DATABASE=sciencedb_development
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
ports:
- 27017:27017
networks:
- instance1

gql_cassandra1:
container_name: cassandra1
build:
context: .
dockerfile: Dockerfile.cassandra
volumes:
- ./docker-entrypoint.sh.cassandra:/docker-entrypoint.sh
- ./cassandra-keyspace.cql:/docker-entrypoint-initdb.d/cassandra-keyspace.cql
ports:
- 9042:9042
environment:
- MAX_HEAP_SIZE=256M
- HEAP_NEWSIZE=128M
networks:
- instance1

gql_science_db_graphql_server1:
container_name: server1
depends_on:
- gql_postgres1
- gql_mongodb1
build:
context: .
dockerfile: Dockerfile.graphql_server
Expand Down
105 changes: 105 additions & 0 deletions test/integration_test_misc/docker-entrypoint.sh.cassandra
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
set -e

###############################
# This file was copied from the Cassandra container and modified according to https://stackoverflow.com/a/42698847.
# The modification runs all '.sh' and '.cql' files in the 'docker-entrypoint-initdb.d' folder. This mimics the
# behaviour of e.g. the default postgres container.
###############################

# first arg is `-f` or `--some-option`
# or there are no args
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
set -- cassandra -f "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
find "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra \
\! -user cassandra -exec chown cassandra '{}' +
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $NF != "lo" {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}

# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}

if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

if [ -n "${CASSANDRA_NAME:+1}" ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

_sed-in-place "$CASSANDRA_CONF/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'

for yaml in \
broadcast_address \
broadcast_rpc_address \
cluster_name \
endpoint_snitch \
listen_address \
num_tokens \
rpc_address \
start_rpc \
; do
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
_sed-in-place "$CASSANDRA_CONF/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
_sed-in-place "$CASSANDRA_CONF/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi

for f in docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.cql) echo "$0: running $f" && until cqlsh -f "$f"; do >&2 echo "Cassandra is unavailable - sleeping"; sleep 2; done & ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

exec "$@"
10 changes: 10 additions & 0 deletions test/integration_test_misc/init-mongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
db.createUser({
user: "sciencedb",
pwd: "sciencedb",
roles: [
{
role: "readWrite",
db: "sciencedb_development",
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"model": "animal",
"storageType": "mongodb",
"attributes": {
"animal_id": "String",
"category": "String",
"animal_name": "String",
"age": "Int",
"weight": "Float",
"health": "Boolean",
"birthday": "DateTime",
"personality": "[String]",
"farm_id": "String",
"food_ids": "[String]"
},
"associations": {
"farm": {
"type": "to_one",
"target": "farm",
"targetKey": "farm_id",
"keyIn": "animal",
"targetStorageType": "mongodb",
"label": "farm_name"
},
"food":{
"type": "to_many",
"reverseAssociationType": "to_many",
"target": "food",
"targetKey": "animal_ids",
"sourceKey": "food_ids",
"keyIn": "animal",
"targetStorageType": "mongodb"
},
"unique_tracker":{
"type" : "to_one",
"target" : "tracker",
"targetKey" : "animal_id",
"keyIn": "tracker",
"targetStorageType" : "mongodb"
}
},
"internalId": "animal_id",
"id": {
"name": "animal_id",
"type": "String"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"targetKey" : "country_id",
"keyIn": "capital",
"targetStorageType" : "sql"
},
"incidents": {
"type": "to_many",
"target": "Incident",
"targetKey": "capital_id",
"keyIn": "Incident",
"targetStorageType": "cassandra"
}
},
"internalId": "capital_id"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"model" : "city",
"storageType" : "cassandra",
"attributes" : {
"city_id": "String",
"name": "String",

"intArr": "[Int]",
"strArr": "[String]",
"floatArr": "[Float]",
"boolArr": "[Boolean]",
"dateTimeArr": "[DateTime]",

"river_ids": "[String]"
},
"associations": {
"rivers": {
"type": "to_many",
"target": "river",
"targetStorageType": "sql",
"sourceKey": "river_ids",
"targetKey": "city_ids",
"keyIn": "city",
"reverseAssociationType":"to_many"
}
},
"internalId": "city_id"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"model": "Incident",
"storageType": "cassandra",
"attributes": {
"incident_id": "String",
"incident_description": "String",
"incident_number": "Int",
"capital_id": "String"
},

"associations": {

"instants": {
"type": "to_many",
"target": "Instant",
"targetKey": "incident_assoc_id",
"keyIn" : "Instant",
"targetStorageType": "cassandra"
},
"town": {
"type": "to_one",
"target": "capital",
"targetKey": "capital_id",
"keyIn" : "Incident",
"targetStorageType": "sql"
}

},

"internalId" : "incident_id"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"model": "Instant",
"storageType": "cassandra",
"attributes": {
"instant_id": "String",
"incident_assoc_id": "String",
"year": "Int",
"month": "Int",
"day": "Int",
"hour": "Int",
"minute": "Int"
},

"associations": {

"incident": {
"type": "to_one",
"target": "Incident",
"targetKey": "incident_assoc_id",
"keyIn" : "Instant",
"targetStorageType": "cassandra"
}

},

"internalId" : "instant_id"
}
Loading