Purging user data from dev install


(Mark) #1

What’s a good method to purge a dev install before going live - essentially, getting it ready for the final import. (aka killing all users, posts, pm’s, etc.)


(Neil Lalonde) #2

Importing Restoring a backup will overwrite all data, if that’s all you need.

If you need a fresh empty database and you’re using the docker setup, you can do this:

./launcher enter app

# in the container as root now

sv stop unicorn

su postgres -c 'psql -c "drop database discourse"'
# or keep it: "alter database discourse rename to discourse_backup"

su postgres -c 'createdb discourse'
su postgres -c 'psql discourse -c "grant all privileges on database discourse to discourse;"'
su postgres -c 'psql discourse -c "alter schema public owner to discourse;"'
su postgres -c 'psql discourse -c "create extension if not exists hstore;"'
su postgres -c 'psql discourse -c "create extension if not exists pg_trgm;"'

RAILS_ENV=production rake db:migrate

sv start unicorn

(Mark) #3

Perfect. I just assumed importing again would cause duplicate entries. Thanks!


(Jay Pfaffman) #4

Here’s what I do on my development box, though making a backup of a fresh database and restoring from the web interface is a little faster, I think.

#!/usr/bin/env bash
if [ ! -f discourse.sublime-project ]
then
    echo "Dude. There's no Discourse here."
    exit
else
    echo Killing any running rubies. . .
    killall ruby
    RAILS_ENV=development
    export RAILS_ENV
    sleep 5 # make sure they all quit
    RAILS_ENV=development bundle exec rake db:drop db:create db:migrate

    cat <<EOF | bundle exec rake admin:create
pfaffman@gmail.com
1secretpassword!
1secretpassword!

EOF
    echo Flushing Redis
    redis-cli flushall
    echo Done.
fi

(Neil Lalonde) #5

Hmm, I said “importing will overwrite all data”, but I meant “restoring a backup will overwrite all data”. The import scripts will NOT overwrite data.


(Jay Pfaffman) #6

I missed that this was the point of your question. I guess it’s clear now that the cool thing about the import scripts is that they import only new data, so you can do an import, wait hours for it to process, then run it again with the latest version of the database in a few minutes.

I’m developing an importer, so I have to clear the database after making changes to the code before I can re-run it to see what happened.