diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76afa13..920b5a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,29 +10,12 @@ jobs: strategy: matrix: ruby-version: ['3.2.2'] - node: ['14', '16'] + node: ['20'] env: RAILS_ENV: test - MYSQL_HOST: 127.0.0.1 - MYSQL_PORT: 3306 - MYSQL_VERSION: 5.7 - MYSQL_DATABASE: hours_test - MYSQL_ROOT_PASSWORD: rootpassword - MYSQL_USER: user - MYSQL_USER_PASSWORD: password NOKOGIRI_USE_SYSTEM_LIBRARIES: true steps: - # Set up MySQL first because it can take some time to start up - - uses: mirromutth/mysql-action@v1.1 - with: - host port: ${{ env.MYSQL_PORT }} - container port: ${{ env.MYSQL_PORT }} - character set server: 'utf8mb4' - mysql version: ${{ env.MYSQL_VERSION }} - collation server: 'utf8mb4_general_ci' - mysql database: ${{ env.MYSQL_DATABASE }} - mysql root password: ${{ env.MYSQL_ROOT_PASSWORD }} - uses: actions/checkout@v2 - name: Install libxslt for nokogiri gem (required for version < 1.11) run: sudo apt-get install -y libxml2-dev libxslt-dev @@ -49,21 +32,9 @@ jobs: node-version: ${{ matrix.node }} - run: npm install -g yarn - run: yarn install - - run: cp config/database.gh-actions.yml config/database.yml + - run: cp config/database.template.yml config/database.yml - run: cp config/secrets.template.yml config/secrets.yml - run: cp config/wifi_density.template.yml config/wifi_density.yml - # Before we run any MySQL-related commands, make sure that MySQL has started - - name: Wait for MySQL to start - run: | - for i in 1 2 3 4 5; do mysqladmin ping -u root -p${{ env.MYSQL_ROOT_PASSWORD }} -h ${{ env.MYSQL_HOST }} --port ${{ env.MYSQL_PORT }} && break || sleep 5; done - # Run one final time to return success or error status (cancelling CI run if we get an error status) - mysqladmin ping -u root -p${{ env.MYSQL_ROOT_PASSWORD }} -h ${{ env.MYSQL_HOST }} --port ${{ env.MYSQL_PORT }} - - name: Grant database permissions - run: | - mysql -u root -p${{ env.MYSQL_ROOT_PASSWORD }} -h ${{ env.MYSQL_HOST }} --port ${{ env.MYSQL_PORT }} -e "CREATE USER '${{ env.MYSQL_USER }}'@'%' IDENTIFIED BY '${{ env.MYSQL_USER_PASSWORD }}';"; - mysql -u root -p${{ env.MYSQL_ROOT_PASSWORD }} -h ${{ env.MYSQL_HOST }} --port ${{ env.MYSQL_PORT }} -e "GRANT ALL PRIVILEGES ON ${{ env.MYSQL_DATABASE }}.* TO '${{ env.MYSQL_USER }}'@'%';"; - - name: Database user connection test - run: mysql -u ${{ env.MYSQL_USER }} -p${{ env.MYSQL_USER_PASSWORD }} -h ${{ env.MYSQL_HOST }} --port ${{ env.MYSQL_PORT }} -e "SHOW DATABASES;"; - run: RAILS_ENV=test bundle exec rake db:schema:load --trace - run: RAILS_ENV=test bundle exec rake db:test:prepare - name: Run tests diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..209e3ef --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20 diff --git a/.ruby-version b/.ruby-version index c939cb5..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.0.3 \ No newline at end of file +3.2.2 diff --git a/Gemfile b/Gemfile index fbca204..ae91378 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,7 @@ gem 'jbuilder', '~> 2.5' # gem 'redis', '~> 3.0' # Use sqlite3 as the database for Active Record -gem "sqlite3", "~> 1.4.2" +gem "sqlite3", "~> 1.5.0" gem 'mysql2' diff --git a/Gemfile.lock b/Gemfile.lock index 80eabda..0a7c75c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,7 +83,7 @@ GEM bootsnap (1.10.3) msgpack (~> 1.2) builder (3.2.4) - byebug (11.0.0) + byebug (11.1.3) cancancan (3.5.0) capistrano (3.17.3) airbrussh (>= 1.0.0) @@ -289,7 +289,8 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.4.2) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) sshkit (1.21.6) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) @@ -357,7 +358,7 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sprockets-rails - sqlite3 (~> 1.4.2) + sqlite3 (~> 1.5.0) tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) diff --git a/README.md b/README.md index 51df791..924b81c 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,18 @@ - Git clone this repo - Setup a MySQL db locally and add credentials to config/database.yml - `$ bundle install` -- `$ rake db:migrate` -- If you don't have yarn currently installed please run `brew install yarn` -- `$ yarn` -- `$ rake db:seed` +- `$ bundle exec rake db:migrate` +- If you don't have yarn currently installed, install node 20 (preferably using nvm) and then run `npm install -g yarn` +- `$ yarn install` +- `$ bundle exec rake db:seed` - Seeds the db with two locations and an administrative user. Administrative credentials are: + The above seed command will seed the db with two locations and an administrative user. Administrative credentials are: ``` name: Test User email: admin@example.com ``` -- `$ rails s` -- Navigate to `localhost:3000` +- `$ bundle exec rails s` +- Navigate to `http://localhost:3000` ## Testing diff --git a/config/database.gh-actions.yml b/config/database.gh-actions.yml deleted file mode 100644 index 00fca4c..0000000 --- a/config/database.gh-actions.yml +++ /dev/null @@ -1,12 +0,0 @@ -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. - -test: - adapter: mysql2 - host: 127.0.0.1 # GitHub Actions uses Docker, so we use 172.17.0.1 instead of 127.0.0.1 - port: 3306 - pool: 5 - database: hours_test - username: user - password: password diff --git a/config/database.template.yml b/config/database.template.yml index 90ab6ae..a33fe83 100644 --- a/config/database.template.yml +++ b/config/database.template.yml @@ -1,17 +1,15 @@ default: &default - adapter: mysql2 + adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - database: "hours" - username: "user" - password: "password" + timeout: 5000 development: <<: *default - database: "hours_dev" + database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default - database: "hours_test" + database: db/test.sqlite3 diff --git a/db/schema.rb b/db/schema.rb index b060934..e50128e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -36,7 +36,7 @@ t.string "summary" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.bigint "primary_location_id" + t.integer "primary_location_id" t.boolean "primary", default: false t.boolean "front_page", default: false, null: false t.string "short_note" @@ -50,7 +50,7 @@ end create_table "permissions", force: :cascade do |t| - t.bigint "user_id" + t.integer "user_id" t.string "role", null: false t.string "subject_class" t.integer "subject_id" @@ -69,7 +69,7 @@ t.boolean "tbd", default: false, null: false t.boolean "closed", default: false, null: false t.string "note" - t.bigint "location_id" + t.integer "location_id" t.index ["close"], name: "index_timetables_on_close" t.index ["date"], name: "index_timetables_on_date" t.index ["location_id", "date"], name: "index_timetables_on_location_id_and_date", unique: true diff --git a/db/seeds.rb b/db/seeds.rb index e2bb9d8..a4964ba 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,8 +7,8 @@ # Character.create(name: 'Luke', movie: movies.first) all_location = Location.create(name: "All Locations", code: "all", primary: true, front_page: false) -butler = Location.create(name: "Butler", code: "butler", primary: true) -avery = Location.create(name: "Avery", code: "avery", primary: true) +butler = Location.create(name: "Butler", code: "butler", primary: true, front_page: true) +avery = Location.create(name: "Avery", code: "avery", primary: true, front_page: true) rbml = Location.create(name: "Rare Books", code: "rbml", primary_location: butler) admin = User.create(email: "admin@example.com", provider: :developer, name: "Test Admin")