Sequelize-cli doesn't do anything - sql-server

I am trying to use sequelize and sequelize-cli to create database schema changes (MSSQL) by using the migration mechanism. But nothing is happening - it looks like it does not find any migration files in the migration folder.
I did the following in a new folder to create a test project:
npm init
[ added relevant packages: sequelize, sequelize-cli, tedious ]
sequelize init
[ here I added the connection information, all to a blank database on Azure SQL ]
sequelize init:models
sequelize init:migrations
sequelize migration:create
I added the following to the created migration file:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('users');
}
};
which is basically just according to the template created by the last sequelize command.
Now I would expect a new table to be created when I run the migrate command:
sequelize db:migrate
But all I get is this:
Sequelize [Node: 0.12.2, CLI: 1.7.4, ORM: 3.5.1]
Loaded configuration file "config/config.json".
Using environment "development".
Using gulpfile /usr/local/lib/node_modules/sequelize-cli/lib/gulpfile.js
Finished 'db:migrate' after 161 ms
which means it did not find any migration files. No table has appeared in the database and no sequelizeMeta table was created.
What's wrong?

You can try creating a .sequelizerc file in the root directory to point it to the correct migrations folder:
var path = require('path');
module.exports = {
'config': path.resolve('path/to/folder', 'config/config.json'),
'migrations-path': path.resolve('path/to/folder', 'migrations'),
'models-path': path.resolve('path/to/folder, 'models')
}
Run sequelize init after creating file

Related

Phpstan doctrine database connection error

I'm using doctrine in a project (not symfony). In this project I also use phpstan, i installed both phpstan/phpstan-doctrine and phpstan/extension-installer.
My phpstan.neon is like this:
parameters:
level: 8
paths:
- src/
doctrine:
objectManagerLoader: tests/object-manager.php
Inside tests/object-manager.php it return the result of a call to a function that return the entity manager.
Here is the code that create the entity manager
$database_url = $_ENV['DATABASE_URL'];
$isDevMode = $this->isDevMode();
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
[$this->getProjectDirectory() . '/src'],
$isDevMode,
$proxyDir,
$cache,
$useSimpleAnnotationReader
);
// database configuration parameters
$conn = [
'url' => $database_url,
];
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
When i run vendor/bin/phpstan analyze i get this error:
Internal error: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "postgres_db" to address: nodename nor servname provided, or not known
This appear because i'm using docker and my database url is postgres://user:password#postgres_db/database postgres_db is the name of my database container so the hostname is known inside the docker container.
When i run phpstan inside the container i do not have the error.
So is there a way to run phpstan outside docker ? Because i'm pretty sure that when i'll push my code the github workflow will fail because of this
Do phpstan need to try to reach the database ?
I opened an issue on the github of phpstan-doctrine and i had an answer by #jlherren that explained :
The problem is that Doctrine needs to know what version of the DB server it is working with in order to instantiate the correct AbstractPlatform implementation, of which there are several available for the same DB vendor (e.g. PostgreSQL94Platform or PostgreSQL100Platform for postgres, and similarly for other DB drivers). To auto-detect this information, it will simply connect to the DB and query the version.
I just changed my database url from:
DATABASE_URL=postgres://user:password#database_ip/database
To:
DATABASE_URL=postgres://user:password#database_ip/database?serverVersion=14.2

firebase cloud functions: cannot read property 'environment' of undefined

am getting this error while I'm trying to deploy to a new firebase project using
firebase deploy --only functions command. I have two projects in use, one dev and one prod, I was working on prod and deploy worked well now too but when I added this project dev the deploying keeps working well in prod but in this new project dev no. I instead get this error:
Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'environment' of undefined
at Object. (/home/projectId/Bitbucket/project-backend/functions/lib/db.js:6:35)
I added the key and eveything in cert/dev/firebase-dev.json in order to work.
The file db.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
const admin = require("firebase-admin");
const functions = require("firebase-functions");
const dir = functions.config().app.environment;
const certFile = `firebase-${dir}.json`;
//using admin SDK
const serviceAccount = require(__dirname + `/../cert/${dir}/${certFile}`);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
.....
Any Idea? Thanks.
Since the error is cannot read property 'environment' of undefined and in your code we see
const dir = functions.config().app.environment;
the error seems to come from the environment configuration.
You should double check that the environment configuration is correctly set in the dev environment/project.
For that, you should use the firebase functions:config:get CLI command, as explained in the doc.

Cannot connect to MS-SQL with react-native

