Page MenuHomePhabricator

Management command to fill db with sample data
ClosedPublic

Authored by Info-Screen on Aug 22 2018, 9:56 PM.

Details

Summary

It is now possible to add sampledata into the database automatically by calling the sampledata management command.
This command will refuse to work unless DEBUG is True.

The command works by importing all sampledata modules (using Django autodiscover),
where the functions that insert sample data registers with the sampledata registry.
Then all functions in the registery are called.

This works similar to how admin entries are discovered.

Test Plan

rm db.sqlite3; ./manage.py migrate && ./manage.py sampledata

Diff Detail

Repository
rAPI Server API
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Is there a way to call this from the API itself?

The lib doesn't know where the API is installed and cannot call its scripts. It would be convenient to have a way to reset the data after changes like 'remove a user' and such.

Because this will be called often, please make sure this is as efficient as possible.

Can we randomize this somehow?
So each post, user, bio, and comments are different

All data will look similar, so we wont know if an action is successfully triggered

Also looking at the sampledata db"
areas_comment has image data missing
areas_post has image data missing
users_profile only has 1 bio, all users should have bio's
Shouldnt areas_reputation reputation be non-0
Maybe provide passwords for other example users?
Again, all data should be atleast different in some form or another.
We can do random ints? maybe preset random images?

WyldBot requested changes to this revision.Sep 3 2018, 8:32 PM
This revision now requires changes to proceed.Sep 3 2018, 8:32 PM
In D187#4454, @WyldBot wrote:

users_profile only has 1 bio, all users should have bio's

User without bio might be interesting as well

Shouldnt areas_reputation reputation be non-0

Reputation currently doesn't change and is 0 for all users.

Maybe provide passwords for other example users?

All passwords are password123

We can do random ints? maybe preset random images?

Why?

random ints were just a spitball, regardless I feel like we should have just a tad bit more data, or be able to input more data on the fly, without having to reset the DB.

This revision is now accepted and ready to land.Sep 15 2018, 6:34 PM

It looks good to me, can you add a file with a simplified list of the test data? (or a new page in the documentation, like what you did for the REST API)

I'm not too familiar with the framework so it would save a lot of time.

This revision was automatically updated to reflect the committed changes.