I want to migrate users from one database to the next - database-connection

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

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

How to handle multiple connection string in .net 4.7 application

we have two databases in our project, one for primary and one for backup. Both of the databases have exactly same data.
we have used EF designer model to get SP's from db. we call any method by just using object.spName . This is working perfectly if we have only one db. But since we have multi db system i need to make sure that insertion operation works on both db and select queries can be run from primary only and backup will be used to get records only if primary is down.
What is the best approach to get this working, or how can i specify multiple db in same connection string
You don't want to do this on the application layer... You should look into database technologies like replication to perform this, or use native database backups and restore them on a schedule
Imagine an error occurs between the first and second, or someone does a manual query - your dbs will be out of sync.

Ruby and Rails: Adding a column to a model without migrate

There are a number of questions here about adding columns to a model via rails migration files and a rake db:migrate.
In this case, however, the application is basically a CRUD on top of an existing SQL Server database that is generated by another application. That is, I don't control it. Those who do control the database have added several columns to a table.
What I need is for the Rails app to respect the changes made to the database without assuming it has full control over the table structures.
I've tried plugging the new fields into the model and controller files, but sql queries give TinyTDS errors saying the new fields don't exist. Queries by hand (via SQL Server Management Studio) work fine. What am I missing? Why doesn't Rails recognize the new fields when they appear in the table model?
UPDATE:
It turns out that the problem is more subtle than I though when asking the initial question. As background, this application is set up with two databases, one production, one development/test. They are both on the same SQL Server database server. What's actually happening with the missing columns is that the Rails app pulls from production no matter what environment I use. Even when I change both environments to use the same development database (in database.yml), the app continues to query the production database.
Perhaps this is a problem between Rails and SQL Server. I've cleared all caches and cleared all database connections, but it makes no difference. It seems that the Rails app is caching the database name and login info somewhere.
One day I'd like to get this fixed, but for now I'll simply move the development database to another server for testing.
ActiveRecord has a cache of the table fields. If you want to reset the cache for a model without restarting your application, you can do:
MyModel.reset_column_information

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.

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