Skip to content

Commit

Permalink
Release Trilogy Adapter
Browse files Browse the repository at this point in the history
Trilogy Adapter is a database adapter for [Trilogy][].

It's currently in production use on github.com.

[Trilogy]: https://github.com/github/trilogy

Co-authored-by: Aaron Patterson <tenderlove@github.com>
Co-authored-by: Adam Roben <adam@roben.org>
Co-authored-by: Ali Ibrahim <aibrahim2k2@gmail.com>
Co-authored-by: Aman Gupta <aman@tmm1.net>
Co-authored-by: Arthur Nogueira Neves <github@arthurnn.com>
Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Ashe Connor <kivikakk@github.com>
Co-authored-by: Brandon Keepers <brandon@opensoul.org>
Co-authored-by: Brian Lopez <seniorlopez@gmail.com>
Co-authored-by: Brooke Kuhlmann <brooke@testdouble.com>
Co-authored-by: Bryana Knight <bryanaknight@github.com>
Co-authored-by: Carl Brasic <brasic@github.com>
Co-authored-by: Chris Bloom <chrisbloom7@github.com>
Co-authored-by: Cliff Pruitt <cliff.pruitt@cliffpruitt.com>
Co-authored-by: Daniel Colson <composerinteralia@github.com>
Co-authored-by: David Calavera <david.calavera@gmail.com>
Co-authored-by: David Celis <davidcelis@github.com>
Co-authored-by: David Ratajczak <david@mockra.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Eileen Uchitelle <eileencodes@gmail.com>
Co-authored-by: Garrett Bjerkhoel <garrett@github.com>
Co-authored-by: Georgi Knox <georgicodes@github.com>
Co-authored-by: HParker <HParker@github.com>
Co-authored-by: Hailey Somerville <hailey@hailey.lol>
Co-authored-by: James Dennes <jdennes@gmail.com>
Co-authored-by: Jane Sternbach <janester@github.com>
Co-authored-by: Jess Bees <toomanybees@github.com>
Co-authored-by: Jesse Toth <jesse.toth@github.com>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: John Barnette <jbarnette@github.com>
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: John Nunemaker <nunemaker@gmail.com>
Co-authored-by: Jonathan Hoyt <hoyt@github.com>
Co-authored-by: Katrina Owen <kytrinyx@github.com>
Co-authored-by: Keeran Raj Hawoldar <keeran@gmail.com>
Co-authored-by: Kevin Solorio <soloriok@gmail.com>
Co-authored-by: Leo Correa <lcorr005@gmail.com>
Co-authored-by: Lizz Hale <lizzhale@github.com>
Co-authored-by: Matt Jones <al2o3cr@gmail.com>
Co-authored-by: Matthew Draper <matthewd@github.com>
Co-authored-by: Max Veytsman <mveytsman@github.com>
Co-authored-by: Nathan Witmer <nathan@zerowidth.com>
Co-authored-by: Nick Holden <nick.r.holden@gmail.com>
Co-authored-by: Patrick Reynolds <patrick.reynolds@github.com>
Co-authored-by: Rob Sanheim <rsanheim@gmail.com>
Co-authored-by: Rocio Delgado <rocio@github.com>
Co-authored-by: Sam Lambert <sam.lambert@github.com>
Co-authored-by: Shay Frendt <shay@github.com>
Co-authored-by: Shlomi Noach <shlomi-noach@github.com>
Co-authored-by: Sophie Haskins <sophaskins@github.com>
Co-authored-by: Thomas Maurer <tma@github.com>
Co-authored-by: Tim Pease <tim.pease@gmail.com>
Co-authored-by: Yossef Mendelssohn <ymendel@pobox.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zhongying Qiao <cryptoque@users.noreply.github.com>
  • Loading branch information
Show file tree
Hide file tree
Showing 32 changed files with 1,832 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.gitignore
.env*
Dockerfile
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on: push

