ar-uuid 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/tests.yml +75 -0
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +39 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +1 -0
- data/LICENSE.md +20 -0
- data/README.md +72 -33
- data/Rakefile +5 -2
- data/ar-uuid.gemspec +10 -4
- data/bin/console +16 -0
- data/bin/setup +10 -0
- data/lib/ar-uuid.rb +1 -1
- data/lib/ar/uuid.rb +13 -0
- data/lib/{active_record → ar}/uuid/ext.rb +7 -2
- data/lib/{active_record → ar}/uuid/schema.rb +3 -3
- data/lib/{active_record → ar}/uuid/table_definition.rb +8 -5
- data/lib/{active_record → ar}/uuid/utils.rb +6 -3
- data/lib/{active_record → ar}/uuid/version.rb +2 -2
- metadata +57 -19
- data/.travis.yml +0 -29
- data/gemfiles/4_2.gemfile +0 -6
- data/lib/active_record/uuid.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89711805f2e4a8f202186b701a490127ed55dc23df8aaee62f0fcaad8648c840
|
4
|
+
data.tar.gz: 4443bec600bf3366de382b5724a202a0107b173d3b2f48f238084695f516fa53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fd89d52a5e7c5d306f9cd532b9a2201195f9e4ce171386cf87d2ac8dacdc647203e032dd07fabce340460438971250597e9dde630ae87f917b02bc111dd78f8
|
7
|
+
data.tar.gz: e8b4248c57c4b6cf1711119961f2fce98aff1e7410d6767f6dd9513cd06c5c0a2ea0097fd149b3893737e5ac3972ae7416c000dfe88bf148ecfc44c2d4b61247
|
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,75 @@
|
|
1
|
+
---
|
2
|
+
name: Tests
|
3
|
+
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
branches:
|
7
|
+
- main
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- main
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
|
15
|
+
runs-on: "ubuntu-latest"
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [2.6.x, 2.7.x, 3.0.x]
|
20
|
+
gemfile:
|
21
|
+
- Gemfile
|
22
|
+
- gemfiles/6_0.gemfile
|
23
|
+
- gemfiles/5_2.gemfile
|
24
|
+
- gemfiles/5_1.gemfile
|
25
|
+
- gemfiles/5_0.gemfile
|
26
|
+
|
27
|
+
services:
|
28
|
+
postgres:
|
29
|
+
image: postgres:11.5
|
30
|
+
ports: ["5432:5432"]
|
31
|
+
options:
|
32
|
+
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
|
33
|
+
--health-retries 5
|
34
|
+
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v2.3.4
|
37
|
+
|
38
|
+
- uses: actions/cache@v2
|
39
|
+
with:
|
40
|
+
path: vendor/bundle
|
41
|
+
key: >
|
42
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-${{
|
43
|
+
hashFiles(matrix.gemfile) }}
|
44
|
+
restore-keys: >
|
45
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-${{
|
46
|
+
hashFiles(matrix.gemfile) }}
|
47
|
+
|
48
|
+
- name: Set up Ruby
|
49
|
+
uses: actions/setup-ruby@v1
|
50
|
+
with:
|
51
|
+
ruby-version: ${{ matrix.ruby }}
|
52
|
+
|
53
|
+
- name: Install PostgreSQL client
|
54
|
+
env:
|
55
|
+
PGHOST: localhost
|
56
|
+
PGUSER: postgres
|
57
|
+
run: |
|
58
|
+
sudo apt-get -yqq install libpq-dev
|
59
|
+
psql -U postgres -c "create database test"
|
60
|
+
|
61
|
+
- name: Install gem dependencies
|
62
|
+
env:
|
63
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
64
|
+
run: |
|
65
|
+
gem install bundler
|
66
|
+
bundle config path vendor/bundle
|
67
|
+
bundle update --jobs 4 --retry 3
|
68
|
+
|
69
|
+
- name: Run Tests
|
70
|
+
env:
|
71
|
+
PGHOST: localhost
|
72
|
+
PGUSER: postgres
|
73
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
74
|
+
run: |
|
75
|
+
bundle exec rake
|
data/.rubocop.yml
CHANGED
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,30 @@
|
|
1
|
-
#
|
1
|
+
# ar-uuid
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Tests](https://github.com/fnando/ar-uuid/workflows/Tests/badge.svg)](https://github.com/fnando/ar-uuid)
|
4
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)
|
6
5
|
[![Gem](https://img.shields.io/gem/v/ar-uuid.svg)](https://rubygems.org/gems/ar-uuid)
|
7
6
|
[![Gem](https://img.shields.io/gem/dt/ar-uuid.svg)](https://rubygems.org/gems/ar-uuid)
|
8
7
|
|
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`.
|
8
|
+
Override migration methods to support UUID columns without having to be explicit
|
9
|
+
about it.
|
15
10
|
|
16
11
|
## Installation
|
17
12
|
|
18
|
-
|
13
|
+
```bash
|
14
|
+
gem install ar-uuid
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add the following line to your project's Gemfile:
|
19
18
|
|
20
19
|
```ruby
|
21
20
|
gem "ar-uuid"
|
22
21
|
```
|
23
22
|
|
24
|
-
And then execute:
|
25
|
-
|
26
|
-
$ bundle
|
27
|
-
|
28
|
-
Or install it yourself as:
|
29
|
-
|
30
|
-
$ gem install ar-uuid
|
31
|
-
|
32
23
|
## Usage
|
33
24
|
|
34
|
-
There's no setup. Just adding the gem to your Gemfile is enough. When you create
|
25
|
+
There's no setup. Just adding the gem to your Gemfile is enough. When you create
|
26
|
+
a new table, the `id` column will be defined as `uuid`. This is also true for
|
27
|
+
references.
|
35
28
|
|
36
29
|
```ruby
|
37
30
|
create_table :users
|
@@ -44,7 +37,8 @@ create_table :posts do |t|
|
|
44
37
|
end
|
45
38
|
```
|
46
39
|
|
47
|
-
If you need a serial column, AR's PostgreSQL supports the `bigserial` column
|
40
|
+
If you need a serial column, AR's PostgreSQL supports the `bigserial` column
|
41
|
+
type.
|
48
42
|
|
49
43
|
```ruby
|
50
44
|
create_table :users do |t|
|
@@ -52,11 +46,43 @@ create_table :users do |t|
|
|
52
46
|
end
|
53
47
|
```
|
54
48
|
|
55
|
-
###
|
49
|
+
### Sorting
|
50
|
+
|
51
|
+
#### Rails 6.0 or newer
|
56
52
|
|
57
|
-
|
53
|
+
If you're using Rails 6.0 or newer, you can set a default sorting with
|
54
|
+
[ActiveRecord::ModelSchema.implicit_order_column](https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema.html#method-c-implicit_order_column),
|
55
|
+
so methods like `ActiveRecord::FinderMethods::InstanceMethods#first` and
|
56
|
+
`ActiveRecord::FinderMethods::InstanceMethods#last` will work transparently, as
|
57
|
+
long as you define another column for sorting, such as `created_at` (you may
|
58
|
+
need to add an index).
|
58
59
|
|
59
|
-
The
|
60
|
+
The following example sets a default behavior to always sort using `created_at`
|
61
|
+
(when available). On your abstract model, add the following lines:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class ApplicationRecord < ActiveRecord::Base
|
65
|
+
self.abstract_class = true
|
66
|
+
|
67
|
+
def self.inherited(child_class)
|
68
|
+
super
|
69
|
+
|
70
|
+
return unless child_class.columns.any? {|col| col.name == "created_at" }
|
71
|
+
|
72
|
+
child_class.implicit_order_column ||= "created_at"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
#### Older Rails versions
|
78
|
+
|
79
|
+
For older Rails versions, you can't use methods like
|
80
|
+
`ActiveRecord::FinderMethods::InstanceMethods#first` and
|
81
|
+
`ActiveRecord::FinderMethods::InstanceMethods#last`, since they are scoped to
|
82
|
+
the sequential id.
|
83
|
+
|
84
|
+
The easiest alternative is ordering results and calling `first`/`last`. You can
|
85
|
+
either create a sequence, or use the `created_at`/`updated_at` columns:
|
60
86
|
|
61
87
|
```ruby
|
62
88
|
# Get first record
|
@@ -75,20 +101,33 @@ User.older.first
|
|
75
101
|
User.newer.first
|
76
102
|
```
|
77
103
|
|
78
|
-
You can also replace `.first` with
|
104
|
+
You can also replace `.first` with
|
105
|
+
[ActiveRecord::FinderMethods::InstanceMethods#take](https://github.com/rails/rails/blob/f52354ad1d15120dcc5284714bee7ee3f052986c/activerecord/lib/active_record/relation/finder_methods.rb#L104),
|
106
|
+
which will use the order implemented by the database.
|
79
107
|
|
80
108
|
There's no alternative to `.last`.
|
81
109
|
|
82
|
-
##
|
110
|
+
## Maintainer
|
83
111
|
|
84
|
-
|
85
|
-
|
86
|
-
|
112
|
+
- [Nando Vieira](https://github.com/fnando)
|
113
|
+
|
114
|
+
## Contributors
|
115
|
+
|
116
|
+
- https://github.com/fnando/ar-uuid/contributors
|
87
117
|
|
88
118
|
## Contributing
|
89
119
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
120
|
+
For more details about how to contribute, please read
|
121
|
+
https://github.com/fnando/ar-uuid/blob/main/CONTRIBUTING.md.
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the
|
126
|
+
[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
|
127
|
+
found at https://github.com/fnando/ar-uuid/blob/main/LICENSE.md.
|
128
|
+
|
129
|
+
## Code of Conduct
|
130
|
+
|
131
|
+
Everyone interacting in the ar-uuid project's codebases, issue trackers, chat
|
132
|
+
rooms and mailing lists is expected to follow the
|
133
|
+
[code of conduct](https://github.com/fnando/ar-uuid/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rake/testtask"
|
5
|
+
require "rubocop/rake_task"
|
5
6
|
|
6
7
|
Rake::TestTask.new(:test) do |t|
|
7
8
|
t.libs << "test"
|
9
|
+
t.libs << "lib"
|
8
10
|
t.test_files = FileList["test/**/*_test.rb"]
|
9
|
-
t.warning = false
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
task default: %i[test rubocop]
|
data/ar-uuid.gemspec
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "./lib/
|
3
|
+
require "./lib/ar/uuid/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ar-uuid"
|
7
|
-
spec.version =
|
7
|
+
spec.version = AR::UUID::VERSION
|
8
8
|
spec.authors = ["Nando Vieira"]
|
9
9
|
spec.email = ["fnando.vieira@gmail.com"]
|
10
|
-
spec.summary =
|
10
|
+
spec.summary = "Override migration methods to support UUID columns " \
|
11
|
+
"without having to be explicit about it."
|
11
12
|
spec.description = spec.summary
|
12
13
|
spec.homepage = "http://rubygems.org/gems/ar-uuid"
|
13
14
|
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
14
16
|
|
15
|
-
spec.files = `git ls-files -z
|
17
|
+
spec.files = `git ls-files -z`
|
18
|
+
.split("\x0")
|
19
|
+
.reject {|f| f.match(%r{^(test|spec|features)/}) }
|
16
20
|
spec.bindir = "exe"
|
17
21
|
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
18
22
|
spec.require_paths = ["lib"]
|
@@ -25,5 +29,7 @@ Gem::Specification.new do |spec|
|
|
25
29
|
spec.add_development_dependency "pg"
|
26
30
|
spec.add_development_dependency "pry-meta"
|
27
31
|
spec.add_development_dependency "rake"
|
32
|
+
spec.add_development_dependency "rubocop"
|
33
|
+
spec.add_development_dependency "rubocop-fnando"
|
28
34
|
spec.add_development_dependency "simplecov"
|
29
35
|
end
|
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "ar-uuid"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
begin
|
11
|
+
require "pry"
|
12
|
+
Pry.start
|
13
|
+
rescue LoadError
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
16
|
+
end
|
data/bin/setup
ADDED
data/lib/ar-uuid.rb
CHANGED
data/lib/ar/uuid.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AR
|
4
|
+
module UUID
|
5
|
+
require "active_record"
|
6
|
+
require "active_record/base"
|
7
|
+
require "ar/uuid/version"
|
8
|
+
require "ar/uuid/schema"
|
9
|
+
require "ar/uuid/table_definition"
|
10
|
+
require "ar/uuid/ext"
|
11
|
+
require "ar/uuid/utils"
|
12
|
+
end
|
13
|
+
end
|
@@ -3,6 +3,11 @@
|
|
3
3
|
ActiveSupport.on_load(:active_record) do
|
4
4
|
require "active_record/connection_adapters/postgresql_adapter"
|
5
5
|
|
6
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include
|
7
|
-
|
6
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(
|
7
|
+
AR::UUID::Schema
|
8
|
+
)
|
9
|
+
|
10
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.include(
|
11
|
+
AR::UUID::TableDefinition
|
12
|
+
)
|
8
13
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module AR
|
4
4
|
module UUID
|
5
5
|
module Schema
|
6
6
|
def create_table(table_name, options = {}, &block)
|
7
7
|
options[:id] = :uuid unless options.key?(:id)
|
8
|
-
super(table_name, options, &block)
|
8
|
+
super(table_name, **options, &block)
|
9
9
|
end
|
10
10
|
|
11
11
|
def add_reference(table_name, ref_name, options = {})
|
12
12
|
options[:type] = :uuid unless options.key?(:type)
|
13
|
-
super(table_name, ref_name, options)
|
13
|
+
super(table_name, ref_name, **options)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,20 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module AR
|
4
4
|
module UUID
|
5
5
|
module TableDefinition
|
6
6
|
def references(*args)
|
7
7
|
options = args.extract_options!
|
8
8
|
options[:type] = :uuid unless options.include?(:type)
|
9
|
-
options[:null] = !::ActiveRecord::UUID::Utils.belongs_to_required_by_default unless options.include?(:null)
|
10
|
-
args << options
|
11
9
|
|
12
|
-
|
10
|
+
unless options.include?(:null)
|
11
|
+
options[:null] =
|
12
|
+
!::AR::UUID::Utils.belongs_to_required_by_default
|
13
|
+
end
|
14
|
+
|
15
|
+
super(*args, **options)
|
13
16
|
end
|
14
17
|
alias belongs_to references
|
15
18
|
|
16
19
|
def primary_key(name, type = :primary_key, **options)
|
17
|
-
options[:default] = ::
|
20
|
+
options[:default] = ::AR::UUID::Utils.uuid_default_function
|
18
21
|
super(name, type, **options)
|
19
22
|
end
|
20
23
|
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module AR
|
4
4
|
module UUID
|
5
5
|
MissingExtensionError = Class.new(StandardError) do
|
6
6
|
def initialize
|
7
|
-
super(
|
7
|
+
super(
|
8
|
+
'Use either `enable_extension "uuid-ossp"` or' \
|
9
|
+
'`enable_extension "pgcrypto"`'
|
10
|
+
)
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
11
14
|
module Utils
|
12
|
-
EXTENSIONS_SQL =
|
15
|
+
EXTENSIONS_SQL = <<~SQL
|
13
16
|
select
|
14
17
|
extname
|
15
18
|
from pg_extension
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-fnando
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: simplecov
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,39 +150,49 @@ dependencies:
|
|
122
150
|
- - ">="
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0'
|
125
|
-
description:
|
126
|
-
|
153
|
+
description: Override migration methods to support UUID columns without having to
|
154
|
+
be explicit about it.
|
127
155
|
email:
|
128
156
|
- fnando.vieira@gmail.com
|
129
157
|
executables: []
|
130
158
|
extensions: []
|
131
159
|
extra_rdoc_files: []
|
132
160
|
files:
|
161
|
+
- ".github/FUNDING.yml"
|
162
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
163
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
164
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
165
|
+
- ".github/dependabot.yml"
|
166
|
+
- ".github/workflows/tests.yml"
|
133
167
|
- ".gitignore"
|
134
168
|
- ".rubocop.yml"
|
135
|
-
-
|
169
|
+
- CHANGELOG.md
|
170
|
+
- CODE_OF_CONDUCT.md
|
171
|
+
- CONTRIBUTING.md
|
136
172
|
- Gemfile
|
173
|
+
- LICENSE.md
|
137
174
|
- LICENSE.txt
|
138
175
|
- README.md
|
139
176
|
- Rakefile
|
140
177
|
- ar-uuid.gemspec
|
141
|
-
-
|
178
|
+
- bin/console
|
179
|
+
- bin/setup
|
142
180
|
- gemfiles/5_0.gemfile
|
143
181
|
- gemfiles/5_1.gemfile
|
144
182
|
- gemfiles/5_2.gemfile
|
145
183
|
- gemfiles/6_0.gemfile
|
146
|
-
- lib/active_record/uuid.rb
|
147
|
-
- lib/active_record/uuid/ext.rb
|
148
|
-
- lib/active_record/uuid/schema.rb
|
149
|
-
- lib/active_record/uuid/table_definition.rb
|
150
|
-
- lib/active_record/uuid/utils.rb
|
151
|
-
- lib/active_record/uuid/version.rb
|
152
184
|
- lib/ar-uuid.rb
|
185
|
+
- lib/ar/uuid.rb
|
186
|
+
- lib/ar/uuid/ext.rb
|
187
|
+
- lib/ar/uuid/schema.rb
|
188
|
+
- lib/ar/uuid/table_definition.rb
|
189
|
+
- lib/ar/uuid/utils.rb
|
190
|
+
- lib/ar/uuid/version.rb
|
153
191
|
homepage: http://rubygems.org/gems/ar-uuid
|
154
192
|
licenses:
|
155
193
|
- MIT
|
156
194
|
metadata: {}
|
157
|
-
post_install_message:
|
195
|
+
post_install_message:
|
158
196
|
rdoc_options: []
|
159
197
|
require_paths:
|
160
198
|
- lib
|
@@ -162,16 +200,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
200
|
requirements:
|
163
201
|
- - ">="
|
164
202
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
203
|
+
version: 2.6.0
|
166
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
205
|
requirements:
|
168
206
|
- - ">="
|
169
207
|
- !ruby/object:Gem::Version
|
170
208
|
version: '0'
|
171
209
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
173
|
-
signing_key:
|
210
|
+
rubygems_version: 3.2.22
|
211
|
+
signing_key:
|
174
212
|
specification_version: 4
|
175
|
-
summary:
|
176
|
-
|
213
|
+
summary: Override migration methods to support UUID columns without having to be explicit
|
214
|
+
about it.
|
177
215
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
before_install:
|
6
|
-
- gem install bundler
|
7
|
-
before_script:
|
8
|
-
- createdb test
|
9
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
|
-
- chmod +x ./cc-test-reporter
|
11
|
-
- "./cc-test-reporter before-build"
|
12
|
-
addons:
|
13
|
-
postgresql: '9.4'
|
14
|
-
rvm:
|
15
|
-
- 2.6.5
|
16
|
-
- 2.5.7
|
17
|
-
gemfile:
|
18
|
-
- gemfiles/6_0.gemfile
|
19
|
-
- gemfiles/5_2.gemfile
|
20
|
-
- gemfiles/5_1.gemfile
|
21
|
-
- gemfiles/5_0.gemfile
|
22
|
-
- gemfiles/4_2.gemfile
|
23
|
-
notifications:
|
24
|
-
email: false
|
25
|
-
after_script:
|
26
|
-
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
27
|
-
env:
|
28
|
-
global:
|
29
|
-
secure: e3q9FNNyflF3TXteIJ/GAMHiMBpDgwNX5CbnogE+n60GulXI1TgoWHyXQwlSKQWHHm5yKTQ+Gn4oPQndocG4dfD0EEb56XMCvwgyuUFRkVQDqaycEBvSN/QDAV1SOTH0aZLv0G+BC6PtDvEmjbC3FLtJzp2t1SXaZvDUBUEp7dU=
|
data/gemfiles/4_2.gemfile
DELETED
data/lib/active_record/uuid.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module UUID
|
5
|
-
require "active_record"
|
6
|
-
require "active_record/base"
|
7
|
-
require "active_record/uuid/version"
|
8
|
-
require "active_record/uuid/schema"
|
9
|
-
require "active_record/uuid/table_definition"
|
10
|
-
require "active_record/uuid/ext"
|
11
|
-
require "active_record/uuid/utils"
|
12
|
-
end
|
13
|
-
end
|