I have used the following package
import MSSQL from 'react-native-mssql';
near the above package on hover, it shows
Could not find a declaration file for module 'react-native-mssql'. 'd:/React Native Apps/Login/node_modules/react-native-mssql/index.android.js' implicitly has an 'any' type.
Try npm install #types/react-native-mssql if it exists or add a new declaration (.d.ts) file containing declare module 'react-native-mssql';
module "d:/React Native Apps/Login/node_modules/react-native-mssql/index.android
I have tried installing as mentioned above but nothing works.
And in code, I am getting an error at below line.
MSSQL.connect(config);
error is following
undeined is not an object (evaluating '_reactNativeMssql2.default.connect')
Please tell me how do I connect to MSSQL with react-native.
react-native-mssql can be installed with npm install --save react-native-mssql
then edit file android/settings.gradle and add:
include ':react-native-mssql'
project(':react-native-mssql').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mssql/android')
as well as file android/app/build.gradle:
dependencies {
...
implementation project(':react-native-mssql')
}
then it can be added to the packages list:
...
import com.stonem.mssql.MSSQLPackage;
...
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
.addPackage(new MSSQLPackage())
...
);
}
and then connected:
import MSSQL from 'react-native-mssql';
...
let config = {
server: '192.168.1.1', // ip address of the mssql database
username: 'sa', // username to login to the database
password: 'password', // password to login to the database
database: 'admin', // the name of the database to connect to
port: 1234 // OPTIONAL, port of the database on the server
}
MSSQL.connect(config);
an example for a SELECT query:
let query = 'SELECT TOP * FROM USERS'
MSSQL.executeQuery(query);
and one for an UPDATE query:
let query = 'UPDATE USERS SET Active=0'
MSSQL.executeUpdate(query);
make sure to call MSSQL.close(); once the connection isn't required anymore.
You could use "react-native link react-native-mssql" in the command prompt after using "cd Project_Name" to fix the issue, if 'Could not find a declaration file for module 'react-native-mssql' was your issue all along.

Dynamically Loading Plugin Configuration Files in CakePHP 3

Question: How do I load a configuration file from a Plugin/config Directory?
Demo Project: https://github.com/CakePHPKitchen/CakeDC-Users-Permissions-Example
I am using CakeDC/users plugin and it has a permissions.php file that it loads the RBAC permissions from. From what I can tell, it either loads the default permissions file that is in the user plugin's config folder OR it loads the permissions.php file from the app/config folder.
Now for my app skeleton I have a bunch of permissions in the app/config/permissions.php, however, I do not want to modify that file as I will be doing git pulls from the upstream repo and I would like to avoid conflicts.
So what I would like to do is, in the app skeleton bootstrap
I would like to
foreach(Plugin::loaded() as $plugin) {
$path = Plugin::path($plugin) . 'config/permissions.php';
if(file_exists($path)) {
Configure::load($path, 'default', true);
}
}
But I am getting the following error....
Error: The application is trying to load a file from the /Users/jlroberts/Projects/JeffreyLRobertsCom/CakePHPKitchen/PluginDemos/plugins/SharpAgent/config/permissions plugin.
Make sure your plugin /Users/jlroberts/Projects/JeffreyLRobertsCom/CakePHPKitchen/PluginDemos/plugins/SharpAgent/config/permissions is in the /Users/jlroberts/Projects/JeffreyLRobertsCom/CakePHPKitchen/PluginDemos/plugins/ directory and was loaded.
Any ideas on how I can load the permissions.php file from the Plugin/config directory?
EDITED: You can load permissions.php file from the Plugin as it is doing now, but change the contents of permissions.php to preserve existing permissions defined in configuration, for example:
config/permissions.php
$permissions = [
// add your app permissions here
[
// ...
],
];
// there are more permissions in this config key, defined across your plugins
$morePermissions = \Cake\Core\Configure::read('MyPermissions');
$allPerms = array_merge($permissions, $morePermissions);
return ['CakeDC/Auth.permissions' => $allPerms];
Then inside each plugin you could have:
YOUR_PLUGIN/config/bootstrap.php
$permissions = \Cake\Core\Configure::read('MyPermissions');
$someMorePermissions = [
[
// permissions injected into the app from this plugin
]
];
$permissions = array_merge((array)$permissions, $someMorePermissions);
\Cake\Core\Configure::write('MyPermissions', $permissions);
Allowing each plugin to dynamically inject/manage permissions into the app.
I've created a c9.io environment with this code here https://ide.c9.io/steinkel/users-35-custom-permissions

Grails - logging from Quartz job and Filter

I would like to stock my logs into files:
Here is how I declare my appenders in Config.groovy:
log4j = {
appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
file name: "scraperServiceDetailedLogger",
file: "target/scraperServiceDetailed.log"
file name: "scraperServiceLogger",
file: "target/scraperService.log"
file name: "filterLogger",
file: "target/filter.log"
}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
error scraperServiceDetailedLogger: "grails.app.service.personalcreditcomparator.ScraperService"
info scraperServiceLogger: "grails.app.jobs.personalcreditcomparator.ScraperJob"
info filterLogger: "grails.app.conf.personalcreditcomparator.AdministratorInterfaceProtectorFilters"
}
The 3 files are created properly but only scraperServiceDetailedLogger stores the logs properly. The other two files remain empty.
The level of logging is respected while calling the log.
What am I missing ?
Thank you for any help provided.
For quartz jobs try the Logger prefix of 'grails.app.task'
info scraperServiceLogger: "grails.app.task.personalcreditcomparator.ScraperJob"
And for filters try the Logger prefix of 'grails.app.filters'
info filterLogger: "grails.app.filters.personalcreditcomparator.AdministratorInterfaceProtectorFilters"

Resources