jobs:
test:
strategy:
matrix:
rails_version:
- main
ruby_version:
- '3.0'
fail-fast: false
runs-on: ubuntu-latest
name: Test on Rails ${{ matrix.rails_version }}
env:
RAILS_VERSION: ${{ matrix.rails_version }}
DB_HOST: 127.0.0.1
DB_PORT: 3306
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
- name: Cache .gem files
uses: actions/cache@v3
with:
key: gems-${{ matrix.rails_version }}-${{ hashFiles('Gemfile', '*.gemspec') }}
path: vendor/cache
- name: Start mysql
run: docker run -d --rm --name=mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -p 3306:3306 --health-interval=1s --health-timeout=5s --health-retries=5 --volume="$(pwd)"/script/setup.sql:/docker-entrypoint-initdb.d/setup.sql --health-cmd='mysql trilogy_test -e "select * from posts"' mysql:5.7 --sql_mode=NO_ENGINE_SUBSTITUTION --log-bin --server-id=1 --gtid-mode=ON --enforce-gtid-consistency=ON
- uses: ruby/setup-ruby@bd94d6a504586da892a5753afdd1480096ed30df
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Wait for mysql
run: timeout -v '1m' bash -c 'until [ "`docker inspect -f {{.State.Health.Status}} mysql `" == "healthy" ]; do sleep 0.5; done'
- name: Run tests
run: bundle exec rake
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.bundle
.rubocop-http*
pkg/*
Gemfile.lock
tmp
log/*
.byebug_history
vendor/cache/byebug-*.gem
vendor/cache/coderay-*.gem
vendor/cache/concurrent-ruby-*.gem
vendor/cache/connection_pool-*.gem
vendor/cache/i18n-*.gem
vendor/cache/method_source-*.gem
vendor/cache/minitest-*.gem
vendor/cache/minitest-focus-*.gem
vendor/cache/pry-*.gem
vendor/cache/pry-*.gem
vendor/cache/rake-*.gem
vendor/cache/toxiproxy-*.gem
vendor/cache/tzinfo-*.gem
vendor/cache/zeitwerk-*.gem
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.4
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## 2.0.0

### Added

- Initial release of the adapter.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @github/ruby-architecture
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at opensource+trilogy@github.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Contributing

[fork]: https://github.com/github/activerecord-trilogy-adapter/fork
[pr]: https://github.com/github/activerecord-trilogy-adapter/compare
[style]: https://github.com/styleguide/ruby
[code-of-conduct]: CODE_OF_CONDUCT.md

Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.

Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.md).

Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.

## Setup

For local development, run:

bin/setup

To test, run:

bundle exec rake

## Submitting a pull request

0. [Fork][fork] and clone the repository
0. Configure and install the dependencies: `bin/setup`
0. Make sure the tests pass on your machine: `bundle exec rake`
0. Create a new branch: `git checkout -b my-branch-name`
0. Make your change, add tests, and make sure the tests still pass
0. Push to your fork and [submit a pull request][pr]
0. Pat your self on the back and wait for your pull request to be reviewed and merged.

Here are a few things you can do that will increase the likelihood of your pull request being accepted:

- Follow the [style guide][style].
- Write tests.
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).

## Resources

- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
- [GitHub Help](https://help.github.com)

9 changes: 9 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ruby:2.6.3
LABEL maintainer="github@github.com"

RUN apt-get update -qq && apt-get install -y default-mysql-client

WORKDIR /app
COPY . .

CMD ["script/test"]
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

source "https://rubygems.org"

if !ENV["RAILS_VERSION"] || ENV["RAILS_VERSION"] == "main"
gem "activerecord", git: "https://github.com/rails/rails", branch: "main"
else
gem "activerecord", ENV["RAILS_VERSION"]
end

gemspec
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2018-2022 GitHub, Inc.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Trilogy Adapter

Active Record database adapter for [Trilogy](https://github.com/github/trilogy)

## Requirements

- [Ruby](https://www.ruby-lang.org) 2.7 or higher
- [Active Record](https://github.com/rails/rails) 7.1 or higher
- [Trilogy](https://github.com/github/trilogy) 2.1.1 or higher

## Setup

* Add the following to your Gemfile:

```rb
gem "activerecord-trilogy-adapter"
```

* Update your database configuration (e.g. `config/database.yml`) to use
`trilogy` as the adapter.

## Versioning

Read [Semantic Versioning](https://semver.org) for details. Briefly, it means:

- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
- Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
- Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.

## Code of Conduct

Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By
participating in this project you agree to abide by its terms.

## Contributions

Read [CONTRIBUTING](CONTRIBUTING.md) for details.

## License

Released under the [MIT License](LICENSE.md).
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

begin
require "bundler/gem_tasks"

require "rake/testtask"

Rake::TestTask.new do |task|
task.libs << "test"
task.pattern = "test/**/*_test.rb"
end
rescue LoadError => error
puts error.message
end

task default: %i[test]
31 changes: 31 additions & 0 deletions activerecord-trilogy-adapter.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative "lib/trilogy_adapter/version"

Gem::Specification.new do |spec|
spec.name = "activerecord-trilogy-adapter"
spec.version = TrilogyAdapter::VERSION
spec.platform = Gem::Platform::RUBY
spec.authors = ["GitHub Engineering"]
spec.email = ["opensource+trilogy@github.com"]
spec.homepage = "https://github.com/github/activerecord-trilogy-adapter"
spec.summary = "Active Record adapter for https://github.com/github/trilogy."
spec.license = "MIT"

spec.metadata = {
"source_code_uri" => "https://github.com/github/activerecord-trilogy-adapter",
"changelog_uri" => "https://github.com/github/activerecord-trilogy-adapter/blob/master/CHANGELOG.md",
"bug_tracker_uri" => "https://github.com/github/activerecord-trilogy-adapter/issues"
}

spec.add_dependency "trilogy", ">= 2.1.1"
spec.add_dependency "activerecord", ">= 7.1.0.alpha"
spec.add_development_dependency "minitest", "~> 5.11"
spec.add_development_dependency "minitest-focus", "~> 1.1"
spec.add_development_dependency "pry", "~> 0.10"
spec.add_development_dependency "rake", "~> 12.3"

spec.files = Dir["lib/**/*"]
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
spec.require_paths = ["lib"]
end
9 changes: 9 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /usr/bin/env bash

set -o nounset # Exit, with error message, when attempting to use an undefined variable.
set -o errexit # Abort script at first error, when a command exits with non-zero status.
set -o pipefail # Return exit status of the last command in the pipe that returned a non-zero return value.
IFS=$'\n\t' # Defines newlines and tabs as delimiters for splitting words and iterating arrays.

bundle install
$(brew --prefix)/opt/mysql@5.7/bin/mysql --user=root --password= < "script/setup.sql"
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.5"
services:
db:
image: mysql:5.7
command: --sql_mode="NO_ENGINE_SUBSTITUTION"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- "db-data:/var/lib/mysql"
app:
image: app
build:
context: .
dockerfile: Dockerfile.test
environment:
DB_HOST: db
depends_on:
- db

volumes:
db-data:
Loading

0 comments on commit e5c4e01

Please sign in to comment.