Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Add IP and MAC address types #12884

Merged
merged 1 commit into from
Mar 28, 2016
Merged

[5.2] Add IP and MAC address types #12884

merged 1 commit into from
Mar 28, 2016

Conversation

aejnsn
Copy link
Contributor

@aejnsn aejnsn commented Mar 27, 2016

Same as previous PR intended at 5.3. At request of @GrahamCampbell pushing to 5.2.

PostgreSQL has some very useful data types and functions to handle network data, namely inet and macaddr. I had been working on a package to extend Laravel's support of PostgreSQL types. I would like to see more of these types added to Laravel. I have had several occasions where I have really wanted more of PostgreSQL's data types (in addition to inet and macaddr).

Given that Taylor noted he would consider it in his HashNode AMA, I wanted to propose this.
screen shot 2016-03-27 at 4 10 22 pm

Verified

This commit was signed with the committer’s verified signature.
Eomm Manuel Spigolon
@aejnsn
Copy link
Contributor Author

aejnsn commented Mar 27, 2016

Looks like StyleCI has had an error on its end. @GrahamCampbell?

@GrahamCampbell
Copy link
Member

I've retriggered the ci services.

@taylorotwell taylorotwell merged commit a334724 into laravel:5.2 Mar 28, 2016
@aejnsn
Copy link
Contributor Author

aejnsn commented Mar 28, 2016

Thanks @GrahamCampbell.

@salarmehr
Copy link

I think for fixed length column such as ip and mac char type is more efficient than varchar.

@aejnsn
Copy link
Contributor Author

aejnsn commented Apr 23, 2016

@salarmehr The IP address type is not fixed length, as the PostgreSQL type can take IPv4 or IPv6. IPv6 alone is definitely not fixed length, given the possibility of IPv4-mapped IPv6 addresses.

There are several conventions pertaining to MAC addresses, thus causing the length to vary. Here are a few of those conventions pulled from the PostgreSQL documentation regarding the MAC address type:

'08:00:2b:01:02:03'
'08-00-2b-01-02-03'
'08002b:010203'
'08002b-010203'
'0800.2b01.0203'
'0800-2b01-0203'
'08002b010203'

The intention of this PR was to allow Laravel to use these two 'real' network types within PostgreSQL out of the box, while still providing a fully compatible fallback solution for other database systems.

@salarmehr
Copy link

The comment was for mysql. Regardless of their format, the length does not change dramatically.

@aejnsn
Copy link
Contributor Author

aejnsn commented Apr 24, 2016

Regardless of which database system your comment pertains to, Laravel should have a level playing field across all of them.

The length does indeed change dramatically, as the example, IPv4-mapped IPv6 addresses, I mentioned above could require up to an additional 15 characters.

Example:

Full notation IPv6 Address:
2001:0db8:0a0b:12f0:0000:0000:0000:0001 (39 characters)

Compressed notation IPv6 Address:
2001:db8:a0b:12f0::1 (20 characters)

IPv4-mapped IPv6 Address:
0064:ff9b:0000:0000:0000:0000:183.152.86.120 (44 characters)

This is an epitomical use case for the varchar type. It fits the exact definition in that the character count will vary for this field. Using a fixed length char of 45 characters is wasteful (e.g., the IPv4 address 8.8.8.8 consumes 8 bytes as varchar). A varchar consumes number of characters + 1 bytes. A char would always consume the set length--45 bytes in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants