mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-03-15 13:49:59 +00:00
3.2 KiB
3.2 KiB
Psych Coding 1
Base Setup
-
Create free account on Heroku
-
Install Heroku CLI https://devcenter.heroku.com/articles/getting-started-with-java#set-up
-
Install PostgreSQL https://www.postgresql.org/download/
brew install postgres sudo chown -R `whoami` /usr/local
-
Ensure postgres is started automatically on boot
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql postgres -V
-
Create new Idea Project
- Spring Initializer
-
- SDK 11 or 13
- com.psych.game
- Scaler Backend Project - Psych
- Java 11
- Maven
-
- Spring Boot Dev Tools
- Lombok
- Spring Web
- Rest Repositories
- Spring Web Services
- Spring Data JPA
- PostgreSQL Driver
- name: pragypsych
Hello World
- Create File: devtest.HelloController
package com.psych.game.devtest; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/dev-test") public class HelloController { @GetMapping("/") public String hello() { return "Hello, World!"; } }
- Try Build & Run
- Build succeeds
- Run fails: Because No DB
- Run postgres
psql postgres \du # display users \list # list databases create database psych_local; \connect psych_local # connect to specific DB \dt # display tables in current DB # psql postgres -U pragyagarwal
- Add psych_local DB to IntelliJ
- Create application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/psych_local spring.jpa.hibernate.ddl-auto=update
- Run again. Go to http://localhost:8080/dev-test/
Deploy on Heroku
- Create new project.
heroku create pragy-psych
- goto https://pragy-psych.herokuapp.com/ to find nothing
- add git
git init git add . git commit -m "Init"
- add heroku remote
git remote add heroku https://git.heroku.com/pragy-psych.git
- Deploy
git push heroku master
- Error: Push Rejected - invalid target release: 11
- Create system.properties
java.runtime.version=11
- Add, commit & deploy
- Goto https://pragy-psych.herokuapp.com/dev-test/
- Goto https://dashboard.heroku.com/apps/pragy-psych to see your stuff
- Note: it auto adds postgres free account
- See the logs
heroku logs --tail
Make the models
Test
https://pragy-psych.herokuapp.com/dev-test/ https://pragy-psych.herokuapp.com/dev-test/questions https://pragy-psych.herokuapp.com/dev-test/populate
Post Lecture
Restore
Google Docs – create and edit documents online, for free. YouTube