Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequelize 步驟 & heroku #22

Open
ddylanlinn opened this issue Aug 8, 2021 · 0 comments
Open

Sequelize 步驟 & heroku #22

ddylanlinn opened this issue Aug 8, 2021 · 0 comments

Comments

@ddylanlinn
Copy link
Collaborator

ddylanlinn commented Aug 8, 2021

npm install
npm init
npm install bcrypt
npm install body-parser
npm installbcypt connect-flash
npm install ejs
npm install express
npm install express-session
npm install --save sequelize
npm install --save mysql2
npm install mysql
npm install --save sequelize-cli
安裝各檔案

npx sequelize-cli init
到config修改db登入資訊
規劃好資料結構 建立models
npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string

npx sequelize-cli db:migrate


heroku

1.在專案的package.json中的
script裡加入
"db:migrate": "npx sequelize db:migrate", // 執行sequelize migrate 產生資料庫
"start": "npm run db:migrate && node index.js", // 執行 index

另外加入引擎執行版本
"engines": {
"node": "14.x"
},

2.在index.js中的port加入環境變數
const port = process.env.PORT || 5001

3.建立版本控制 $git init

4.建立 .gitignore檔
填入 node_modules //不上傳

5.git add + commit

6.$heroku create

7.$git push heroku master

此時靜態部屬完成
若有資料庫則會出現錯誤
$heroku logs --tail 檢視錯誤訊息

8.點選ADD-ONS 的 ClearDB MySQL (or heroku Postgres)

9.照文件輸入
$heroku addons:create cleardb:ignite

10.回到 heroku 個人頁面新建的專案底下
設定裡面的 Config Vars 會有 CLEARDB_DATABASE_URL
及 mysql://帳號:密碼@host DATABASE?reconnect=true

11.回到本地 config資料夾中的 config.json 中
在production項目中新增 "use_env_variable": "CLEARDB_DATABASE_URL"

  1. git add + commit + push 即可

若要使用其他DB軟體連上資料庫
HOST 帳號 密碼為個人頁面該專案底下 CLEARDB_DATABASE_URL
mysql://帳號:密碼@host DATABASE?reconnect=true

@ddylanlinn ddylanlinn changed the title Sequelize 步驟 Sequelize 步驟 & heroku Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant