Typeorm Migration:generate failure Not enough non-option arguments: got 0, need at least 1 - typeorm

I tried this command in different possible ways but the basic structure of my command was.
yarn typeorm migration:generate -n=consent-record -d=\"./src/db/CliDataSource.ts\"
this is my typeorm command in the package.json for yarn berry
"typeorm": "ts-node -P ./tsconfig.typeorm.json $(yarn bin typeorm) -d ./src/db/CliDataSource.ts",
I also tried installing typeorm locally as an npm. and also tried with npx.
but they all give the following error. "Not enough non-option arguments: got 0, need at least 1"
this error clearly doesn't mention what is missing.
my CliDataSource goes like this.
export const CliDataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5436,
username: '****',
password: '******',
database: 'consent',
synchronize: false,
logging: false,
entities,
migrations,
migrationsRun: true,
subscribers: [],
});
I am using typeorm "^0.3.6"

Latest updates to the typeorm has removed -n flag which we used to rename migrations. how it works now is that we need to provide the migration file path. that will store the migration in that specified file. so the updated operations were
my typeorm alias inside package.json.
"typeorm": "ts-node -P ./tsconfig.typeorm.json $(yarn bin typeorm) -d ./src/db/CliDataSource.ts",
CLI Command
yarn typeorm migration:generate ./src/db/migrations/consent-record
The official documentation seems outdated. hope it will be updated soon.
Special thanks to Jacob Copini #woov

I had a similar issue but solved it initially using a util file like this
// contents of migration.ts
import { exec } from 'child_process';
const command = `npm run typeorm migration:create ./src/migrations/${process.argv[2]}`;
(() => exec(command, (error, stdout, stderr) => {
if (error !== null) {
console.error(stderr);
}
console.log(stdout);
}))();
In the package.json:
"migration:create": "ts-node migration.ts"
And to use, type the following:
npm run migration:create unique-key-username
But here's how it should be done after the latest changes in TypeORM:
// new syntax for TypeORM ormconfig.ts
const { DataSource } = require("typeorm");
require('dotenv').config();
for (const envName of Object.keys(process.env)) {
process.env[envName] = process.env[envName].replace(/\\n/g, '\n');
}
const connectionSource = new DataSource({
type: 'mysql',
host: process.env.DB_HOST,
port: +process.env.DB_PORT,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
entities: [__dirname + '/entities/**/*.{js,ts}'],
migrations: [__dirname + '/dist/src/migrations/*.js'],
});
module.exports = {
connectionSource,
}
// package.json
"typeorm": "ts-node node_modules/typeorm/cli.js",
"migration:create": "ts-node migration.ts -d ./ormconfig.ts",
"migration:run": "typeorm migration:run -d ./ormconfig.ts",
"migration:revert": "typeorm migration:revert -d ./ormconfig.ts",

Had the same issue, the workaround I found for now is to use the compiled js file
For example, this will work
npx typeorm migration:generate Init -d dist/db/CliDataSource.js
As the CLI command fails to import the .ts file for some reason, probably because of the file URL it tries to generate, also for some reason it will only import a ts file if the closest package.json file is set to a type => module
File URL ->
typeorm/src/db/CliDataSource.ts
: pathToFileURL(filePath).toString(),
package.json module type check ->
typeorm/src/db/CliDataSource.ts/
const isModule = (packageJson as any)?.type === "module"
This command below does not work
npx typeorm migration:generate Init -d ./src/db/CliDataSource.ts

Related

Antd_dayjs_vite_plugin : TypeError: (0 , import_antd_dayjs_vite_plugin.default) is not a function

At the beginning I got a problem with the french date in the antd calendar. I use vite so I install the antd_dayjs_vite_plugin to switch from Moment.js to Day.js. It worked well but this morning the vite build process is in error. I tried to update the antd_dayjs_vite_plugin version (was 1.1.4) and now I got the same problem when I try to lunch a yarn dev as you can see :
$ yarn dev
yarn run v1.22.15
$ vite
failed to load config from vite.config.ts
error when starting dev server:
TypeError: (0 , import_antd_dayjs_vite_plugin.default) is not a function [...]
Here is the code in vite.config.ts :
import reactRefresh from '#vitejs/plugin-react-refresh';
import antdDayjs from 'antd-dayjs-vite-plugin';
import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [reactRefresh(), antdDayjs()],
server: {
host: process.env.HOST || '127.0.0.1',
},
resolve: {
alias: [{ find: '#', replacement: '/src' }],
},
define: {
__APP_VERSION__: JSON.stringify(process.env.npm_package_version),
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
});
The problem also appears in antd-dayjs-vite-plugin 1.1.4 version or the 1.2.2. I also already tried to update vite to 3.1 (was in 2.5).
I don't understand the code seems to be exactly the same as the usage in the Readme package.
Thanks in advance for your help. 🙏🏻
Seams that a default export is expected by vite.js (tried to replace import statement with import {antdDayjs} from 'antd-dayjs-vite-plugin'; without success)
I was able to create a workaround using patch-package with the below steps:
modifiy node_modules/antd-dayjs-vite-plugin/dist-node/index.js
at the very end of that file, add exports.default = antdDayjs;
create a patch for antd-dayjs-vite-plugin
ensure you have the postinstall script (refer to patch-package doc)

How to move changed created migration to dist folder?

I started to use Typeorm Migration. I've defined in the package.json the next commands:
"migration:create": "cross-env NODE_ENV=dev npm run typeorm migration:create -- -n",
"migration:generate": "cross-env NODE_ENV=dev npm run typeorm migration:generate -- -n",
"migration:run": "cross-env NODE_ENV=dev npm run typeorm migration:run",
"migration:revert": "cross-env NODE_ENV=dev npm run typeorm migration:revert"
And my ormconfig looks like that
const connectionOptions: ConnectionOptions = {
type: envConfig.DATABASE_TYPE,
host: envConfig.DATABASE_HOST,
port: envConfig.DATABASE_PORT,
username: envConfig.DATABASE_USERNAME,
password: envConfig.DATABASE_PASSWORD,
database: envConfig.DATABASE_NAME,
entities: ["dist/**/*.entity.js"],
synchronize: envConfig.DATABASE_SYNCHRONIZE,
migrations: ["dist/migrations/*{.js, .ts}"],
cli: {
migrationsDir: 'src/migrations',
},
}
export = connectionOptions
When I change something into my entity, and run migration:generate all are working fine, and in the dist folder( migrations) I get a migration file. But for example a need to insert a new value into an existing table( without modifying any fields). For that, I run a migration:create that generates an empty file with up and down functions, where in up I've already described my query. But in the dist folder this file is empty( because it was created when I ran the create command)
My question is, how I can update the file from the dist folder to the actual information that I've written into a created file? Thanks

Chainlink Hackathon 21 HardHat tutorial execute function in Smart Contract

I would put this on stack overflow but it's specific to the hackathon. This is for the HardHat tutorial. I am trying to execute my get-number function on my smart contract. My contract is deployed. This is my command: npx hardhat get-number --contract 0x5FbDB2315678afecb367f032d93F642f64180aa3. This is the error I get: Error: call revert exception (method="getNumber()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0). Any thoughts would help...Thanks.
Here is the Task
task("get-number", "Reads the number")
.addParam("contract", "The contract's address")
.setAction(async (taskArgs) => {
const contractAddr = taskArgs.contract;
const MyFirstContract = await ethers.getContractFactory('MyFirstContract');
const accounts = await ethers.getSigners();
const signer = accounts[0];
const myFirstContract = await new ethers.Contract(contractAddr, MyFirstContract.interface, signer);
let result = BigInt(await myFirstContract.getNumber()).toString();
console.log('Stored number is: ' + result);
});
module.exports = {};
I had similar error when following along with this hackathon tutorial.
My fix was to specify the --network when executing my task, get-number. So, in your example:
npx hardhat get-number --network localhost --contract 0x5FbDB2315678afecb367f032d93F642f64180aa3
This will execute the task using the Hardhat network the demo instructed you to start when you ran npx hardhat node
Hardhat Network doc
See Running Stand-Alone doc
I asked on the hackathon Discord why the demo didn't pass this, yet still worked, but haven't yet received an answer.
I have the same problem, and the way I fixed it is to start hardhat with npx hardhat node --hostname 0.0.0.0 instead of npx hardhat node
You'll need to deploy the contract to localhost as well: npx hardhat run scripts/deploy.js --network localhost
Then using npx hardhat --network localhost to call the 2 functions.

