Question: I'm trying to copy my production database on Heroku across to my staging server. 

My staging server has been ahead of my production server with a migration that creates an extra table. I now want to dry-run the migration to add that table on the production database and so would like to revert my staging's database in order to do so.

The problem is that each time I `restore` the staging database to the production one the table sticks around. I was expecting the database to be destroyed and repopulated but it only seems to be being repopulated.

```
heroku pgbackups:url b104 --app production
# 'http://s3.amazonaws.com/...'

heroku pgbackups:restore DATABASE 'http://s3.amazonaws.com/...' --app staging

```

Every time I do this I find that the "newer" table is still remaining. 

Does `pgbackups:restore` actually restore table structure or simply data - what's going on here?

Answer: 
A restore is a simple Postgres restore, so essentially a scripted version of your data.

In order to do this, you need to nuke your database first, and then rebuild it from the database script:

```
heroku pg:reset
heroku pgbackups:restore blah...

```
as neil said, the pgbackups:restore only moves the data and does not change the actual db structure.

for complete db restore (change app-production, app-staging and migration\_number to fit your app):

first, get the current migration from your production.

```
heroku run rake db:version --app app-production

```

reset staging db (naturally, back it up if needed)

```
heroku pg:reset DATABASE_URL --confirm app-staging

```

run the migrations until migration\_number to fit the production db structure

```
heroku run rake db:migrate VERSION=current_migration_number --app app-staging

```

capture the production app

```
heroku pgbackups:capture --app app-production

```

push the data to the staging app

> 
> EDIT - in case you're using the heroku toolbelt, the syntax pattern
>  has changed from `pgbackups:action_name` to `pg:backups action_name`
> 
> 
> 

```
heroku pgbackups:restore DATABASE "heroku pgbackups:url --app app-production" --app app-staging

```

the staging db should now match the production data and structure

```
heroku run rake db:migrate --app app-staging

```

hope that helps.