Entity Framework Migrations Intercept Create/Drop table - entity-framework-6

EF Migrations: Add-Migration identifies the tables, fields to be added, removed, updated.
I want to intercept these methods to write some custom login to Create Table, Drop Table. And that in turn will generate the migration code automatically.
Is there a way to do that?
When I add a table, I want to add an article for replication in publisher database. Hope it is possible to add this automatically.
Thanks

Related

dynamically change schema for some tables in entity framework using db first with postgres

i am using entity framework 6 in my web api project which is database first EF with postgres.
we have say 10 tables, out of which say 5 are in central schema. but while login user select organization so on the basis of basis of that i want the other 5 tables to come from the some specific schema as per the organization selected(we have multiple schema containing same (say 5) table structure but different data)
while login i get the schema name so that is not the problem, but i want something to implement the above mentioned scenario.
Also the solution as mentioned in this awesome article
https://archive.codeplex.com/?p=efmodeladapter
is not acceptable in my project as we dont want to add anything in auto-generated file otherwise everytime we need to update that file manually whenever we do some update
Thanks in advance

What internal tables are automatically created by Rails?

I'm working on blacklisting these for the data analysis tool Metabase.
I can't find any lists anywhere that specify which tables the framework creates, but I want to make sure I get db migration / ActiveRecord ones and other internal ones created by the framework that a user likely wouldn't be interested in looking at.
The only table that Rails (or rather ActiveRecord) creates regardless of application models is schema_migrations.
By default rails does not create any table when you create a new app.
But when you add a migration for create table that time rails create a table schema_migrations and that is used to save version of the migrations.
This table will create with first table when run rake db:migrate

Why are relations between databases not part of the migration file?

I use the migration file to setup the database structure.
That is very convenient as I am not constrained to a specific type of database (mysql, sql,...)
If I want to have relationships between different tables, I have to use the Associations has_to, belongs_to IN THE MODEL FILE.
I don't get this. Now you can't just roll back a migration of the database go on from this point. No, you also have to modify the model file manually.
Why did they choose this design concept?
Migrations are for changing the state of your database, not for altering the behavior of your models.
I don't get this. Now you can't just roll back a migration of the database go on from this point. No, you also have to modify the model file manually.
Of course you do. You have to modify the model/controller/view code to use any migrated changes to the database, associations or otherwise. What's the big deal? How else would you consume the changes you're making to your database, if not through changes to your application code?
Your application code is always going to be tied to the state of the database. Migrations aren't supposed to isolate you from this.

RoR migrations and data

I'm new to rails and I'm not sure I fully understand migrations. Is there a way to run them without losing table data? Also, is it bad to mess with old migrations to change table structures, or are you just supposed to create new ones?
At version 0 there's nothing in the database. So how do you think you'll be able to keep data? :)
Usually it's not recommended to edit old migrations, because you'll have to reapply them. It's much easier to create new migration and roll it out.
Migrations are nothing but a way to encapsulate the Database used, its just ruby code. Read more here: http://guides.rubyonrails.org/migrations.html
A migration which creates a table is supposed to drop the table when the same migration is reverted(:down). Since it deletes the table there is no chance of retaining data.
Once a migration is executed for a table & you still need to alter structure, you should always create a new migration file for using the generator:
rails g migration AddColumnNameToTableName

Add foreign key constraints to existing tables in Ruby on Rails (MySQL)

What's the best way to add foreign keys to my existing tables in Rails with an underlying MySQL database? clearly the solution should be done in a migration, as I want this versioned. Otherwise I'd create the constraints myself.
I can't seem to find one, conducive response to they above. Again, the tables have already been created with previous migrations. I'm just going back now and adding referential integrity wherever it's applicable.
Foreigner works nicely for managing foreign keys.
Alternatively, you can just use the execute method to issue ALTER statements within your new migrations.

Resources