TypeORM generates migrations with db name - database

I need to generate the migration with TypeORM and it does it with this command:
npm run typeorm migration:generate -n test
but the problem is that it generates the migrations that include the DB name
await queryRunner.query(`CREATE TABLE \`testdb\`.\`lbs_user\` (\`id\` char(36) NOT ...
can I somehow remove "testdb"?
this is the config file
{
"type": "mysql",
"host": conf.env.migrationDatabase.host,
"port": conf.env.migrationDatabase.port,
"username": conf.env.migrationDatabase.username,
"password": conf.env.migrationDatabase.password,
"database": conf.env.migrationDatabase.dbName, //the database name is -> testdb
"entityPrefix": conf.env.database.entityPrefix,
"synchronize": false,
"migrationsTableName": `${conf.env.database.entityPrefix}migrations`,
"entities": ["src/modules/db/entities/**/*.entity.ts"],
"migrations": ["src/migrations/**/*.ts"],
"cli": {
"migrationsDir": "src/migrations",
}
}
Entity declaration:
#Entity("user")
export class UserEntity {
#PrimaryColumn({ generated: "uuid" })
id: string;
#Column({
unique: true,
})
email: string;

In the end, it appeared that I was using an old version of typeorm. upgraded to version 0.2.38 and no database name is generated anymore.

Related

Using Volttron aggregation agent

I'm trying to get the aggregate agent to work with timescale db.
https://volttron.readthedocs.io/en/main/developing-volttron/developing-agents/specifications/aggregate.html
I have a file aggregation.config
{
"connection": {
"type": "postgresql",
"params": {
"dbname": "volttrondb",
"host": "127.0.0.1",
"port": 5432,
"user": "user",
"password": "password",
"timescale_dialect": true
}
},
"aggregations":[
# list of aggregation groups each with unique aggregation_period and
# list of points that needs to be collected
{
"aggregation_period": "1h",
"use_calendar_time_periods": true,
"utc_collection_start_time":"2016-03-01T01:15:01.000000",
"points": [
{
"topic_names": ["campus/building/fake/EKG_Cos", "campus/building/fake/EKG_Sin"],
"aggregation_topic_name":"campus/building/fake/avg_of_EKG_Cos_EKG_Sin",
"aggregation_type": "avg",
"min_count": 2
}
]
}
]
}
And run the following command
vctl install services/core/SQLAggregateHistorian/ --tag aggregate-historian -c config/aggregation.config --start
It starts correctly - the vctl status shows it running and there are no errors in the log.
I do not see the point campus/building/fake/avg_of_EKG_Cos_EKG_Sin in the topics table.
Any suggestions?

Sync incompatible role error message in MongoDB App Services even though sync seems to work

I have a Flexible Sync app in MongoDB App Services (formerly MongoDB Realm).
The main model object is an Activity, which should be readable and writable by its owner, but also read-only by a supervisor.
These are the sync roles I have set up:
{
"rules": {
"Activity": [
{
"name": "owner_supervisor_activity_permission",
"applyWhen": {},
"read": {
"$or": [
{
"ownerID": "%%user.id"
},
{
"supervisorID": "%%user.id"
}
]
},
"write": {
"ownerID": "%%user.id"
}
}
]
},
"defaultRoles": [
{
"name": "owner-read-write",
"applyWhen": {},
"read": {
"ownerID": "%%user.id"
},
"write": {
"ownerID": "%%user.id"
}
}
]
}
Although sync seems to work just fine, I get the following error message in the logs for both roles:
Using sync incompatible role "owner_supervisor_activity_permission" for table "Activity". this role will default to deny all access. consider changing this role to be sync compatible (ProtocolErrorCode=201)
I do not know what to do here and I’m wondering if it could be a bug.
Do I need to set the per-collection rules? I thought sync roles overrode those.
Is it a matter of using the applyWhen field?
Thanks

How to log with Serilog to Oracle using appsettings.json?

I'm working on a project where I'm converting an application's database from MSSqlServer to Oracle. I'm using Serilog for the logging, and the Serilog.Sinks.Oracle project for further help.
This is the program.cs code for my MSSQLServer implementation:
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
This is a snippet of the appsettings.json code also for the MSSQLServer implementation (the rest not shown is the implementation of custom columns):
{
"AllowedHosts": "*",
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "connString",
"schemaName": "dbo",
"tableName": "TestLog5",
"autoCreateSqlTable": false,
How would I go about recycling this code to change it to work with Oracle? The Serilog.Sinks.Oracle project gives instructions on how to implement it from program.cs, but I really need the configuring to come from appsettings.json.
Basically this possibility seems not to exist.
You can create an extension method like this :
public static LoggerConfiguration Oracle(this LoggerSinkConfiguration loggerConfiguration, string connectionString)
{
var sink = new BatchLoggerConfiguration()
.WithSettings(connectionString)
.UseBurstBatch()
.CreateSink();
return loggerConfiguration.Sink(sink);
}
Arguments of your extension method have to correspond to json properties under Args property.
Name in json should correspond to your extension method name.
Sample configuration file :
"Serilog": {
"Using": [
"Serilog.Sinks.File",
"<your assembly name>"
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "..output-.log",
"rollingInterval": "Day",
"fileSizeLimitBytes": "10485760"
}
},
{
"Name": "Oracle",
"Args": {
"connectionString": "Data Source=xxxx"
}
}

LoopBack AngularJS extending User model

i'm facing some problems when using an extended user model in my AngularJS application.
here is my user.json:
{
"name": "user",
"base": "User",
"strict": false,
"idInjection": true,
"properties": {
"clientType": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": []
}
here is my model-config.json:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
]
},
"User": {
"dataSource": "mongo"
},
"AccessToken": {
"dataSource": "mongo",
"public": false
},
"ACL": {
"dataSource": "mongo",
"public": false
},
"RoleMapping": {
"dataSource": "mongo",
"public": false
},
"Role": {
"dataSource": "mongo",
"public": false
},
"Store": {
"dataSource": "mongo",
"public": true
},
"user": {
"dataSource": "mongo",
"public": true
}
}
this is my UserCtrl.js
angular.module('app.controllers.user', [])
.controller('UserCtrl', ['user', function (user) {
var vm = this;
vm.addUser = function () {
user.create({
firstName: vm.firstName,
lastName: vm.lastName,
email: vm.email,
password: vm.password,
userType: 'customer'
})
.$promise
.then(function (c) {
console.log('added user: ' + c.email);
});
};
}])
i'm getting the following error:
Error: [$injector:unpr] Unknown provider: userProvider <- user <- UserCtrl
if i use 'User' instead of 'user' it works, but it doesn't use my extended user-model with the specified ACL (READ for everyone)
i've read that you can specify var myUser = app.model.user to make sure that LoopBack uses the extended model. but i don't know how to do that in AngularJS since i specify the model as function parameter in the controller..
can you tell me how to use my extended user model within my AngularJS app?
thanks in advance!!
Do you have your user model generated inside Angular client library? If your application works when you use loopback auto-generated "User" model, then my best guess is that you have created your extended model "user", after you initially generated your angular services. If you are not using grunt task then you should regenerate angular services to update file with all changes and new models that you added since you last time generated the file.
Use lb-ng command to do it. As documentation suggests
For example, if your application has the standard LoopBack project layout, then in the /client sub-directory, enter these commands:
$ mkdir js
$ lb-ng ../server/server.js js/lb-services.js
You can find more information on the following link
http://docs.strongloop.com/display/public/LB/AngularJS+JavaScript+SDK
You need to define a Service, Factory, Provider, Value or Constant called 'user' in order for the service to be injectable in your controller. I do not see either of these in your post.
My suggestion is, if your extended user model is an instance of a class, then use a service:
app.service('user', fn);
If your extended user model is an object literal in JSON format, then use a factory:
app.factory('user', function() { return { ... }; });

How do I create a correct hasOne relation between two objects with loopback and angular

I've recently started to code in angular as the frontend code and was planning to use loopback (www.loopback.io) as my backend (with a mongodb for my storage).
Now, as a basic idea I'm just creating a login form and register form and will go on from there. Yet, I can't seem to get my models correct, especially the relations between them.
I'd like a user model for the basic username/password stuff, and a person model where I can store more info like firstname, lastname, and more.
I'm currently using the "default" User model that you get out of the box and created a person model with the needed properties.
What I can't get correct though, is the link between the two (a one to one relation, so the HasOne relation).
These are my models:
user.json
{
"name": "user",
"base": "User",
"idInjection": true,
"properties": {},
"validations": [],
"relations": {
"person": {
"type": "hasOne",
"model": "Person",
"foreignKey": "id"
}
},
"acls": [],
"methods": []
}
person.json
{
"name": "Person",
"plural": "Person",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"FirstName": {
"type": "string",
"required": true
},
"LastName": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
my register function
(I'm using the automaticaly generated lb-services file you can extract with the angular SDK provided by loopback, that's why you just see stuff like "User.create" in stead of a "real" api call)
function register(email, password, firstname, lastname) {
var usr = User.create({
email: email,
password: password
}).$promise;
var prs = usr.person.create({
firstname: firstname,
lastname: lastname
});
return usr;
}
There's bound to be a bunch of stuff wrong here, I just don't know what. The user gets created in the database, yet I can't seem to instantly also create a "person" object and link that to the newly created user.
Any help is appreciated, cause I can't seem to find that many resources online that use angular and loopback with the generated lb-services file...
Seems that you reference undefined property person of usr instance.
Create person using User resource, in success callback:
function register(email, password, firstname, lastname) {
var usr = User.create({
email: email,
password: password
}, function() {
User.person.create({ userId: usr.id }, {
firstname: firstname,
lastname: lastname
}, function(person) {
console.log('Persone created:', persone)
})
});
return usr;
}

Resources