Laravel 8 jetstream hot reload and browser sync do not work

I have a big problem with a system I just created.
I did the standard installation of Laravel 8 with jetstream using the docker and laravel sail...
However, I am not able to do the npm run hot or npm run watch to auto reload or browser sync...
My files are standard with laravel 8 and I haven't made any changes to the code yet.
Informations:
Laravel: v8.41.0
PHP: PHP v8.0.5
Jetstream: v2.3.5
npm: v7.7.6
NodeJS: v15.14.0
my webpack.mix.js looks like this:
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js').vue()
.postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
require('tailwindcss'),
])
.webpackConfig(require('./webpack.config'));
if (mix.inProduction()) {
mix.version();
}
my webpack.config.js looks like this:
const path = require('path');
module.exports = {
resolve: {
alias: {
'#': path.resolve('resources/js'),
},
},
};
I have also tried to change the two webpacks with some information I found earlier in research, but really nothing is working, would there be a way for Hot Reload and Browser Sync to work together with Laravel Sail?
While a browsersync script is already included in app.blade.php I did not get it to work either. I removed that line and expanded my webpack.mix.js as follows:
mix.browserSync({
proxy: 'YOURDOMAIN.test',
host: 'YOURDOMAIN.test',
open: 'external'
});
Then run npm run watch- probably twice because it's going to install browsersync - and it's working.
open: 'external' save me ( same i use valet and https )
.browserSync({
proxy: 'https://app.tunnel.test',
host: 'app.tunnel.test',
open: 'external',
https: {
key: homedir + '/.config/valet/Certificates/' + domain + '.key',
cert: homedir + '/.config/valet/Certificates/' + domain + '.crt',
},
})

Step by step to making db connection in symfony1.4

I'm new to symfony. My existing application is developed in symfony1.4. They didn't used any db connection. Now I want to create new MySQL database connection in this application.
How can I do that?
in settings.yml
all:
use_database: true
from the console run this command
php symfony configure:database "mysql:host=dbhost;dbname=yourdbname" dbuser dbpassword
Please check all the steps to make db connection symfony1.4
Step 1 :
file : config/ProjectConfiguration.class.php
find what:
---------
public function setup()
{
$this->enablePlugins('owCorePlugin');
}
Repalce with :
------------
public function setup()
{
$this->enablePlugins('owCorePlugin');
$this->enablePlugins('sfDoctrinePlugin');
}
Step 2 :
config/databases.yml
You need to create this file and add below code.replace caps letter with your details.You need to maintain same space also.
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:host=HOST_NAME;dbname=DB_NAME
username: USERNAME
password: PASSWORD
Step 3:
frontend/config/settings.yml
find what :
use_database: false
Replace with
use_database: true
Run the following command:
change the project configuration.Make sure you need to run this command in root folder of our project
php symfony configure:database --name=doctrine --class=sfDoctrineDatabase "mysql:host=HOST_NAME;dbname=DB_NAME" USERNAME PASSWORD
step 5: schema files
$ php symfony doctrine:build-schema
$ php symfony doctrine:build-model
$ php symfony doctrine:build-forms
$ php symfony doctrine:build-filters
$ ln -s lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/web web/sfDoctrinePlugin

Resources