aboutsummaryrefslogtreecommitdiff
path: root/tasks/db/seed
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/db/seed')
-rw-r--r--tasks/db/seed/required_data.cr30
-rw-r--r--tasks/db/seed/sample_data.cr30
2 files changed, 60 insertions, 0 deletions
diff --git a/tasks/db/seed/required_data.cr b/tasks/db/seed/required_data.cr
new file mode 100644
index 0000000..d866040
--- /dev/null
+++ b/tasks/db/seed/required_data.cr
@@ -0,0 +1,30 @@
+require "../../../spec/support/factories/**"
+
+# Add seeds here that are *required* for your app to work.
+# For example, you might need at least one admin user or you might need at least
+# one category for your blog posts for the app to work.
+#
+# Use `Db::Seed::SampleData` if your only want to add sample data helpful for
+# development.
+class Db::Seed::RequiredData < LuckyTask::Task
+ summary "Add database records required for the app to work"
+
+ def call
+ # Using a Avram::Factory:
+ #
+ # Use the defaults, but override just the email
+ # UserFactory.create &.email("me@example.com")
+
+ # Using a SaveOperation:
+ #
+ # SaveUser.create!(email: "me@example.com", name: "Jane")
+ #
+ # You likely want to be able to run this file more than once. To do that,
+ # only create the record if it doesn't exist yet:
+ #
+ # unless UserQuery.new.email("me@example.com").first?
+ # SaveUser.create!(email: "me@example.com", name: "Jane")
+ # end
+ puts "Done adding required data"
+ end
+end
diff --git a/tasks/db/seed/sample_data.cr b/tasks/db/seed/sample_data.cr
new file mode 100644
index 0000000..231d7e8
--- /dev/null
+++ b/tasks/db/seed/sample_data.cr
@@ -0,0 +1,30 @@
+require "../../../spec/support/factories/**"
+
+# Add sample data helpful for development, e.g. (fake users, blog posts, etc.)
+#
+# Use `Db::Seed::RequiredData` if you need to create data *required* for your
+# app to work.
+class Db::Seed::SampleData < LuckyTask::Task
+ summary "Add sample database records helpful for development"
+
+ def call
+ # Using an Avram::Factory:
+ #
+ # Use the defaults, but override just the email
+ # UserFactory.create &.email("me@example.com")
+
+ # Using a SaveOperation:
+ # ```
+ # SignUpUser.create!(email: "me@example.com", password: "test123", password_confirmation: "test123")
+ # ```
+ #
+ # You likely want to be able to run this file more than once. To do that,
+ # only create the record if it doesn't exist yet:
+ # ```
+ # if UserQuery.new.email("me@example.com").none?
+ # SignUpUser.create!(email: "me@example.com", password: "test123", password_confirmation: "test123")
+ # end
+ # ```
+ puts "Done adding sample data"
+ end
+end