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

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

Related

I want to migrate users from one database to the next

I am attempting to create a custom command that will migrate user data from one database to the next, This database is not normalized, very legacy, very badly made.
All of that is fine, but I am unsure, in a custom laravel command of how to connect to a different database and do select commands and get back collections of data, like you would if you were doing User::all().
I wont have models for this other database, the application that uses said database is written in php 5.2.
How can I create a custom command that does select statements to another database? All the answers I find are for creating migrations to another database.
You can define multiple database connection configurations in your config/database.php file, then use DB::connection('connection_name_here') to run queries on specific connections.
For example:
DB::connection('first_db')->select("...");
DB::connection('second_db')->select("...");
More information on multiple connections can be found in Laravel's documentation: https://laravel.com/docs/5.7/database#using-multiple-database-connections

Can a Drupal based website's schema be imported to Rails?

I'm working on a web site that needs to be re-written in Rails. The website was before in Drupal, and there are almost 100,000 records in the database. Now, in Drupal there are tables that do not make any place in Rails in my opinion. For example,
Table name: node_type
It stores information regarding modules in Drupal.
Table name: node
It stores information for node(s) in Drupal.
Table name: semaphore # I've no idea what it is!
Table name: rdf_mapping # No idea
I've not been working with Drupal, so all I want to ask: Is it possible to have a schema for Rails, in which the existing 100,000 records can be imported from Drupal? If so, how? If not so, what are the other options that I'm left with? Or I have to design an entirely new database schema?
Drupal's database schema is not extensively documented for a reason... it's considered implementation details, is not a public API and should not be accessed directly, especially by outside application.
It is also very hard to document because for a given site, any enabled module can add its own tables and alter existing ones (usually adding columns). Plus you have module like Fields (part of Drupal core) that create tables dynamically depending on defined content types.
For a RoR developer, the Drupal schema will probably look weird and be uncomfortable to work with. I would follow suggestion from others, create a new schema for your new application and create a migration script to get the data from the old Drupal database to your new database. I don't knwon about RoR, but try to find a good data migration that allows replay, updates and rollback, etc. You will probably have to migrate the data multiple times to fixes bugs in the process.
Well, I don't have straight forward answers, but I have some ideas what I would do simply to not make so much changes in the database, or as per the comment you can write down an sql script to migrate the data according to the rails schema like types for each tables. Now, I am just intended here to share my thoughts, but I believe there might be more explicit solutions and this is do-able in many ways, may be you need some customizations(?) overriding the default conventions. According to my thoughts, you can try the following things.
Generated Related model skipping migrations
Define tables explicitly to each models like the following snippets:
class Semaphore < ActiveRecord::Base
self.table_name = "semaphore"
end
You have to define foreign keys and primary keys explicitly for both record id and associations.
You have generate time stamp or you can explicitly avoid that like the following ways
ActiveRecord::Base.record_timestamps = false
These are basic things I can see is important.

Multiple postgresql Database at runtime in ruby on rails

When customers is created in my app ruby on rails,I want to create database for each customers without break/closing my exiting/running application database.When particular customer is login then I want to CRUD operations on both databases.
My app Database name is myapp.
E.g when customer 1 is created in myapp I want create One database for customer_1.
when customer 2 is created in myapp I want create One database for customer_2.
When customer 1 is login in myapp , when he does any crud operations then I want save all data in Myapp database as well as customer_1 database.
try sequel
Sequel is a simple, flexible, and powerful SQL database access toolkit
for Ruby.
Sequel provides thread safety, connection pooling and a concise DSL
for constructing SQL queries and table schemas.
i think this tool can help you create many database set on you app
You can try to use establish_connection (using before_filter in application_controller) http://www.runtime-era.com/2012/11/dynamic-activerecord-database.html
first make another label and put there all setting of databasee in database.yml then in respected model from where you want to connect different database create two different methods and assign their database connection by establish_connection(database.yml files label name here such as "development") and another method put another db name, which location you want to switch database then call these methods.

Generating admin user from the Seed() method

I'm building a project where the user can access a CMS like admin system (I'm using the built in login that comes with MVC 4 projects). Each site will store the data in it's own SQL CE database. I want to publish the project without any existing db, and then let Entity Framework create it for me on the first hit.
The problem is that I can't let the /Account/Register method be [AllowAnonymous], so I need to have an already existing admin account in the "Users" table.
I want to have a "superuser" account that is already there when the db gets created, and then through this account I will log in and create a user account for the customer that is going to be using the CMS.
Is this possible, or do I need to drop this idea and just publish the project with an existing db?
If you have any other smart solutions, I'm all ears!? ;)
PS. The reason why I don't want to publish the site with a db is that I might accidentally overwrite any existing data if I do some bug fixes and forget to exclude the db from the project before deployment (for already existing sites etc).
I also have it set up so the Seed method fills the database with "starup" values, so the user starts with a clean slate.
Hopefully someone have any good ideas. I've tried searching but I couldn't really find what I was looking for.
Found the solution here:
http://kevin-junghans.blogspot.se/2013/01/seeding-customizing-aspnet-mvc.html
/ Mikael

How can someone add a sql server table from a different database to a ruby on rails application?

I have a database labor which contains the tables that the rails application has created and i have a different database called data_collection that contains a table called employees that i need to pull information so that my application can use it. It doesn't need to be edited from the application only readable. All of these databases are sql server. How would i go about doing this?
Thanks
you could define an activerecord connection for each Model you have , here some example .
link
have a nice day !
You could also see if your friendly DBA has set up a Linked server connection for you to use. Or you could try using the OPENROWSET feature in TSQL. Or you could just do what #andrea suggests.

Resources