setup_db 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. DB="mysql -h 127.0.0.1 -P 3306 -u root -ppassword"
  3. echo "DROP DATABASE IF EXISTS zotero_master" | $DB
  4. echo "DROP DATABASE IF EXISTS zotero_shards" | $DB
  5. echo "DROP DATABASE IF EXISTS zotero_ids" | $DB
  6. echo "CREATE DATABASE zotero_master" | $DB
  7. echo "CREATE DATABASE zotero_shards" | $DB
  8. echo "CREATE DATABASE zotero_ids" | $DB
  9. echo "DROP USER zotero@localhost;" | $DB
  10. echo "CREATE USER zotero@localhost IDENTIFIED BY 'foobar';" | $DB
  11. echo "GRANT SELECT, INSERT, UPDATE, DELETE ON zotero_master.* TO zotero@localhost;" | $DB
  12. echo "GRANT SELECT, INSERT, UPDATE, DELETE ON zotero_shards.* TO zotero@localhost;" | $DB
  13. echo "GRANT SELECT,INSERT,DELETE ON zotero_ids.* TO zotero@localhost;" | $DB
  14. # Load in master schema
  15. $DB zotero_master < master.sql
  16. $DB zotero_master < coredata.sql
  17. # Set up shard info
  18. echo "INSERT INTO shardHosts VALUES (1, '127.0.0.1', 3306, 'up');" | $DB zotero_master
  19. echo "INSERT INTO shards VALUES (1, 1, 'zotero_shards', 'up', 0);" | $DB zotero_master
  20. # Load in shard schema
  21. cat shard.sql | $DB zotero_shards
  22. cat triggers.sql | $DB zotero_shards
  23. # Load in schema on id server
  24. cat ids.sql | $DB zotero_ids