1、数据库初始化
(1)登录数据库,创建名为data_system的database
ubuntu@VM-16-15-ubuntu:~/data_symtem$ mysql -u root -p //输入你在5.2 节配置的数据库密码 Enter password: //创建一个名为data_system数据库 mysql> create database data_system;
(2)修改config/database.yml文件
在本地电脑修改代码,将生产环境的数据库名字修改成刚刚创建的database名字
production: <<: *default database: data_system
(3)在本地电脑上修改代码之后,用git提交到版本库,再在云服务器上面下来代码。
在本地电脑上提交代码
/vagrant/data_system$ git add . /vagrant/data_system$ git commit -m "database" /vagrant/data_system$ git push origin master
到服务器上下拉代码
ubuntu@VM-16-15-ubuntu:~/data_symtem$ git pull origin master
4)回到项目目录下,运行rake db:migrate
将映射文件映射到数据库中
ubuntu@VM-16-15-ubuntu:~/data_symtem$ rake db:migrate //系统返回信息 == 20180915153542 CreateAccounts: migrating =================================== -- create_table(:accounts) -> 0.0718s == 20180915153542 CreateAccounts: migrated (0.0720s) ========================== == 20180928104207 AddAuthTokenToAccounts: migrating =========================== -- add_column(:accounts, :auth_token, :string) -> 0.3115s == 20180928104207 AddAuthTokenToAccounts: migrated (0.3116s) ================== == 20181015070219 CreatePosts: migrating ====================================== -- create_table(:posts) -> 0.3994s == 20181015070219 CreatePosts: migrated (0.3995s) ============================= == 20181031104807 CreateThumbs: migrating ===================================== -- create_table(:thumbs) -> 0.1826s == 20181031104807 CreateThumbs: migrated (0.1827s) ============================ == 20181127085433 CreateComments: migrating =================================== -- create_table(:comments) -> 0.2406s == 20181127085433 CreateComments: migrated (0.2408s) ========================== == 20181128074435 RenameRePostIdForComment: migrating ========================= -- rename_column(:comments, :re_post_id, :re_comment_id) -> 0.0322s -- rename_column(:comments, :re_account_id, :re_reply_id) -> 0.0311s == 20181128074435 RenameRePostIdForComment: migrated (0.0638s) ================
2、gem初始化
(1)运行bundle install
,安装Gemfile文件中声明的gem插件
ubuntu@VM-16-15-ubuntu:~/data_symtem$ bundle install