Luke Skibinski Holt wrote:
...
> I'm just looking for a quick way to update my models in the development
> stage while keeping test data.

Hey Luke,

I keep sample/test data in sql files and have a script that reloads
that data into my database.  The script:

- recreate the app's database (dropdb, createdb)
- initialize the django tables (django-admin.py init)
- install the admin and app projects (django-admin.py install admin,
etc)
- load all the sql files found in some/path/to/sql/files/ in alpha
order

I keep the sql files in a directory and I name them in such a way that
they will be loaded back into the database in the order I need:

$ ls -1
100_users.sql
150_addresses.sql
...
550_customers.sql
600_applications.sql
...
900_notes.sql
950_state_histories.sql

I wrote a simple bash script to handle the drudgery.  The heart of the
script, the part that loads the sql, looks like this:

            for SQL_FILE in $APP_SQL/*.sql
            do
                echo
                echo "    Loading $SQL_FILE"
                su - $USER_NAME -c "psql $APP_NAME < $SQL_FILE"
            done

which loads all my data.  The rest of the script collects info from the
user regarding paths to django-admin.py, repository trunk and database
user, etc., then runs the database and django-admin.py commands to
drop/create the db and init and install django apps.

When our schema changes, I edit the appropriate sql file to match the
new schema.  Then I run my 'complete_rebuild' script.  Each member of
the development team has a copy of the script so that if any of us
changes the sample/test data, the rest can quickly and easily
synchronize our local database with the new changes.  We occasionally
make changes to our schema, but frequently change the sample data to
exercise testing edge cases.  This approach has worked well for us
during development.  It allows us to have a common starting point of
data and a fast and easy way to rebuild the application during
development.

I hope that helps.

Eric.

Reply via email to