-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] New db:show
, db:table
and db:monitor
commands
#43367
Conversation
Would this also show table check constraints? |
db:monitor
, db:show
and db:table
commandsdb:show
, db:table
and db:monitor
commands
Not currently it doesn't. |
I want to suggest to keep |
I feel like the I get that there might be tables that are not backed by a model, but just wanted to make that suggestion. |
Co-authored-by: bastien-phi <bastien.philippe@soyhuce.fr>
@timacdonald the way @joedixon and I see this command is that |
@jbrooksuk - What if migrations are not present, and framework directly connect with remote database on production. |
@timacdonald there's still Laravel apps that don't use Eloquent and just use the database query builder to perform database operations. In that regard it makes sense to me to keep |
This isn't using migrations to generate the output. It's essentially connecting to your database directly (from the |
@jbrooksuk - I understand that! but the concern is if the app connected with multiple database such as DB1 and DB2 will is there any option that i have to parse along with command could you let us know show it will work with multiple database connection. can't we have it within model which would have connection property which will display which model connected with which database and will display accordingly. |
Hi @imManish - This set of commands doesn't have any relation to models. It specifically allows you to get a snapshot of a single database/table. The commands will use your default connection, however you are free to choose which database you which to inspect by using the |
) * wip * wip * wip * wip * wip * wip * Create `AbstractDatabaseCommand` * wip * Change return type of connection count methods * Add `db:monitor` * Move dbal check * Formatting * Opt-in to expensive operations * Apply fixes from StyleCI * Ask for table * Rename variable * Change how getTableSize works * Make `--max` optional in `db:monitor` * wip * Standardise headings * make `db:monitor` use an argument for databases * Use option again * Move composer to abstract * Add composer * Apply fixes from StyleCI * Update src/Illuminate/Database/Console/MonitorCommand.php Co-authored-by: bastien-phi <bastien.philippe@soyhuce.fr> * formatting * Apply fixes from StyleCI Co-authored-by: Joe Dixon <hello@joedixon.co.uk> Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Dries Vints <dries@vints.io> Co-authored-by: bastien-phi <bastien.philippe@soyhuce.fr> Co-authored-by: Taylor Otwell <taylor@laravel.com>
This PR adds three new Artisan commands which provide information about the database directly from a Laravel project.
In summary, it exposes information such as:
db:show
This command gives you an overview of the database as a whole. Out of the box, it will utilise your default connection, but you may optionally choose the connection you wish to inspect.
Upon running the command, you will see a summary of the database including database type, connection details, number of connections, total rows and overall size.
You will also see a breakdown of tables including table size and optionally (using the
--with-counts
option), the number of rows. This is an option as it can be an expensive operation on larger databases.Additionally, using the
--with-views
option, you may also see a summary of the database views.The output for this command is also available in JSON using the
--json
option.Example JSON
This command is really useful to get a better understanding of the health of your database.
db:table
Where
db:show
allows you to see the state of a database as a whole,db:table
allows you to see the state of an individual table by passing the table name as an argument or selecting the table from the list of tables provided.As with
db:show
, the command will use your default database connection, but you may pass the connection you wish to use.This command provides a summary of the table including the size and number of rows as well as a breakdown of every column along with its attributes and data type.
Additionally, it presents an overview of all indexes and foreign keys including the columns and tables referenced. It’s a great way to get a better understanding of a given table and how it relates to others.
The output for this command is also available in JSON using the
--json
option.Example JSON
db:monitor
Much like the
queue:monitor
command,db:monitor
allows you to quickly see the number of connections your database is handling, which is a great indicator of the load it is currently under.In addition, you may pass the
--max
option which will dispatch aDatabaseBusy
event when the number of connections is ≥ the max provided. If no--max
value is provided, no events will be dispatched. Your application may listen for this event in order to, for instance, send an email to the operations team notifying them the database is under strain.Typically, this would be run as a scheduled command as often as you would like the check to be carried out.