ar-uuid 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +4 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +70 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +39 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +90 -33
- data/Rakefile +7 -2
- data/ar-uuid.gemspec +17 -7
- data/bin/console +16 -0
- data/bin/setup +10 -0
- data/gemfiles/6_0.gemfile +5 -0
- data/gemfiles/6_1.gemfile +5 -0
- data/gemfiles/7_0.gemfile +5 -0
- data/lib/{active_record → ar}/uuid/ext.rb +9 -2
- data/lib/{active_record → ar}/uuid/schema.rb +5 -3
- data/lib/ar/uuid/table_definition.rb +25 -0
- data/lib/{active_record → ar}/uuid/utils.rb +11 -5
- data/lib/ar/uuid/version.rb +7 -0
- data/lib/ar/uuid.rb +13 -0
- data/lib/ar-uuid.rb +3 -1
- metadata +69 -32
- data/.travis.yml +0 -22
- data/gemfiles/4_2.gemfile +0 -3
- data/gemfiles/4_2.gemfile.lock +0 -81
- data/gemfiles/5_0.gemfile +0 -3
- data/gemfiles/5_0.gemfile.lock +0 -80
- data/gemfiles/5_1.gemfile +0 -3
- data/gemfiles/5_1.gemfile.lock +0 -80
- data/lib/active_record/uuid/table_definition.rb +0 -21
- data/lib/active_record/uuid/version.rb +0 -5
- data/lib/active_record/uuid.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 750147d7697999f1d3509ff6ecc6285b18d34e321794fc3ac57978c93887803a
|
4
|
+
data.tar.gz: 596c88e367384dd1a57d6ea57f9bfc0911da47beb26250ec60b16128655e97dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07df5b242c40693b4a324f9486c30419af3d87674e51f0353fb0d266f60b0e743780f539b3a4a0327f0861d7067609c52e0ed9d9c079c21676349907918969da
|
7
|
+
data.tar.gz: d2a5c5077dbaffc6e05ac725f37bf63f27d2e2ec59a045ca1b715cec025954acbc5b587745df973f75106e204b01065fa7de057ff9199b61b5d66f645b7d23ec
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
name: "🐛 Bug Report"
|
3
|
+
about: Report a reproducible bug or regression.
|
4
|
+
title: 'Bug: '
|
5
|
+
labels: 'Status: Unconfirmed'
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
<!--
|
10
|
+
- Please provide a clear and concise description of what the bug is.
|
11
|
+
- If possible, add an example reproducing your issue.
|
12
|
+
- Please test using the latest version of ar-uuid
|
13
|
+
to make sure your issue has not already been fixed.
|
14
|
+
-->
|
15
|
+
|
16
|
+
## Description
|
17
|
+
|
18
|
+
[Add bug description here]
|
19
|
+
|
20
|
+
## How to reproduce
|
21
|
+
|
22
|
+
[Add steps on how to reproduce this issue]
|
23
|
+
|
24
|
+
## What do you expect
|
25
|
+
|
26
|
+
[Describe what do you expect to happen]
|
27
|
+
|
28
|
+
## What happened instead
|
29
|
+
|
30
|
+
[Describe the actual results]
|
31
|
+
|
32
|
+
## Software:
|
33
|
+
|
34
|
+
- Gem version: [Add gem version here]
|
35
|
+
- Ruby version: [Add version here]
|
36
|
+
|
37
|
+
## Full backtrace
|
38
|
+
|
39
|
+
```text
|
40
|
+
[Paste full backtrace here]
|
41
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
name: "💡 Feature request"
|
3
|
+
about: Have an idea that may be useful? Make a suggestion!
|
4
|
+
title: 'Feature Request: '
|
5
|
+
labels: 'Feature request'
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
_A clear and concise description of what the problem is._
|
12
|
+
|
13
|
+
## Describe the solution
|
14
|
+
|
15
|
+
_A clear and concise description of what you want to happen._
|
16
|
+
|
17
|
+
## Alternatives you considered
|
18
|
+
|
19
|
+
_A clear and concise description of any alternative solutions or features you've considered._
|
20
|
+
|
21
|
+
## Additional context
|
22
|
+
|
23
|
+
_Add any other context, screenshots, links, etc about the feature request here._
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<!--
|
2
|
+
If you're making a doc PR or something tiny where the below is irrelevant,
|
3
|
+
delete this template and use a short description, but in your description aim to
|
4
|
+
include both what the change is, and why it is being made, with enough context
|
5
|
+
for anyone to understand.
|
6
|
+
-->
|
7
|
+
|
8
|
+
<details>
|
9
|
+
<summary>PR Checklist</summary>
|
10
|
+
|
11
|
+
### PR Structure
|
12
|
+
|
13
|
+
- [ ] This PR has reasonably narrow scope (if not, break it down into smaller
|
14
|
+
PRs).
|
15
|
+
- [ ] This PR avoids mixing refactoring changes with feature changes (split into
|
16
|
+
two PRs otherwise).
|
17
|
+
- [ ] This PR's title starts is concise and descriptive.
|
18
|
+
|
19
|
+
### Thoroughness
|
20
|
+
|
21
|
+
- [ ] This PR adds tests for the most critical parts of the new functionality or
|
22
|
+
fixes.
|
23
|
+
- [ ] I've updated any docs, `.md` files, etc… affected by this change.
|
24
|
+
|
25
|
+
</details>
|
26
|
+
|
27
|
+
### What
|
28
|
+
|
29
|
+
[TODO: Short statement about what is changing.]
|
30
|
+
|
31
|
+
### Why
|
32
|
+
|
33
|
+
[TODO: Why this change is being made. Include any context required to understand
|
34
|
+
the why.]
|
35
|
+
|
36
|
+
### Known limitations
|
37
|
+
|
38
|
+
[TODO or N/A]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
# Documentation:
|
3
|
+
# https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
|
4
|
+
|
5
|
+
version: 2
|
6
|
+
updates:
|
7
|
+
- package-ecosystem: "github-actions"
|
8
|
+
directory: "/"
|
9
|
+
schedule:
|
10
|
+
interval: "daily"
|
11
|
+
|
12
|
+
- package-ecosystem: "bundler"
|
13
|
+
directory: "/"
|
14
|
+
schedule:
|
15
|
+
interval: "daily"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
name: ruby-tests
|
3
|
+
|
4
|
+
on:
|
5
|
+
pull_request_target:
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
workflow_dispatch:
|
10
|
+
inputs: {}
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
|
15
|
+
runs-on: "ubuntu-latest"
|
16
|
+
if: |
|
17
|
+
github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
|
18
|
+
github.actor != 'dependabot[bot]'
|
19
|
+
strategy:
|
20
|
+
fail-fast: false
|
21
|
+
matrix:
|
22
|
+
ruby: ["2.7", "3.0", "3.1"]
|
23
|
+
gemfile:
|
24
|
+
- Gemfile
|
25
|
+
- gemfiles/7_0.gemfile
|
26
|
+
- gemfiles/6_1.gemfile
|
27
|
+
- gemfiles/6_0.gemfile
|
28
|
+
services:
|
29
|
+
postgres:
|
30
|
+
image: postgres:11.5
|
31
|
+
ports: ["5432:5432"]
|
32
|
+
options:
|
33
|
+
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
|
34
|
+
--health-retries 5
|
35
|
+
|
36
|
+
steps:
|
37
|
+
- uses: actions/checkout@v3.0.2
|
38
|
+
|
39
|
+
- uses: actions/cache@v3.0.5
|
40
|
+
with:
|
41
|
+
path: vendor/bundle
|
42
|
+
key: >
|
43
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-${{
|
44
|
+
hashFiles(matrix.gemfile) }}
|
45
|
+
|
46
|
+
- name: Install PostgreSQL 11 client
|
47
|
+
run: |
|
48
|
+
sudo apt -y install libpq-dev
|
49
|
+
|
50
|
+
- name: Set up Ruby
|
51
|
+
uses: ruby/setup-ruby@v1
|
52
|
+
with:
|
53
|
+
ruby-version: ${{ matrix.ruby }}
|
54
|
+
|
55
|
+
- name: Install gem dependencies
|
56
|
+
env:
|
57
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
58
|
+
run: |
|
59
|
+
gem install bundler
|
60
|
+
bundle config path vendor/bundle
|
61
|
+
bundle update --jobs 4 --retry 3
|
62
|
+
|
63
|
+
- name: Run Tests
|
64
|
+
env:
|
65
|
+
PGHOST: localhost
|
66
|
+
PGUSER: postgres
|
67
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
68
|
+
run: |
|
69
|
+
psql -U postgres -c "create database test"
|
70
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
<!--
|
4
|
+
Prefix your message with one of the following:
|
5
|
+
|
6
|
+
- [Added] for new features.
|
7
|
+
- [Changed] for changes in existing functionality.
|
8
|
+
- [Deprecated] for soon-to-be removed features.
|
9
|
+
- [Removed] for now removed features.
|
10
|
+
- [Fixed] for any bug fixes.
|
11
|
+
- [Security] in case of vulnerabilities.
|
12
|
+
-->
|
13
|
+
|
14
|
+
## Unreleased
|
15
|
+
|
16
|
+
- [Changed] Change namespace from `ActiveRecord::UUID` to `AR::UUID`.
|
17
|
+
- [Removed] Dropped support for Rails 4.2.
|
18
|
+
|
19
|
+
## v0.2.1 - 2019-11-26
|
20
|
+
|
21
|
+
- No significant changes.
|
22
|
+
|
23
|
+
## v0.2.0 - 2017-06-23
|
24
|
+
|
25
|
+
- [Fixed] Use the first available extension for UUID generation (`pgcrypto` or
|
26
|
+
`uuid-ossp`).
|
27
|
+
- [Fixed] Handle `belongs_to_required_by_default`.
|
28
|
+
|
29
|
+
## v0.1.2 - 2015-05-23
|
30
|
+
|
31
|
+
- [Fixed] Make sure we always override schema statements's create_table method.
|
32
|
+
|
33
|
+
## v0.1.1 - 2015-04-27
|
34
|
+
|
35
|
+
- Initial release.
|
36
|
+
|
37
|
+
## v0.1.0 - 2015-04-27
|
38
|
+
|
39
|
+
- Yanked release.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at me@fnando.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Contributing to ar-uuid
|
2
|
+
|
3
|
+
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
|
4
|
+
|
5
|
+
The following is a set of guidelines for contributing to this project. These are
|
6
|
+
mostly guidelines, not rules. Use your best judgment, and feel free to propose
|
7
|
+
changes to this document in a pull request.
|
8
|
+
|
9
|
+
## Code of Conduct
|
10
|
+
|
11
|
+
Everyone interacting in this project's codebases, issue trackers, chat rooms and
|
12
|
+
mailing lists is expected to follow the [code of conduct](https://github.com/fnando/ar-uuid/blob/main/CODE_OF_CONDUCT.md).
|
13
|
+
|
14
|
+
## Reporting bugs
|
15
|
+
|
16
|
+
This section guides you through submitting a bug report. Following these
|
17
|
+
guidelines helps maintainers and the community understand your report, reproduce
|
18
|
+
the behavior, and find related reports.
|
19
|
+
|
20
|
+
- Before creating bug reports, please check the open issues; somebody may
|
21
|
+
already have submitted something similar, and you may not need to create a new
|
22
|
+
one.
|
23
|
+
- When you are creating a bug report, please include as many details as
|
24
|
+
possible, with an example reproducing the issue.
|
25
|
+
|
26
|
+
## Contributing with code
|
27
|
+
|
28
|
+
Before making any radicals changes, please make sure you discuss your intention
|
29
|
+
by [opening an issue on Github](https://github.com/fnando/ar-uuid/issues).
|
30
|
+
|
31
|
+
When you're ready to make your pull request, follow checklist below to make sure
|
32
|
+
your contribution is according to how this project works.
|
33
|
+
|
34
|
+
1. [Fork](https://help.github.com/forking/) ar-uuid
|
35
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
36
|
+
3. Make your changes using [descriptive commit messages](#commit-messages)
|
37
|
+
4. Update CHANGELOG.md describing your changes by adding an entry to the
|
38
|
+
"Unreleased" section. If this section is not available, create one right
|
39
|
+
before the last version.
|
40
|
+
5. Push to your branch - `git push origin my_branch`
|
41
|
+
6. [Create a pull request](https://docs.github.com/articles/creating-a-pull-request)
|
42
|
+
7. That's it!
|
43
|
+
|
44
|
+
## Styleguides
|
45
|
+
|
46
|
+
### Commit messages
|
47
|
+
|
48
|
+
- Use the present tense ("Add feature" not "Added feature")
|
49
|
+
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
|
50
|
+
- Limit the first line to 72 characters or less
|
51
|
+
- Reference issues and pull requests liberally after the first line
|
52
|
+
|
53
|
+
### Changelog
|
54
|
+
|
55
|
+
- Add a message describing your changes to the "Unreleased" section. The
|
56
|
+
changelog message should follow the same style as the commit message.
|
57
|
+
- Prefix your message with one of the following:
|
58
|
+
- `[Added]` for new features.
|
59
|
+
- `[Changed]` for changes in existing functionality.
|
60
|
+
- `[Deprecated]` for soon-to-be removed features.
|
61
|
+
- `[Removed]` for now removed features.
|
62
|
+
- `[Fixed]` for any bug fixes.
|
63
|
+
- `[Security]` in case of vulnerabilities.
|
64
|
+
|
65
|
+
### Ruby code
|
66
|
+
|
67
|
+
- This project uses [Rubocop](https://rubocop.org) to enforce code style. Before
|
68
|
+
submitting your changes, make sure your tests are passing and code conforms to
|
69
|
+
the expected style by running `rake`.
|
70
|
+
- Do not change the library version. This will be done by the maintainer
|
71
|
+
whenever a new version is about to be released.
|
72
|
+
|
73
|
+
### JavaScript code
|
74
|
+
|
75
|
+
- This project uses [ESLint](https://eslint.org) to enforce code style. Before
|
76
|
+
submitting your changes, make sure your tests are passing and code conforms to
|
77
|
+
the expected style by running `yarn test:ci`.
|
78
|
+
- Do not change the library version. This will be done by the maintainer
|
79
|
+
whenever a new version is about to be released.
|
data/Gemfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Nando Vieira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,37 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# ar-uuid
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![Code Climate](https://codeclimate.com/github/fnando/ar-uuid/badges/gpa.svg)](https://codeclimate.com/github/fnando/ar-uuid)
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/fnando/ar-uuid/badges/coverage.svg)](https://codeclimate.com/github/fnando/ar-uuid/coverage)
|
3
|
+
[![Tests](https://github.com/fnando/ar-uuid/workflows/ruby-tests/badge.svg)](https://github.com/fnando/ar-uuid)
|
6
4
|
[![Gem](https://img.shields.io/gem/v/ar-uuid.svg)](https://rubygems.org/gems/ar-uuid)
|
7
5
|
[![Gem](https://img.shields.io/gem/dt/ar-uuid.svg)](https://rubygems.org/gems/ar-uuid)
|
8
6
|
|
9
|
-
Override migration methods to support UUID columns without having to be explicit
|
10
|
-
|
11
|
-
What this gem will do for you:
|
12
|
-
|
13
|
-
- When creating new tables, will set the `id` column as `uuid`.
|
14
|
-
- When creating associations with `t.belongs_to`, `t.references` or `add_reference`, will set the column type as `uuid`.
|
7
|
+
Override migration methods to support UUID columns without having to be explicit
|
8
|
+
about it.
|
15
9
|
|
16
10
|
## Installation
|
17
11
|
|
18
|
-
|
12
|
+
```bash
|
13
|
+
gem install ar-uuid
|
14
|
+
```
|
15
|
+
|
16
|
+
Or add the following line to your project's Gemfile:
|
19
17
|
|
20
18
|
```ruby
|
21
19
|
gem "ar-uuid"
|
22
20
|
```
|
23
21
|
|
24
|
-
And then execute:
|
25
|
-
|
26
|
-
$ bundle
|
27
|
-
|
28
|
-
Or install it yourself as:
|
29
|
-
|
30
|
-
$ gem install ar-uuid
|
31
|
-
|
32
22
|
## Usage
|
33
23
|
|
34
|
-
There's no setup. Just adding the gem to your Gemfile is enough. When you create
|
24
|
+
There's no setup. Just adding the gem to your Gemfile is enough. When you create
|
25
|
+
a new table, the `id` column will be defined as `uuid`. This is also true for
|
26
|
+
references.
|
35
27
|
|
36
28
|
```ruby
|
37
29
|
create_table :users
|
@@ -44,7 +36,8 @@ create_table :posts do |t|
|
|
44
36
|
end
|
45
37
|
```
|
46
38
|
|
47
|
-
If you need a serial column, AR's PostgreSQL supports the `bigserial` column
|
39
|
+
If you need a serial column, AR's PostgreSQL supports the `bigserial` column
|
40
|
+
type.
|
48
41
|
|
49
42
|
```ruby
|
50
43
|
create_table :users do |t|
|
@@ -52,24 +45,88 @@ create_table :users do |t|
|
|
52
45
|
end
|
53
46
|
```
|
54
47
|
|
55
|
-
###
|
48
|
+
### Sorting
|
49
|
+
|
50
|
+
#### Rails 6.0 or newer
|
56
51
|
|
57
|
-
|
52
|
+
If you're using Rails 6.0 or newer, you can set a default sorting with
|
53
|
+
[ActiveRecord::ModelSchema.implicit_order_column](https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema.html#method-c-implicit_order_column),
|
54
|
+
so methods like `ActiveRecord::FinderMethods::InstanceMethods#first` and
|
55
|
+
`ActiveRecord::FinderMethods::InstanceMethods#last` will work transparently, as
|
56
|
+
long as you define another column for sorting, such as `created_at` (you may
|
57
|
+
need to add an index).
|
58
|
+
|
59
|
+
The following example sets a default behavior to always sort using `created_at`
|
60
|
+
(when available). On your abstract model, add the following lines:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class ApplicationRecord < ActiveRecord::Base
|
64
|
+
self.abstract_class = true
|
65
|
+
|
66
|
+
def self.inherited(child_class)
|
67
|
+
super
|
68
|
+
|
69
|
+
return unless child_class.columns.any? {|col| col.name == "created_at" }
|
70
|
+
|
71
|
+
child_class.implicit_order_column ||= "created_at"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
58
75
|
|
59
|
-
|
76
|
+
#### Older Rails versions
|
77
|
+
|
78
|
+
For older Rails versions, you can't use methods like
|
79
|
+
`ActiveRecord::FinderMethods::InstanceMethods#first` and
|
80
|
+
`ActiveRecord::FinderMethods::InstanceMethods#last`, since they are scoped to
|
81
|
+
the sequential id.
|
82
|
+
|
83
|
+
The easiest alternative is ordering results and calling `first`/`last`. You can
|
84
|
+
either create a sequence, or use the `created_at`/`updated_at` columns:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
# Get first record
|
88
|
+
User.order(created_at: :asc).first
|
89
|
+
|
90
|
+
# Get last record
|
91
|
+
User.order(created_at: :desc).first
|
92
|
+
|
93
|
+
# Use scopes
|
94
|
+
class User < ApplicationRecord
|
95
|
+
scope :newer, -> { order(created_at: :desc) }
|
96
|
+
scope :older, -> { order(created_at: :asc) }
|
97
|
+
end
|
98
|
+
|
99
|
+
User.older.first
|
100
|
+
User.newer.first
|
101
|
+
```
|
102
|
+
|
103
|
+
You can also replace `.first` with
|
104
|
+
[ActiveRecord::FinderMethods::InstanceMethods#take](https://github.com/rails/rails/blob/f52354ad1d15120dcc5284714bee7ee3f052986c/activerecord/lib/active_record/relation/finder_methods.rb#L104),
|
105
|
+
which will use the order implemented by the database.
|
60
106
|
|
61
107
|
There's no alternative to `.last`.
|
62
108
|
|
63
|
-
##
|
109
|
+
## Maintainer
|
110
|
+
|
111
|
+
- [Nando Vieira](https://github.com/fnando)
|
112
|
+
|
113
|
+
## Contributors
|
64
114
|
|
65
|
-
|
66
|
-
4
|
67
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
115
|
+
- https://github.com/fnando/ar-uuid/contributors
|
68
116
|
|
69
117
|
## Contributing
|
70
118
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
119
|
+
For more details about how to contribute, please read
|
120
|
+
https://github.com/fnando/ar-uuid/blob/main/CONTRIBUTING.md.
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
The gem is available as open source under the terms of the
|
125
|
+
[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
|
126
|
+
found at https://github.com/fnando/ar-uuid/blob/main/LICENSE.md.
|
127
|
+
|
128
|
+
## Code of Conduct
|
129
|
+
|
130
|
+
Everyone interacting in the ar-uuid project's codebases, issue trackers, chat
|
131
|
+
rooms and mailing lists is expected to follow the
|
132
|
+
[code of conduct](https://github.com/fnando/ar-uuid/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rake/testtask"
|
5
|
+
require "rubocop/rake_task"
|
3
6
|
|
4
7
|
Rake::TestTask.new(:test) do |t|
|
5
8
|
t.libs << "test"
|
9
|
+
t.libs << "lib"
|
6
10
|
t.test_files = FileList["test/**/*_test.rb"]
|
7
|
-
t.warning = false
|
8
11
|
end
|
9
12
|
|
10
|
-
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
task default: %i[test rubocop]
|
data/ar-uuid.gemspec
CHANGED
@@ -1,26 +1,36 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "./lib/ar/uuid/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
6
|
spec.name = "ar-uuid"
|
5
|
-
spec.version =
|
7
|
+
spec.version = AR::UUID::VERSION
|
6
8
|
spec.authors = ["Nando Vieira"]
|
7
9
|
spec.email = ["fnando.vieira@gmail.com"]
|
8
|
-
spec.summary =
|
10
|
+
spec.summary = "Override migration methods to support UUID columns " \
|
11
|
+
"without having to be explicit about it."
|
9
12
|
spec.description = spec.summary
|
10
13
|
spec.homepage = "http://rubygems.org/gems/ar-uuid"
|
11
14
|
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
16
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
12
17
|
|
13
|
-
spec.files = `git ls-files -z
|
18
|
+
spec.files = `git ls-files -z`
|
19
|
+
.split("\x0")
|
20
|
+
.reject {|f| f.match(%r{^(test|spec|features)/}) }
|
14
21
|
spec.bindir = "exe"
|
15
|
-
spec.executables = spec.files.grep(%r{^exe/}) {
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
16
23
|
spec.require_paths = ["lib"]
|
17
24
|
|
18
25
|
spec.add_dependency "activerecord"
|
26
|
+
|
19
27
|
spec.add_development_dependency "bundler"
|
20
|
-
spec.add_development_dependency "rake"
|
21
28
|
spec.add_development_dependency "minitest-utils"
|
22
29
|
spec.add_development_dependency "mocha"
|
23
30
|
spec.add_development_dependency "pg"
|
24
31
|
spec.add_development_dependency "pry-meta"
|
25
|
-
spec.add_development_dependency "
|
32
|
+
spec.add_development_dependency "rake"
|
33
|
+
spec.add_development_dependency "rubocop"
|
34
|
+
spec.add_development_dependency "rubocop-fnando"
|
35
|
+
spec.add_development_dependency "simplecov"
|
26
36
|
end
|