Skip to content

Commit 4869b5a

Browse files
committed
Using pg in yai branch, released new version
1 parent 175c551 commit 4869b5a

7 files changed

+58
-33
lines changed

.gitlab-ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
image: circleci/ruby:3.0.3-node-browsers
33

44
variables:
5+
POSTGRES_HOST: postgres
6+
POSTGRES_DB: pagila_test
7+
POSTGRES_USER: postgres
8+
POSTGRES_PASSWORD: postgres
59
CACHE_FALLBACK_KEY: "$CI_COMMIT_REF_SLUG"
610

711
before_script:
@@ -15,6 +19,8 @@ stages:
1519
- deploy
1620

1721
test:
22+
services:
23+
- postgres:12.9
1824
stage: test
1925
cache:
2026
- key:
@@ -27,6 +33,8 @@ test:
2733
- yarn.lock
2834
paths:
2935
- ".yarn-cache/"
36+
variables:
37+
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB
3038
script:
3139
- bundle install -j $(nproc)
3240
- yarn install --cache-folder .yarn-cache

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ENV RAILS_ENV="production" \
1313
BUNDLE_PATH="/usr/local/bundle" \
1414
BUNDLE_WITHOUT="development"
1515

16+
# Install libpq to access pg
17+
RUN apt-get update && apt-get install -y libpq-dev
1618

1719
# Throw-away build stage to reduce size of final image
1820
FROM base as build

Gemfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ gem 'rails-i18n'
1111
# released.
1212
gem 'mail', '= 2.8.1'
1313

14-
# Use sqlite3 as the database for Active Record
15-
gem 'sqlite3'
14+
gem 'pg'
1615
# Use Puma as the app server
1716
gem 'puma'
1817
# Use jquery as the JavaScript library

Gemfile.lock

+2-7
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ GEM
285285
racc (~> 1.4)
286286
orm_adapter (0.5.0)
287287
pagy (7.0.11)
288+
pg (1.5.6)
288289
psych (5.1.2)
289290
stringio
290291
public_suffix (5.0.4)
@@ -377,12 +378,6 @@ GEM
377378
actionpack (>= 5.2)
378379
activesupport (>= 5.2)
379380
sprockets (>= 3.0.0)
380-
sqlite3 (1.7.3-aarch64-linux)
381-
sqlite3 (1.7.3-arm-linux)
382-
sqlite3 (1.7.3-arm64-darwin)
383-
sqlite3 (1.7.3-x86-linux)
384-
sqlite3 (1.7.3-x86_64-darwin)
385-
sqlite3 (1.7.3-x86_64-linux)
386381
sshkit (1.22.0)
387382
mutex_m
388383
net-scp (>= 1.1.2)
@@ -470,6 +465,7 @@ DEPENDENCIES
470465
minitest
471466
minitest-ci
472467
pagy
468+
pg
473469
puma
474470
pundit
475471
rails (~> 7.1.2)
@@ -480,7 +476,6 @@ DEPENDENCIES
480476
simplecov
481477
spring
482478
sprockets
483-
sqlite3
484479
terser
485480
turbolinks
486481
tzinfo-data

