Skip to content

Commit fa008e3

Browse files
authored
Dev environment: Add basic Devcontainer pointed at sqlite (#1484)
* Add devcontainer * Fix image * Fix * Swap to sqlite * Fix DB migrations on other DBs that aren't postgres * Add libpq-dev, as its easier than explaining to new devs to run CI=1 DB=sqlite bundle * Fix Ruby 3.4 deps * Fix Ruby 3.4 deps * Adjust migration * Change history * Add install script * Allow in dev the codespaces proxy * Update post install * Rubocop * Update 20230422234321_create_action_text_tables.action_text.rb * Fix devcontainer * Purge snap version * Update firefox install * Change migration to be optional * Change migration to be optional * Change migration to be optional * Fix forms
1 parent 67a41c4 commit fa008e3

11 files changed

+118
-27
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
3+
"features": {
4+
"ghcr.io/devcontainers/features/ruby:1": {}
5+
},
6+
"postCreateCommand": "sh .devcontainer/install.sh"
7+
}

.devcontainer/install.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /bin/bash
2+
3+
sudo add-apt-repository -y ppa:mozillateam/ppa
4+
5+
echo -e "Package: firefox*\nPin: release o=LP-PPA-mozillateam-ppa\nPin-Priority: 550\n\nPackage: firefox*\nPin: release o=Ubuntu\nPin-Priority: -1" | sudo tee /etc/apt/preferences.d/99-mozillateamppa
6+
7+
sudo apt-get update
8+
9+
sudo apt install -y libpq-dev # Not strictly needed, but easier than explaining to users to constantly pass DB=sqlite
10+
sudo apt install -y firefox
11+
12+
bundle
13+
14+
cp config/database.sqlite.yml config/database.yml
15+
16+
bundle exec rake db:create
17+
bundle exec rake db:migrate
18+
bundle exec rake db:seed
19+
bundle exec rake ffcrm:demo:load
20+
21+
bundle exec rails s -b 0.0.0.0

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,11 @@ gem 'mini_magick'
109109
gem 'image_processing', '~> 1.2'
110110
gem 'jquery-ui-rails', git: 'https://github.com/jquery-ui-rails/jquery-ui-rails.git', tag: 'v7.0.0' # See https://github.com/jquery-ui-rails/jquery-ui-rails/issues/146
111111

112+
# Ruby 3.4 explict dependencies
113+
gem 'bigdecimal'
114+
gem 'mutex_m'
115+
gem 'drb'
116+
gem 'csv'
117+
112118
# Workaround problems from concurrent-ruby 1.3.5
113119
require "logger"

Gemfile.lock

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ GEM
109109
execjs (~> 2)
110110
base64 (0.2.0)
111111
bcrypt (3.1.20)
112+
bigdecimal (3.2.2)
112113
bootsnap (1.18.6)
113114
msgpack (~> 1.2)
114115
bootstrap (5.0.2)
@@ -159,6 +160,7 @@ GEM
159160
crass (1.0.6)
160161
css_parser (1.19.0)
161162
addressable
163+
csv (3.3.5)
162164
database_cleaner (2.1.0)
163165
database_cleaner-active_record (>= 2, < 3)
164166
database_cleaner-active_record (2.2.0)
@@ -178,9 +180,8 @@ GEM
178180
devise (>= 4.9.0)
179181
rails-i18n
180182
diff-lcs (1.6.1)
181-
dynamic_form (1.3.1)
182-
actionview (> 5.2.0)
183-
activemodel (> 5.2.0)
183+
drb (2.2.3)
184+
dynamic_form (1.2.0)
184185
email_reply_parser_ffcrm (0.5.0)
185186
erubi (1.13.1)
186187
execjs (2.10.0)
@@ -261,6 +262,7 @@ GEM
261262
libv8-node (~> 24.1.0.0)
262263
minitest (5.25.5)
263264
msgpack (1.8.0)
265+
mutex_m (0.3.0)
264266
nenv (0.3.0)
265267
net-imap (0.5.7)
266268
date
@@ -507,6 +509,7 @@ DEPENDENCIES
507509
acts-as-taggable-on (>= 3.4.3)
508510
acts_as_commentable!
509511
acts_as_list
512+
bigdecimal
510513
bootsnap
511514
bootstrap (~> 5.0.0)
512515
brakeman
@@ -520,10 +523,12 @@ DEPENDENCIES
520523
coffee-rails
521524
coffee-script-source (~> 1.8, >= 1.8.0)
522525
country_select
526+
csv
523527
database_cleaner
524528
devise (~> 4.6)
525529
devise-encryptable
526530
devise-i18n
531+
drb
527532
dynamic_form
528533
email_reply_parser_ffcrm
529534
execjs
@@ -541,6 +546,7 @@ DEPENDENCIES
541546
jquery-ui-rails!
542547
mini_magick
543548
mini_racer
549+
mutex_m
544550
nokogiri (>= 1.8.1)
545551
paper_trail (~> 15.1.0)
546552
pg

