How (and whether) to populate rails application with initial data

Try a rake task. For example: Create the file /lib/tasks/bootstrap.rake In the file, add a task to create your default user: namespace :bootstrap do desc “Add the default user” task :default_user => :environment do User.create( :name => ‘default’, :password => ‘password’ ) end desc “Create the default comment” task :default_comment => :environment do Comment.create( :title … Read more

Completely copying a postgres table with SQL

The create table as feature in PostgreSQL may now be the answer the OP was looking for. https://www.postgresql.org/docs/9.5/static/sql-createtableas.html create table my_table_copy as select * from my_table This will create an identical table with the data. Adding with no data will copy the schema without the data. create table my_table_copy as select * from my_table with … Read more

Loading initial data with Django 1.7+ and data migrations

Update: See @GwynBleidD’s comment below for the problems this solution can cause, and see @Rockallite’s answer below for an approach that’s more durable to future model changes. Assuming you have a fixture file in <yourapp>/fixtures/initial_data.json Create your empty migration: In Django 1.7: python manage.py makemigrations –empty <yourapp> In Django 1.8+, you can provide a name: … Read more

How to group by week in MySQL?

You can use both YEAR(timestamp) and WEEK(timestamp), and use both of the these expressions in the SELECT and the GROUP BY clause. Not overly elegant, but functional… And of course you can combine these two date parts in a single expression as well, i.e. something like SELECT CONCAT(YEAR(timestamp), “https://stackoverflow.com/”, WEEK(timestamp)), etc… FROM … WHERE .. … Read more

How do I move a redis database from one server to another?

First, create a dump on server A. A$ redis-cli 127.0.0.1:6379> CONFIG GET dir 1) “dir” 2) “/var/lib/redis/” 127.0.0.1:6379> SAVE OK This ensures dump.rdb is completely up-to-date, and shows us where it is stored (/var/lib/redis/dump.rdb in this case). dump.rdb is also periodically written to disk automatically. Next, copy it to server B: A$ scp /var/lib/redis/dump.rdb myuser@B:/tmp/dump.rdb … Read more

bahis casinocanlı casino siteleritürkçe altyazılı pornocanlı bahis casino