How to put meta into cube's schema when i use playground/generate-schema to generate schema automatically? - cube.js

The cubejs is great.
I can use api which is '/playground/generate-schema' to generate schema automatically.It works great.
But now I want to add meta to dimensions like this:
--- before ---
dimensions:{
...
level: {
sql: `level`,
type: `number`
},
...
--- after ---
dimensions:{
...
level: {
sql: `level`,
type: `number`,
meta:{
dict:'alarmlevel'
}
},
...
}
What should I do ?

Related

AWS Amplify/AppSync/DynamoDB - Can I not do a BatchGetItem on a specified key/ secondary index?

Thank you for checking out my question. My case is the following:
I am trying to query (BatchGetItem) a table by the key "clientId", which is also a secondary index. However the response of the server is The provided key element does not match the schema (Service: DynamoDb, Status Code: 400, Request ID: ..., Extended Request ID: null). I used Amazon tutorial-dynamodb-batch as example and I thought I was able to get items based on a field of choice as in the batchgetitem-retrieve-readings example.
My request.vtl code is:
#set($clientPermissions = $ctx.stash.clientPermissions)
#if( $util.isList($clientPermissions) )
#set($ids = [])
#foreach($item in $clientPermissions)
#set($map = {})
$util.qr($map.put("clientId", $util.dynamodb.toString($item.clientId)))
$util.qr($ids.add($map))
#end
{
"version" : "2018-05-29",
"operation" : "BatchGetItem",
"tables" : {
"Organization-u2zvdkpmrvbovku7cnyivjcaqq-develop": {
"keys": $util.toJson($ids),
"consistentRead": true
}
}
}
#else
#return
#end
This is my table schema:
##
## Organizations
##
type Organization
#model(subscriptions: null)
##auth(rules: [ { allow: groups, groups: ["Admin"] } ])
#key(name: "byClient", fields: ["clientId"])
{
id: ID!
name: String!
parents: [OrganizationRelation] #connection(keyName: "byChild", fields: ["id"])
children: [OrganizationRelation] #connection(keyName: "byParent", fields: ["id"])
clientId: ID!
client: Client #connection(fields: ["clientId"])
}
Hope someone has any experience with this. I am really stuck if I can't fix this.
Thank you in advance.
Best regards,
Jens

AWS CDK unit test failing - jest ts

I created an AWS CDK app in Typescript that creates an IAM Role. Here is my code:
export class AccountCreatorIamRoleStack extends cdk.Stack {
public create(): iam.Role {
const iamRole = some logic to create iam role goes here;
return iamRole;
}
}
I have confirmed that this code works by creating an IAM Role like this:
var roleCreator = new AccountCreatorIamRoleStack(app, 'AccountCreatorIamRoleStack');
roleCreator.create();
However, when I run this jest unit test:
test('Test IAM Role Created', () => {
const app = new cdk.App();
// WHEN
var stack = new AccountCreatorIamRoleStack(app, 'TestAccountCreatorIamRoleStack').create()
// THEN
expectCDK(stack).to(haveResource("AWS::IAM::Role"));
});
It fails with the following error:
FAIL test/account-creation-iam-role-stack.test.ts
✕ Test IAM Role Created (32 ms)
● Test IAM Role Created
None of 0 resources matches resource 'AWS::IAM::Role' with {
"$anything": true
}.
16 | var stack = new AccountCreatorIamRoleStack(app, 'TestAccountCreatorIamRoleStack').create()
17 | // THEN
> 18 | expectCDK(stack).to(haveResource("AWS::IAM::Role"));
| ^
19 | });
at HaveResourceAssertion.assertOrThrow (node_modules/#aws-cdk/assert/lib/assertions/have-resource.ts:100:13)
at StackInspector._to (node_modules/#aws-cdk/assert/lib/inspector.ts:25:15)
at StackInspector.to (node_modules/#aws-cdk/assert/lib/inspector.ts:15:14)
at Object.<anonymous> (test/account-creation-iam-role-stack.test.ts:18:20)
I can see it is pointing to something on that line, but what exactly is it pointing to that it thinks is an error? Thoughts?
Your code is making an assertion that AWS::IAM::Role has "VisibilityTimeout": 300 but it doesn't have such attribute. It should pass for haveResource("AWS::IAM::Role") alone (without additional properties) when your code is actually creating it.
Here are the current attributes on IAM Role: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html
{
"Type" : "AWS::IAM::Role",
"Properties" : {
"AssumeRolePolicyDocument" : Json,
"Description" : String,
"ManagedPolicyArns" : [ String, ... ],
"MaxSessionDuration" : Integer,
"Path" : String,
"PermissionsBoundary" : String,
"Policies" : [ Policy, ... ],
"RoleName" : String,
"Tags" : [ Tag, ... ]
}
}```
What you should use, when just trying to identify if a resource is created, is countResources:
expectCDK(stack).to(countResources('AWS::IAM::Role', 1));
When using haveResource it is expecting an object to compare it to. Since you are not providing an object to compare, this will fail. Also, this check is pointless if you are not checking the object expectancy and you should use countResources instead.
This is an example of using haveResource for object expectancy:
test('Verify IAM AssumeRole', () => {
expectCDK(stack).to(
haveResource('AWS::IAM::Role', {
AssumeRolePolicyDocument: {
Statement: [
{
Action: 'sts:AssumeRole',
Effect: 'Allow',
Principal: {
Service: [
'codestar.amazonaws.com',
],
},
},
],
},
RoleName: 'some-name-for-assume-role',
}),
);
});
You also have haveResourceLike which can be helpful for partials or you can even do more with using arrayWith(objectLike({...}))
An example of this:
// ECR Auth token Access
expectCDK(stack).to(
haveResourceLike('AWS::IAM::Policy', {
PolicyDocument: {
Statement: arrayWith(
objectLike({
Action: 'ecr:GetAuthorizationToken',
Effect: 'Allow',
Resource: '*',
}),
),
},
}),
);
As for your issue where it is pointing to the stack, this is because the stack has no matching resources for what you are expecting. It points to the stack as this is what is being tested and it's there (a bit misleadingly) to indicate that the stack may be the issue. Although it seems your issue is just that you are using the wrong method to test with.
Also, the error messages need a bit of work. They really aren't that helpful and many are misleading. Numerous times I have run into:
TypeError: Converting circular structure to JSON
When using object expectancy. Normally this is because a value does not match but the error is completely useless... I cannot count how many times this has caused me a headache...
Reference: https://www.npmjs.com/package/#aws-cdk/assert

Loopback4 Model Definition options for mongodb collection name

I am using loopback 4 and trying to configure the Model annotation with properties to configure how the collection is created in Mongo.
I have a Model called say Client and I want the collection in Mongo to be called Clients. The cross over with documentation is confusing, as they reference the properties from v3 in v4 docs.
I have tried this:
import {Entity, model, property} from '#loopback/repository';
#model({
settings: {strict: false},
name: 'client',
plural: 'clients',
options: {
mongodb: {
collection: 'clients',
},
},
})
export class Client extends Entity {
#property({
type: 'string',
id: true,
defaultFn: 'uuidv4',
index: true,
})
id: string;
#property({
type: 'string',
required: true,
})
name: string;
#property({
type: 'string',
})
code?: string;
constructor(data?: Partial<Client>) {
super(data);
}
}
With no Joy, still creates the collection as the Class name Client
This is from 2014, but perhaps it still works. Try not putting the mongodb key options
settings: {strict: false},
name: 'client',
plural: 'clients',
mongodb: {
collection: 'clients',
},
Please note that all model settings must be nested inside settings property, LB4 does not support top-level settings yet.
Also the option plural is not used by LB4 as far as I know.
I think the following code should work for you:
#model({
name: 'client',
settings: {
strict: false
mongodb: {
collection: 'clients',
},
},
})
export class Client extends Entity {
// ...
}
UPDATE: I opened a GitHub issue to discuss how to make #model decorator easier to use for users coming from LB3. See https://github.com/strongloop/loopback-next/issues/2142

Doctrine sortable extension in symfony3 - Error: Not Null

I try to use the doctrine extension sortable via the gedmo extension. I installed the gedmo-package with composer and followed the instructions of the installation in symfony2. I use yaml-files as mapping-information for doctrine.
My yaml-file:
AppBundle\Entity\Picture:
type: entity
table: pictures
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
[...]
type:
type: string
length: 20
position:
type: string
gedmo:
sortable:
groups: [type]
The field position did have the type int, but I also tried string, because that should cause an error by the yaml-driver of the sortable-extension (InvalidMappingException).
But the error I always get is Integrity constraint violation: 19 NOT NULL constraint failed: pictures.position. But in all examples of the sortable extension there is no need to specifically set a value for the position-field or to allow null in the yaml-file. Also I suppose, that the InvalidMappingException should occur before the NOT NULL Exception.
Because of this I think that the extension is not even used.
The config-files I use:
My config.yml file:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: doctrine_extensions.yml}
[...]
My doctrine_extensions.yml file:
services:
# KernelRequest listener
gedmo.listener.sortable:
class: Gedmo\Sortable\SortableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "#annotation_reader" ] ]
i know this question has been asked ages ago, but in case it can help: depending on versions you're using, you can try this syntax (this worked for me):
#Resources/config/doctrine/Entity.orm.yml
[...]
fields:
position:
type: integer
gedmo:
- sortablePosition
and if you need to sort by group, you need to add this into your relation (here is full example):
manyToOne:
parent:
targetEntity: Parent
inversedBy: children
joinColumn:
name: parent_id
referencedColumnName: id
onDelete: cascade
gedmo:
- sortableGroup

Lots of Fun with Doctrine ORM and Silex - Doctrine MappingException: Class does not exist

I am using the DflyDevDoctrineORMServicProvider with Silex. I have created a simple model as a proof of concept.
I am able to build the model (PHP classes) from my Yml files- but when I try to generate the schema, and populate the database etc - it all falls apart, and I get the error message:
[Doctrine\Common\Persistence\Mapping\MappingException]
Class 'DistrictType' does not exist
I must admit, I am struggling with PHP Namespaces and how they relate to Doctrine Mappings and file locations - I'm sure the problem is likely to be related to this confusion.
I will briefly describe my directory layout and the configuration files I am using - hopefully, someone maybe able to spot where I am going wrong:
Directory layout
|
|---src
| app.php // app variable cration, autoloading etc ..
| registration.php // service registration etc ..
|---Entity // Generated models go here
|---Resources
| |-- mappings // YamL model definitions here ...
|
|---config
| cli-config.php
| config.yml
|
|---web
index.php // imports app.php
composer.json
.htaccess
Snippet from registration.php
$app->register(new DoctrineOrmServiceProvider, array(
"orm.proxies_dir" => __DIR__.'/../cache/doctrine/proxy',
"orm.em.options" => array(
"mappings" => array(
// Using actual filesystem paths
array(
"type" => "yml",
"namespace" => "Entity",
"path" => __DIR__."/Resources/mappings"
),
),
),
));
// Setup entity manager (Possible Hack)
$paths = array($app['orm.em.options']['mappings'][0]['path']);
$config = Setup::createYAMLMetadataConfiguration($paths, $app['debug']);
$app['orm.em'] = EntityManager::create($app['db.options'], $config);
cli-config.php
<?php
// ...
$app = require_once __DIR__.'/../src/app.php';
$isDevMode = $app['debug'];
$paths = array($app['orm.em.options']['mappings'][0]['path']);
$config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($app['db.options'], $config);
$commands = array(
new \UseAllFive\Command\LoadDataFixturesDoctrineCommand(),
);
return ConsoleRunner::createHelperSet($entityManager);
Now here are the models:
District.dcm.yml
District:
type: entity
table: pac_district
repositoryClass: DistrictRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 64
nullable: false
manyToOne:
region:
targetEntity: Region
joinColumn:
name: region_id
referencedColumnName: id
onDelete: RESTRICT
onUpdate: CASCADE
district_type:
targetEntity: DistrictType
joinColumn:
name: district_type_id
referencedColumnName: id
onDelete: RESTRICT
onUpdate: CASCADE
uniqueConstraints:
uidx_district_name:
columns: [name]
DistrictType.dcm.yml
DistrictType:
type: entity
table: pac_district_type
repositoryClass: DistrictTypeRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 64
nullable: false
uniqueConstraints:
uidx_district_type_name:
columns: [name]
Region.dcm.yml
Region:
type: entity
table: pac_region
repositoryClass: RegionRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 64
nullable: false
uniqueConstraints:
uidx_region_name:
columns: [name]
composer.json
{
"require": {
"silex/silex": "2.0.*#dev",
"symfony/yaml": "2.6.7",
"doctrine/dbal": "~2.2",
"doctrine/orm": ">=2.1",
"dflydev/doctrine-orm-service-provider": "2.0.*#dev"
},
"autoload": {
"psr-0": {"Controller": "src/"},
"psr-0": {"Entity": "src/"}
}
}
These are the results of the following commands:
root#yourbox:~/path/to/project$ vendor/bin/doctrine orm:generate-entities src/Entity/
Processing entity "Region"
Processing entity "DistrictType"
Processing entity "District"
Entity classes generated to "/path/to/project/src/Entity"
root#yourbox:~/path/to/project$ vendor/bin/doctrine orm:schema-tool:create
[Doctrine\Common\Persistence\Mapping\MappingException]
Class 'DistrictType' does not exist
I have struggled with this for two days straight - and can't see what I'm doing wrong - can anyone spot what Imay be doing wrong?
It is quite simple actually. What you are doing wrong is - autoloading files. The way your composer file is configured now, it will not autoload the entity files and the schema creation will fail.
Modify your composer autoload section by passing an empty string as first parameter, and add Entity to the path, like this:
"autoload": {
"psr-0": {"Controller": "src/"},
"psr-0": {"": "src/Entity/"}
}
Then run composer update and you would be able to generate your entities. On a side note, currently I am developing a small project with Silex as well, and I would strongly recommend you switch to using Namespaces.
Hello #Artamiel that fixed my problem, it was a combination of adding the autoload in composer and fixing the namespace, I mean my autoload now has:
"psr-0": {"Entity": "config/doctrine/"}
And as I have defined the namespace as Entity created such a folder and move the entities there, and finally I am up and running. Thanks