app/controllers/application_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def auto_complete
7979
# See http://blog.nvisium.com/2014/09/understanding-protectfromforgery.html for more details.
8080
#----------------------------------------------------------------------------
8181
def handle_unverified_request
82-
raise ActionController::InvalidAuthenticityToken
82+
unless ENV.fetch('CODESPACE_NAME', nil) && Rails.env.development?
83+
raise ActionController::InvalidAuthenticityToken
84+
end
8385
end
8486

8587
#

config/environments/development.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,20 @@
8383
# Checks for improperly declared sprockets dependencies.
8484
# Raises helpful error messages.
8585
config.assets.raise_runtime_errors = true
86+
87+
# Are we running in a GitHub Codespace?
88+
if ENV.fetch('CODESPACE_NAME', nil)
89+
config.host = "#{ENV['CODESPACE_NAME']}-3000.app.github.dev:443"
90+
config.hosts << ".preview.app.github.dev"
91+
config.hosts << ".app.github.dev"
92+
93+
config.force_ssl = true
94+
config.action_dispatch.cookies_same_site_protection = :lax
95+
96+
config.action_dispatch.trusted_proxies = [
97+
# Trust all IPs (safe in dev only)
98+
IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")
99+
]
100+
end
86101
end
87102
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
# This migration comes from action_text (originally 20180528164100)
4+
class OptionallyCreateActionTextTables < ActiveRecord::Migration[6.0]
5+
def change
6+
# Use Active Record's configured type for primary and foreign keys
7+
primary_key_type, foreign_key_type = primary_and_foreign_key_types
8+
9+
create_table :action_text_rich_texts, id: primary_key_type, if_not_exists: true do |t|
10+
t.string :name, null: false
11+
t.text :body, size: :long
12+
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
13+
14+
t.timestamps
15+
16+
t.index %i[record_type record_id name], name: "index_action_text_rich_texts_uniqueness", unique: true
17+
end
18+
end
19+
20+
private
21+
22+
def primary_and_foreign_key_types
23+
config = Rails.configuration.generators
24+
setting = config.options[config.orm][:primary_key_type]
25+
primary_key_type = setting || :primary_key
26+
foreign_key_type = setting || :bigint
27+
[primary_key_type, foreign_key_type]
28+
end
29+
end

db/migrate/20230526211831_create_active_storage_tables.active_storage.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def change
66
# Use Active Record's configured type for primary and foreign keys
77
primary_key_type, foreign_key_type = primary_and_foreign_key_types
88

9-
create_table :active_storage_blobs, id: primary_key_type do |t|
9+
create_table :active_storage_blobs, id: primary_key_type, if_not_exists: true do |t|
1010
t.string :key, null: false
1111
t.string :filename, null: false
1212
t.string :content_type
@@ -19,7 +19,7 @@ def change
1919
t.index [:key], unique: true
2020
end
2121

22-
create_table :active_storage_attachments, id: primary_key_type do |t|
22+
create_table :active_storage_attachments, id: primary_key_typ, if_not_exists: true do |t|
2323
t.string :name, null: false
2424
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
2525
t.references :blob, null: false, type: foreign_key_type
@@ -30,7 +30,7 @@ def change
3030
t.foreign_key :active_storage_blobs, column: :blob_id
3131
end
3232

33-
create_table :active_storage_variant_records, id: primary_key_type do |t|
33+
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
3434
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
3535
t.string :variation_digest, null: false
3636

