codeception: running multiple sql dump files - mysql

I'm looking for help or documentation if it is possible to dump multiple sql dump files using codeception, and use a configuration like this:
modules:
config:
- Db:
dsn: 'sqlite:./var/cache/test/test.sqlite'
user: ''
password: ''
=> dump: 'tests/_data/*.sql' <=
populate: true
cleanup: true
reconnect: true

You can now do it with
- Db:
dsn: 'sqlite:./var/cache/test/test.sqlite'
user: ''
password: ''
dump:
- 'tests/_data/d1.sql'
- 'tests/_data/d2.sql'

I don't think that is possible straight out of the box.
An alternative would be to combine the dumps into 1 dump file.
You can also have a look at my answer to this post, maybe it can be helpful for you.

Related

Rails not recognizing changes to mysql database

I have a rails app that uses mysql as the database. I've done an sqldump, created a database (called local_prod), and imported the dump into the database. When I try to access the database information with my rails app, it doesn't see any of the data that is in the database. Any idea why this is happening?
When I call for the object I'm looking for through the web app, it returns nil. Here is the sql select statement that is run:
Bound Load (0.5ms) SELECT `bounds`.* FROM `bounds` WHERE `bounds`.`city` = 'boston' AND `bounds`.`state` = 'ma' ORDER BY `bounds`.`id` ASC LIMIT 1
When I copy and paste that same statement into the mysql console in my terminal, it returns all the data I am looking for.
Here is my database.yml file as well:
development:
adapter: mysql2
database: local_prod
host: localhost
username: root
password:
socket: /tmp/mysql.sock
You sure your sql db doesn't have a root password?

How can I extract data from one database, manipulate it, and insert it into another in Rails?

I have two databases (a legacy MySQL one and a new PostgreSQL one), and the schema for the new one was redesigned. As a result, I can't just dump the old database to YAML and load it into the the new one, since columns are named different things and may need to be manipulated. Is there an elegant way to do this?
It's actually fairly easy.
First you need to define the connection to your MySQL database in your database.yml. Let's call it legacy:
development:
adapter: postgresql
.....
test:
adapter: postgresql
.....
legacy:
adapter: mysql2
encoding: utf8
database: your_old_mysql_db
username: root
password:
host: localhost
port: 3306
You will need the mysql2 gem in your gemfile, alongside the pg gem!
Now just create models for each of the tables you want to connect to:
Here's one called LegacyUser, which will let you get the old users out of your MySQL database:
# app/models/legacy_user.rb
class LegacyUser < ActiveRecord::Base
establish_connection :legacy
self.table_name = "whatever_your_my_sql_user_table_name_is"
end
Now, in a Rake task you can pull data out of the MySQL table and stick it into your Postgres table like so:
# lib/tasks/import.rake
namespace :import do
desc "Import Users"
task users: :environment do
puts ""
puts "Importing Legacy Users:"
LegacyUser.find_each do |lu|
print "#{lu.id} - #{lu.first_name}"
u = User.new
u.email = lu.email
u.first_name = lu.first_name
u.last_name = lu.last_name
if u.save
puts "... saved"
else
puts "... bad: #{u.errors.full_messages.join(',')}"
end
end
end
end
Now you can just run:
rake import:users

How to add custom mysql database in symfony

