How can I reset or empty a service?
Larry
I have totally messed up my database’s data and schema. Can I just drop it and start fresh?
0
Comments
Some services offer a native way to run “delete all” on data, in which case that is the preferred method.
If that is difficult or not viable for some reason (for instance, on an SQL database where the schema itself cannot be dropped on Platform.sh), it’s possible to create a new service and use that instead.
The storage for any service or application on Platform.sh is keyed to the service’s
name. Changing the service or applicationnamecreates a new service with a new, empty storage allocation. By the same token, removing a name will result in the data partition for that service being deleted. Do not change the name of a service unless you really intend to wipe all of its data, because that is exactly what will happen.Application containers
To wipe all data from an application, change the
namekey in.platform.app.yaml. For example, changeto
That will result in a new app container being created, with a new disk, that has all the same code but new data. Note that you will also need to update the
upstreaminroutes.yaml:Service containers
To wipe data from a service container, change the name of the service in
services.yaml. For example, changeto
That will result in a brand new empty MariaDB service named
mydb2, and the oldmydbservice will be deleted entirely.You will then need to also update the
relationshipsin.platform.app.yamlto point to the new service name, but you do not need to change the relationship name.After you commit and push your changes, the project will have deleted the
mydbservice and created a new, emptymydb2service.For Drupal (all versions) a quick way to do this would be via
drush:platform drush sql:drop…Will empty all tables, rather than attempt to “
DROP DATABASE ...; CREATE DATABASE ...” which the web user does not have permission to do.You can now run
DROP DATABASE main; CREATE DATABASE mainto remove all tables and data from your database.No privileges will be touched so it’s a good way to clear out the database without changing the service name
Please sign in to leave a comment.