I have totally messed up my database’s data and schema. Can I just drop it and start fresh?
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 application name
creates 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 name
key in .platform.app.yaml
. For example, change
# .platform.app.yaml
name: app
to
# .platform.app.yaml
name: myapp
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 upstream
in routes.yaml
:
https://{default}/:
type: upstream
upstream: myapp
Service containers
To wipe data from a service container, change the name of the service in services.yaml
. For example, change
mydb:
type: mariadb:10.2
disk: 2048
to
mydb2:
type: mariadb:10.2
disk: 2048
That will result in a brand new empty MariaDB service named mydb2
, and the old mydb
service will be deleted entirely.
You will then need to also update the relationships
in .platform.app.yaml
to point to the new service name, but you do not need to change the relationship name.
# .platform.app.yaml
relationships:
database: 'mydb2:mysql'
After you commit and push your changes, the project will have deleted the mydb
service and created a new, empty mydb2
service.
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 main
to 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