Which database uses rails 3 of the --sandbox console?

when I run "rails console --sandbox", I can not see the inserts in my database. When I leave this option, I can just see the data in my development database. Everything from the console seems to work the same way. I am using postgreSQL as described in the Hartl configuration tutorial. I looked in each of the databases: Development, Test, Postgres. But I can not find the data created using the console. Since I use the package, I tried with and without "bundle exec"

Here is my database.yml:

development: adapter: postgresql encoding: unicode database: sample_app_development pool: 5 timeout: 5000 username: user password: test: adapter: postgresql encoding: unicode database: sample_app_test pool: 5 timeout: 5000 username: user password: 

I suppose this is not critical, but I am very curious about what is happening here under the covers.

Thanks Mark

+4
source share
2 answers

Since the console acts as one big transaction in sandbox mode, you can see the inserts that you only make through the console.

If you connect to your db using any method other than the console, then it will use a different connection, and what the console does will be hidden from this connection because it has not been completed yet.

When a connection contacts the database using a transaction, other connections to the database cannot see any changes that it makes until it completes. A transaction connection (in this case, an isolated console) is the only connection that can see the changes made to the database before rollback.

+6
source

You will never see anything in your database with the --sandbox . Any changes made in this mode will be canceled when you exit the console.

When you start the console using this option, you can read: Any changes you make will be discarded when you exit

Additional Information

If you try again, you will see SAVEPOINT active_record_1 before insertion and right after it you will see RELEASE SAVEPOINT active_record_1

Read these two links and you will get a better idea of โ€‹โ€‹what is happening. http://www.postgresql.org/docs/8.1/static/sql-savepoint.html http://www.postgresql.org/docs/9.1/static/sql-release-savepoint.html

Additional information 2 =)

As you can see in these two links, PostgreSQL creates a SAVEPOINT , saves the object, and then RELEASE SAVEPOINT . It does not save data permanently, this does not mean that --sandbox intended for use (IMO). Data is saved and immediately thereafter โ€œreleasedโ€. It is used to verify only to verify the relationship between your models, validation, etc.

+5
source

Source: https://habr.com/ru/post/1469535/


All Articles