Generate Propel migration file for data entry alone - propel

Is it possible to generate a Propel migration file without modifying the schema? I only need to insert values.
Thanks.

You can generate a blank migration like this:
propel migration:create

Yes. Just call the diff target in the Propel 1 command, which will create a migration class.
(Propel on MySQL for me always creates spurious differences e.g. between FLOAT and DECIMAL, which I delete manually. I don't know if it would refuse to create a class if no differences were found).

Propel migration system is not able to insert values, only update your database structure when you update your schema.
If you use Symfony2, you can use the command propel:fixture:* to insert data for test purpose.

Related

Sqitch - single plan row, multiple sql files

I'm looking to move to sqitch, but my team likes their migrations as multiple files. That is, for example, if we create a foreign key and create an index in the same jira ticket, we like PROJ-123-create-fk.sql and PROJ-123-create-index.sql.
I'd like to keep a single row in the sqitch.plan file, so that each jira ticket corresponds to a single row.
Basically, short of adding lines to sqitch.plan, can I do this? Is there a way to "include" other sql files from a master one? Something like
PROJ-123-main.sql
\include PROJ-123-create-fk.sql
\include PROJ-123-create-index.sql
Thanks so much!
The \ir psql directive solved this for me.
in PROJ-123-deploy.sql
\ir PROJ-123-create-fk.sql
\ir PROJ-123-create-index.sql
If the fk and index sql files are in the same directory, they will be executed.
Since you want to store it as a single line in the plan file, it doesn't quite match, but I will explain the method we use below. Maybe there are parts that you want to use in it.
There is a similar situation in my team, but we use sqitch tags. Each version of our application corresponds to a subtask. And each task corresponds to a tag. We create sql files as many as the number of subtasks. Then we combine them in a tag that we created with the name of the main task. In our CI/CD pipeline that we use for the database, we also provide the transition between versions with tags. I wanted to add this method here in case anyone prefers to use a similar structure.
Simple example;
Let's have v2.0 of our application installed and a new table and an index are required for v2.1
We create two subtasks named create table and create index under the main task named v2.1
We create two sql files;
app_v2.1_table_create.sql to create a table, app_v2.1_index_create.sql to create an index.
After that, we create a sqitch tag called v2.1. Notice it has the same name as the main task.

How to do in Ruby on Jets if a new column is added to database table

We need to alter table by adding a new column, in Ruby on Jets, what should be done? on database side, we can add column manually. how about Ruby on Jets files?
Thanks
George
First of all, you should mention your database Name as
If you are using
Dynamodb
You must go through https://rubyonjets.com/docs/database/dynamodb/
or here you will find all the steps to follow for dynomoDb https://www.twilio.com/blog/serverless-ruby-on-aws-lambda-with-the-jets-framework
If You are using MongoDB
You must go through
https://www.youtube.com/watch?v=VwUu1_jMNUQ
https://docs.mongodb.com/mongoid/master/tutorials/getting-started-rails/#create-new-application
https://mongoid.github.io/old/en/mongoid/docs/querying.html
https://mongoid.github.io/old/en/mongoid/docs/querying.html#query_plus
If you are using MySQL you just need to use normal migrations.
Hope this would help you to catch the nearby solutions.
Good Luck!
You should use database migrations: https://rubyonjets.com/docs/database/activerecord/

How to create Laravel model from migration?

I found many results how to create migration from a model, but is there any way to create a model from migrations?
Basically I want to give a table name, and if there is multiple migration files (one to create and others to update the previous states) the model could be updated.
Is there any solution for this?
I'm not sure that there's a good way to create a model directly from migrations, as it depends on what database you use as to the exact structure of your tables.
There seems to be a package which support generating the models from your database, however:
https://github.com/laracademy/generators

EntityFramework code-first, run a database update script after DropCreate

I'm trying to find some nice work arounds for the issues of computed columns in code first. Specifically, I have a number of CreatedAt datetime columns that need to be set to getdate().
I've looked at doing this via the POCO constructors, but to do that I must remove the Computed option (or it won't persist the data), however, there is no easy to way ensure the column is only set if we are inserting a record. So this would overwrite the CreatedAt each time we update.
I'm looking to create an alter script that can be called after the DropCreate that would go through and alter various columns to include the default value of getdate().
Is there an event to hook into something like OnDropCreateCompleted where I could then run additional SQL
What would be the best way handle the alter script? I am thinking just sending raw sql to the server that would run.
Is there another way to handle the getdate() issue that might be more graceful and more inline with code first that I'm missing?
Thanks
You can just make custom initializer derived from your desired one and override Seed method where you can execute any SQL you want to use - here is some example for creating such initializer.
If you are using migrations you can just the custom SQL to Up method.

rails 3:how to generate models for existing database tables

I've configured my database.yml to point to my existing mysql database
how can I generate models from it?
rails generate model existing_table_name
only gives an emty model..
You can try Rmre. It can create models for existing schema and it tries to create all relationships based on foreign keys information.
A Rails model doesn't show your fields, but you can still use them. Try the following. Assuming you have a Model named ModelName and a field called "name", fire up the Rails console and type:
ModelName.find_by_name('foo')
Given a name that exists in the DB, you should see results.
Rails doesn't infer relationships though, but if your database follows Rails conventions they are easily added.
Update
I've noticed this particular lack of explicitness ("magic") is a source of confusion for newbies to Rails. You can always look in schema.rb to see the models and all the fields in one place. Also, if you would prefer to see the schema for each model in the model file, you can use the annotate_models gem, which will put the db schema in a comment at the top of the model file.
Your answer is:
$ rake db:schema:dump
That will set a new db/schema.db to create a schema of your DB.
ActiveRecord doesn't parse a schema definition. It asks the DBM for the table defs and figures out the fields on the fly.
Having the schema is useful if you are going to modify the tables via migrations.
Schema Dumping and You will help you dump it to use as a reference for building migrations.
ActiveRecord makes some suppositions about the table naming and expects an id field to be the primary key with a sequential number as the type. Having the migrations would help you to refactor the tables and/or fieldnames and types, but you can do those same things via your DBM's command-line. You don't really have to follow ActiveRecord's style but doing so helps avoid odd errors and lets AR infer things to make your life easier.
Could try Magic Model Generator
Take a look at rare_map gem.
https://github.com/wnameless/rare_map
It works both on Rail 3 and 4.

Resources