First of all hello everyone !
I'm on a Symfony 1.4 website, and I don't really have knowledge in this framework.
The site already uses 2 database connections, in databases.yml
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:host=localhost;dbname=my_db_name
username: my_username
password: ***
charset: utf8
encoding: utf8
attributes:
default_table_collate: utf8_general_ci
default_table_charset: utf8
use_native_enum: true
# Base de test
test:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:host=localhost;dbname=my_other_db_name
username: my_username
password: ***
charset: utf8
encoding: utf8
attributes:
default_table_collate: utf8_general_ci
default_table_charset: utf8
use_native_enum: true
It's working I think, well I never use base test but I guess it works.
I need to use another database, not in localhost this time but from another server.
I tried so many thing, that i learn from stackoverflow post.
I created a config folder into my module, where I put the code into a new databases.yml
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:host=mysql_host.bdb;dbname=mysql_db_name
username: mysql_username
password: ***
charset: utf8
encoding: utf8
attributes:
default_table_collate: utf8_general_ci
default_table_charset: utf8
use_native_enum: true
I don't know how to access to this database, seems to not working at all.
So I try directly into my template, seems logic because I need this database only into 1 template, in response of a form.
$bd_nom_serveur='mysql_host.bdb';
$bd_login='mysql_user';
$bd_mot_de_passe='***';
$bd_nom_bd='mysql_db_name';
$base = mysqli_connect($bd_nom_serveur, $bd_login, $bd_mot_de_passe, $bd_nom_bd);
Sending me warning
Warning: mysqli_connect(): (HY000/2005): Unknown MySQL server host 'mysql_host.bdb' (2) in /srv/d_/www/draft.site.com/apps/frontend/modules/FormContactSlot/templates/sendMailCatalog.php on line 14
I also tried
$dsn = 'mysql:dbname=mysql_db_name;host=mysql_host.bdb';
$user = 'mysql_user';
$password = '***';
$dbh = new PDO($dsn, $user, $password);
$conn = Doctrine_Manager::connection($dbh);
sendig me error
500 | Internal Server Error | PDOException SQLSTATE[HY000] [2005]
Unknown MySQL server host 'mysql_host.bdb' (2)
I try with and without .bdb but nothing change.
I don't know how to access to this database from symfony 1.4
Can anyone help me please !
keep in mind that I have very little knowledge of Symfony, be gentle please !
EDIT :
I also tried another trick.
I add the database after my principal database on config/databases.yml
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql:host=localhost;dbname=my_db_name
username: my_username
password: ***
charset: utf8
encoding: utf8
attributes:
default_table_collate: utf8_general_ci
default_table_charset: utf8
use_native_enum: true
client:
class: sfDoctrineDatabase
param:
dsn: mysql:host=host.bdb;dbname=dbname
username: user
password: ***
charset: utf8
encoding: utf8
attributes:
default_table_collate: utf8_general_ci
default_table_charset: utf8
use_native_enum: true
And this time I got an error whenever I try to go on my website. I also do the command symfony doctrine:build-schema but this send me the same error unknown mysql server...
Please I need help, I have to access my mysql database from symfony, I don't have the choice.
I respond to myself because I find a solution :
There is no solution.
I'm on a shared OVH solution, and shared OVH databases are not remotely accessible. So I have to take a vps solution, where there is IP host for database.
Thanks to Marek for helping me finding the solution.
Here the query that works.
$bd_nom_serveur='IP host';
$bd_login='mysql_user';
$bd_mot_de_passe='***';
$bd_nom_bd='mysql_db_name';
$base = mysqli_connect($bd_nom_serveur, $bd_login, $bd_mot_de_passe, $bd_nom_bd);
PDO still not working.

converting mysql db to pg db

So, I'm using the mysql2psql gem and I've got the following code:
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: root
password: root
database: hello_development
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: root
password: root
database: hello_development
# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false
I'm a bit confused though, as to how I would convert all of my table e.g. test, and production as well. At the moment, it looks like I am just converting hello_development.
Please advice!
You're specifying which database to use - database: hello_development - which is why it's only running in your development environment. You need to create config files for mysql2pgsql for your test and production environments as well.
Having used mysql2pgsql in the past, keep in mind that there can be a LOT of differences between how mysql and postgres work - make sure that you have fully tested your application in a development environment prior to running this script in your production environment.

How to select the connection to database when I use console in symfony2

I have two databases, (MySQL and Oracle), I did the connection betweek sf2 and both databases, here is my config.yml file:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
sysman:
driver: %database_driver2%
host: %database_host2%
port: %database_port2%
dbname: %database_name2%
user: %database_user2%
password: %database_password2%
charset: UTF8
My question is, how can I run console command on the second database (Oracle), commands like (doctrine:database:create ...), and thanks
Use the --connection parameter:
php app/console doctrine:database:create --connection=default
or
php app/console doctrine:database:create --connection=sysman
You should first read a tutorial about commands and how to pass options and parameters to the commands. And how to distinguish between an option and a parameter.
If you want to make your own commands...
You will probably want to make it like this - if you do not pass an option (you will use the default database), if you pass it, you will make sure it is a valid option, and use the passed database connection name.
Doctrine is not tightly coupled with Mysql, you can use almost all most common available databases.
Also note, commands are container aware. That means you commands can access container, though which you have access to your services, such as doctrine:
protected function execute(InputInterface $input, OutputInterface $output)
{
$connection $input->getArgument('connection');
# Validate connection argument here and use it below
$container = $this->getContainer();
$em = $container->get('doctrine')->getManager(); // default db
$em = $container->get('doctrine')->getManager('sysman'); // another
return 1;
}
I wrote the code without testing, excuse me for any mistake I might have done.
php app/console doctrine:mapping:info --em=default (same without em option)
php app/console doctrine:mapping:info --em=sysman