db/migrate/20230526212613_convert_to_active_storage.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ class ConvertToActiveStorage < ActiveRecord::Migration[5.2]
44
require 'open-uri'
55

66
def up
7-
get_blob_id = case ENV['CI'] && ENV['DB']
8-
when 'sqlite'
9-
'LAST_INSERT_ROWID()'
10-
when 'mysql'
11-
'LAST_INSERT_ID()'
12-
when 'postgres'
13-
'LASTVAL()'
14-
else
15-
'LASTVAL()'
16-
end
17-
187
ActiveRecord::Base.connection.raw_connection.then do |conn|
8+
get_blob_id = case ENV['CI'] && ENV['DB']
9+
when 'mysql'
10+
'LAST_INSERT_ID()'
11+
else
12+
'LASTVAL()'
13+
end
14+
get_blob_id = 'LAST_INSERT_ROWID()' if conn.is_a?(SQLite3::Database)
1915
if conn.is_a?(::PG::Connection)
16+
get_blob_id = 'LASTVAL()'
2017
conn.prepare('active_storage_blobs', <<-SQL)
2118
INSERT INTO active_storage_blobs (
2219
key, filename, content_type, metadata, byte_size, checksum, created_at

db/schema.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
# It's strongly recommended that you check this file into your version control system.
1212

1313
ActiveRecord::Schema[7.0].define(version: 2023_05_26_212613) do
14-
# These are extensions that must be enabled in order to support this database
15-
enable_extension "plpgsql"
16-
1714
create_table "account_contacts", force: :cascade do |t|
1815
t.integer "account_id"
1916
t.integer "contact_id"
@@ -55,6 +52,16 @@
5552
t.index ["user_id", "name", "deleted_at"], name: "index_accounts_on_user_id_and_name_and_deleted_at", unique: true
5653
end
5754

55+
create_table "action_text_rich_texts", force: :cascade do |t|
56+
t.string "name", null: false
57+
t.text "body"
58+
t.string "record_type", null: false
59+
t.bigint "record_id", null: false
60+
t.datetime "created_at", null: false
61+
t.datetime "updated_at", null: false
62+
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
63+
end
64+
5865
create_table "active_storage_attachments", force: :cascade do |t|
5966
t.string "name", null: false
6067
t.string "record_type", null: false
@@ -247,12 +254,12 @@
247254
t.text "collection"
248255
t.boolean "disabled"
249256
t.boolean "required"
250-
t.integer "maxlength"
257+
t.integer "maxlength", limit: 4
251258
t.datetime "created_at", precision: nil
252259
t.datetime "updated_at", precision: nil
253260
t.integer "pair_id"
254261
t.text "settings"
255-
t.integer "minlength", default: 0
262+
t.integer "minlength", limit: 4, default: 0
256263
t.string "pattern"
257264
t.string "autofocus"
258265
t.string "autocomplete"
@@ -417,7 +424,7 @@
417424

418425
create_table "users", force: :cascade do |t|
419426
t.string "username", limit: 32, default: "", null: false
420-
t.string "email", limit: 254, default: "", null: false
427+
t.string "email", limit: 254
421428
t.string "first_name", limit: 32
422429
t.string "last_name", limit: 32
423430
t.string "title", limit: 64
@@ -448,8 +455,8 @@
448455
t.datetime "remember_created_at", precision: nil
449456
t.string "authentication_token"
450457
t.string "confirmation_token", limit: 255
451-
t.datetime "confirmed_at", precision: nil
452-
t.datetime "confirmation_sent_at", precision: nil
458+
t.datetime "confirmed_at"
459+
t.datetime "confirmation_sent_at"
453460
t.index ["authentication_token"], name: "index_users_on_authentication_token", unique: true
454461
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
455462
t.index ["email"], name: "index_users_on_email"
@@ -461,7 +468,7 @@
461468
create_table "versions", force: :cascade do |t|
462469
t.string "item_type", null: false
463470
t.integer "item_id", null: false
464-
t.string "event", limit: 512, null: false
471+
t.string "event", limit: 512
465472
t.string "whodunnit"
466473
t.text "object"
467474
t.datetime "created_at", precision: nil

0 commit comments

Comments
 (0)