What is the command to generate migration script from existing sequelize models? - mysql

I've created models using the following command.
$ node_modules/.bin/sequelize model:create --name XYZ --attributes "....."
But by mistake I deleted the folder containing migration script. Now I want to generate this script again.
I tried using sequelize migration:create, but it generated any empty file.
Please Help.

What you need to do now, after you generated a new migration file is to copy the skeleton from here: http://docs.sequelizejs.com/manual/tutorial/migrations.html#skeleton and to customize your migration using the functions that you need.

Related

Query mysql database before webpack

I have info in mysql. In simple terms I want to get that info, create a bundled file.js using webpack and finally run that script in frontend browser.
Currently I get that info, create a new temp.js file with that info and then run webpack getting the info from that file, but I dont like the idea of creating a new temporal file when running webpack.

Could not open input file: yii when i start rbac migration

I'm new on mac, I'm trying to make migration for rbac, but i have error
Could not open input file: yii
I read a lot of answers and tried everything, but nothing suits me
what could be the problem?
as your ls statement shows, there's no yii file. (yii.bat doesn't count)
you need to run the init script again to generate it
php init

Yii2 run only specific migration

In Yii2, when I use the
yii migrate
command, I get a long list of remaining migrations. How can I only run one specific migration in the list without performing the others?
Run migrate/history to list migrations have been applied:
./yii migrate/history
Copy the name of migration you want to return to later (lets say it is 'm160101_185401_initial_migration'). Save it somewhere because you're going to need this later.
Mark migration history at the one just before the one you need to run:
./yii migrate/mark m170101_185401_create_news_table
Run one migration:
./yii migrate 1
Reset migration history:
./yii migrate/mark m160101_185401_initial_migration
yii migrate --migrationPath=#app/modules/forum/
If you want to skip some migrations that have been implemented in your database without running the migrations, you set your migrations state without running them.
By "marking" the migrations you also assure they will no longer be re-prompted and will be regarded as "done".
you can read about marking in the Yii docs here
To run specific migration, you can mark(skip) migrations upto just before one you want run.
You can mark migration by using one of following command:
Using timestamp to specify the migration yii migrate/mark 150101_185401
Using a string that can be parsed by strtotime() yii migrate/mark "2015-01-01 18:54:01"
Using full nameyii migrate/mark m150101_185401_create_news_table
Using UNIX timestamp yii migrate/mark 1392853618

Executing binary SQL file using SQLCMD from WiX

I'm trying to install SQL script(SSDT) using SQLCMD - as this script contains to many SSDT definitions and cannot be run by the WIX SQL extension.
i want my SQL script file to be binary(as i don't want it to stay on target machine)
how can i set the SQLCMD command to use the binary script (with -i)?
p.s.
i tried this blog:
http://neilsleightholm.blogspot.co.il/2008/08/executing-sqlcmd-from-wix.html##
but this code don't shows the link between the binary SQL file and the SCLCMD command.
can someone help me with the correct code?
this is the code i used, which did not work for me
<Binary Id="CreateSchema.sql" SourceFile="..\SQL\CreateSchema.sql" />
<CustomAction Id="sqlcmd.cmd"
Property="sqlcmd"
Value=""sqlcmd.exe" -S [DATABASE_SERVER]
-i "[#CreateSchema.sql]" -v var=SYSTEM_USER -o [INSTALLDIR]installSql.log" />
<CustomAction Id="sqlcmd"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Return="check"
Execute="deferred"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="sqlcmd.cmd" After="InstallFiles">NOT Installed</Custom>
<Custom Action="sqlcmd" After="sqlcmd.cmd">NOT Installed</Custom>
</InstallExecuteSequence>
the log file showed that -i parameter did not had any file name value:
MSI (s) (4C:6C) [09:58:15:610]: Executing op: CustomActionSchedule(Action=sqlcmd,ActionType=1025,Source=BinaryData,Target=CAQuietExec,CustomActionData="sqlcmd.exe" -S (local) -i "" -v var=SYSTEM_USER -o C:\installSql.log)
That's not how <Binary> works. The [#FileID] syntax is used to dynamically use the at runtime installation full path of a component's file.
Binaries are used typically as temporary extracted files for custom actions or, in this case, sql files among other things.
Consider looking into the SQL Extension in wix. As a minimal example take a look at this code.
Add the sql namespace xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension"
<Binary Id="CreateSchema" SourceFile="..\SQL\CreateSchema.sql" />
<sql:SqlDatabase Id="MyDB" Database="[DATABASE]" Server="[DATABASE_SERVER]" />
And in a component you can add
<sql:SqlScript Id="CreateSchemaScript" BinaryKey="CreateSchema" ExecuteOnInstall="yes" Sequence="1" SqlDb="MyDB"/>
Here is a link to the SQL Schema definition with all the available elements. I haven't done much with the SQL Extension so you may need to do some reading to get a better idea of what you will need to do to accomplish creating your DB on install.
As i mentioned i wanted to use both SQLCMD - since my SQL script is SSDT format, and binary file(so file will be deleted in end of the install).
After looking for answers i understood that i cannot use the WiX [#filekey], as binary file will not be extracted as long as there is no custom action that is running - using it explicitly.
So in the end i understood that the best way is to extract the binary file by my self.
the steps i used in one single custom action are:
extract binary SQL script from MSI binary table.
save this file locally
run SQLCMD with -i and new file path(the one i save to)
delete the SQL file
I encounter some issues, worth mentioned, if you save the file to INSTALLDIR than the directory may not exist at the tun time of the custom action, so consider save it to temp folder or to create directory beforehand.

Is it possible to use Composer to manage Wordpress databases?

I am trying to use Composer for my Wordpress workflow and was wondering if there is a way for Composer to grab a MySQL database from my S3 bucket? The idea here is that I want to develop Wordpress websites locally starting from a backup copy of a database. Was hoping to find a way to automate this through Composer.
You can define custom scripts for composer, and tell it what you want to do.
For example, if you wanted to pull it from S3 and import it using the mysql command line utility, you could add something like this to composer.json:
"scripts": {
"refresh-db": "aws s3 cp s3://my-bucket/db-dump.sql /tmp/db-dump.sql && mysql -hlocalhost -uroot my_db_name < /tmp/db-dump.sql"
}
Then run composer refresh-db to execute it.