README.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,32 @@ rm config/credentials.yml.enc
4040
export EDITOR=vim
4141
# paste credentials.yml.sample or skip
4242
bin/rails credentials:edit
43+
bin/rails db:create
4344
bin/rails test:all
4445
```
4546

46-
# Build & Run in docker mode
47+
# Create postgresql db user in Mac
4748

4849
```bash
49-
docker build --tag ericguo/oauth2id:main .
50-
# or `docker pull ericguo/oauth2id:main` to using existing images
51-
docker run -p 3000:3000 -d --restart always --name oauth2id --env RAILS_MASTER_KEY=YourMasterKey -v ./storage:/rails/storage ericguo/oauth2id:main
50+
sudo su - postgres
51+
createuser oauth2id_prod
52+
psql -d postgres
53+
ALTER ROLE oauth2id_prod LOGIN;
54+
ALTER USER oauth2id_prod PASSWORD 'oauth2id_prod';
55+
CREATE DATABASE oauth2id_prod WITH ENCODING='UTF8' OWNER=oauth2id_prod;
56+
logout
57+
```
58+
59+
# Build & Run in docker mode in OrbStack
60+
61+
```bash
62+
docker build --tag ericguo/oauth2id:yai .
63+
# or `docker pull ericguo/oauth2id:yai` to using existing images
64+
docker run -p 3000:3000 -d --restart always --name oauth2id-yai --env RAILS_MASTER_KEY=YourMasterKey --env OAUTH2ID_DB_NAME=oauth2id_prod --env OAUTH2ID_DB_HOST=host.docker.internal --env OAUTH2ID_DB_USERNAME=oauth2id_prod --env OAUTH2ID_DB_PASSWORD=oauth2id_prod -v ./storage:/rails/storage ericguo/oauth2id:yai
5265
# If can not start in above, do the debug.
53-
docker run --env RAILS_MASTER_KEY=YourMasterKey -v ./storage:/rails/storage -it ericguo/oauth2id:main bash
66+
docker run --env RAILS_MASTER_KEY=YourMasterKey --env OAUTH2ID_DB_NAME=oauth2id_prod --env OAUTH2ID_DB_HOST=host.docker.internal --env OAUTH2ID_DB_USERNAME=oauth2id_prod --env OAUTH2ID_DB_PASSWORD=oauth2id_prod -v ./storage:/rails/storage -it ericguo/oauth2id:yai bash
5467
# After success, push manually.
55-
docker push ericguo/oauth2id:main
68+
docker push ericguo/oauth2id:yai
5669
```
5770

5871
# Dev env setup

config/database.yml.sample

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
---
22
default: &default
3-
adapter: sqlite3
3+
adapter: postgresql
44
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
55
timeout: 5000
66

77
development:
88
primary:
99
<<: *default
10-
database: storage/oauth2id_dev.sqlite3
10+
database: <%= ENV.fetch("OAUTH2ID_DEV_DB_NAME") { 'oauth2id_dev' } %>
1111

1212
# Warning: The database defined as "test" will be erased and
1313
# re-generated from your development database when you run "rake".
1414
# Do not set this db to the same as development or production.
1515
test:
1616
primary:
1717
<<: *default
18-
database: storage/oauth2id_test.sqlite3
18+
database: <%= ENV.fetch("OAUTH2ID_TEST_DB_NAME") { 'oauth2id_test' } %>
19+
username: <%= ENV.fetch("OAUTH2ID_DB_USERNAME") { '' } %>
20+
host: <%= ENV.fetch("OAUTH2ID_DB_HOST") { '' } %>
1921

2022
production:
2123
primary:
2224
<<: *default
23-
database: storage/oauth2id_prod.sqlite3
25+
database: <%= ENV.fetch("OAUTH2ID_DB_NAME") { 'oauth2id_prod' } %>
26+
username: <%= ENV.fetch("OAUTH2ID_DB_USERNAME") { '' } %>
27+
password: <%= ENV.fetch("OAUTH2ID_DB_PASSWORD") { '' } %>
28+
host: <%= ENV.fetch("OAUTH2ID_DB_HOST") { '' } %>

db/schema.rb

+17-14
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_01_05_132232) do
13+
ActiveRecord::Schema[7.1].define(version: 2024_01_05_132232) do
14+
# These are extensions that must be enabled in order to support this database
15+
enable_extension "plpgsql"
16+
1417
create_table "allowlisted_jwts", force: :cascade do |t|
1518
t.string "jti", null: false
1619
t.string "aud", null: false
1720
t.datetime "exp", precision: nil, null: false
18-
t.integer "user_id", null: false
21+
t.bigint "user_id", null: false
1922
t.index ["jti"], name: "index_allowlisted_jwts_on_jti", unique: true
2023
t.index ["user_id"], name: "index_allowlisted_jwts_on_user_id"
2124
end
@@ -30,8 +33,8 @@
3033
end
3134

3235
create_table "department_users", force: :cascade do |t|
33-
t.integer "department_id", null: false
34-
t.integer "user_id", null: false
36+
t.bigint "department_id", null: false
37+
t.bigint "user_id", null: false
3538
t.datetime "created_at", precision: nil, null: false
3639
t.datetime "updated_at", precision: nil, null: false
3740
t.index ["department_id"], name: "index_department_users_on_department_id"
@@ -48,8 +51,8 @@
4851
end
4952

5053
create_table "oauth_access_grants", force: :cascade do |t|
51-
t.integer "resource_owner_id", null: false
52-
t.integer "application_id", null: false
54+
t.bigint "resource_owner_id", null: false
55+
t.bigint "application_id", null: false
5356
t.string "token", null: false
5457
t.integer "expires_in", null: false
5558
t.text "redirect_uri", null: false
@@ -64,8 +67,8 @@
6467
end
6568

6669
create_table "oauth_access_tokens", force: :cascade do |t|
67-
t.integer "resource_owner_id"
68-
t.integer "application_id"
70+
t.bigint "resource_owner_id"
71+
t.bigint "application_id"
6972
t.string "token", null: false
7073
t.string "refresh_token"
7174
t.integer "expires_in"
@@ -111,8 +114,8 @@
111114
end
112115

113116
create_table "position_users", force: :cascade do |t|
114-
t.integer "position_id", null: false
115-
t.integer "user_id", null: false
117+
t.bigint "position_id", null: false
118+
t.bigint "user_id", null: false
116119
t.boolean "main_position", default: false
117120
t.datetime "created_at", precision: nil, null: false
118121
t.datetime "updated_at", precision: nil, null: false
@@ -128,7 +131,7 @@
128131
end
129132

130133
create_table "profiles", force: :cascade do |t|
131-
t.integer "user_id"
134+
t.bigint "user_id"
132135
t.string "title"
133136
t.boolean "gender"
134137
t.string "phone"
@@ -140,8 +143,8 @@
140143
end
141144

142145
create_table "user_allowed_applications", force: :cascade do |t|
143-
t.integer "user_id"
144-
t.integer "oauth_application_id"
146+
t.bigint "user_id"
147+
t.bigint "oauth_application_id"
145148
t.boolean "enable", default: true
146149
t.datetime "created_at", precision: nil, null: false
147150
t.datetime "updated_at", precision: nil, null: false
@@ -150,7 +153,7 @@
150153
end
151154

152155
create_table "user_sign_in_histories", force: :cascade do |t|
153-
t.integer "user_id"
156+
t.bigint "user_id"
154157
t.datetime "sign_in_at", precision: nil
155158
t.text "user_agent"
156159
t.string "sign_in_ip"

0 commit comments

Comments
 (0)