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

Add support for postgres citext data-type #10024

Merged
merged 9 commits into from Oct 15, 2018
Merged

Add support for postgres citext data-type #10024

merged 9 commits into from Oct 15, 2018

Conversation

@justinkalland
Copy link
Contributor

@justinkalland justinkalland commented Oct 11, 2018

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Adds support for CITEXT data-type. This is a Postgres only data-type. This also adds support for ARRAY(CITEXT).

To use CITEXT it must first be enabled in Postgres:

CREATE EXTENSION IF NOT EXISTS citext;

The new tests will fail unless the module is enabled in Postgres. I have created as change to enable the module in the custom Docker image: sushantdhiman/sequelize-postgres#1

Closes #9116
Closes #6572

Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Looks good. I have updated docker images for CI

@@ -11,6 +11,7 @@ AbstractDialect.prototype.supports = {
'ORDER NULLS': false,
'UNION': true,
'UNION ALL': true,
'CITEXT': false,

This comment has been minimized.

@sushantdhiman

sushantdhiman Oct 12, 2018
Contributor

No need for this in supports, these flags are meant to switch code segments when generating queries or declaring support information that is used anywhere in lib/, for tests you can just compare dialect === 'postgres'

@@ -168,6 +168,20 @@ module.exports = BaseTypes => {
array_oids: [1009]
};

function CITEXT() {

This comment has been minimized.

@sushantdhiman

sushantdhiman Oct 12, 2018
Contributor

As this implementation is not changed, defining function CITEXT is not required. You just need

  BaseTypes.CITEXT.types.postgres = {
    oids: [146932],
    array_oids: [146937]
  };
@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented Oct 12, 2018

There is some issue with postgres-9.5 image, I'll fix that in evening (approx 7-8 hours). postgres-10 image is working properly so you can use that to verify your changes on CI

@codecov
Copy link

@codecov codecov bot commented Oct 12, 2018

Codecov Report

Merging #10024 into master will decrease coverage by 0.02%.
The diff coverage is 82.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10024      +/-   ##
==========================================
- Coverage   96.38%   96.36%   -0.03%     
==========================================
  Files          63       63              
  Lines        9386     9399      +13     
==========================================
+ Hits         9047     9057      +10     
- Misses        339      342       +3
Impacted Files Coverage Δ
lib/dialects/postgres/data-types.js 97.82% <100%> (ø) ⬆️
lib/dialects/postgres/connection-manager.js 93.63% <100%> (+0.11%) ⬆️
lib/data-types.js 95.21% <70%> (-0.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa587ac...d4f1e21. Read the comment docs.

@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented Oct 12, 2018

Now all images has been fixed, please address my code related comments and this can be merged

Removed uneeded CITEXT in supports and changed tests to use `dialect` instead.
Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Please add a standard datatypes test here

@@ -120,6 +120,7 @@ Sequelize.STRING(1234) // VARCHAR(1234)
Sequelize.STRING.BINARY // VARCHAR BINARY
Sequelize.TEXT // TEXT
Sequelize.TEXT('tiny') // TINYTEXT
Sequelize.CITEXT() // CITEXT PostgreSQL only.

This comment has been minimized.

@sushantdhiman

sushantdhiman Oct 13, 2018
Contributor

Sequelize.CITEXT not Sequelize.CITEXT()

@justinkalland
Copy link
Contributor Author

@justinkalland justinkalland commented Oct 14, 2018

Discovered that CITEXT has dynamic OIDs and changed to handle that.

@@ -221,7 +222,8 @@ class ConnectionManager extends AbstractConnectionManager {
dataTypes.postgres.GEOMETRY,
dataTypes.postgres.HSTORE,
dataTypes.postgres.GEOGRAPHY,
dataTypes.postgres.ENUM
dataTypes.postgres.ENUM,
dataTypes.CITEXT

This comment has been minimized.

@sushantdhiman

sushantdhiman Oct 14, 2018
Contributor

dataTypes.postgres.CITEXT is not available, right?

As we need to dynamically update OIDs it is better to define this type in postgres/data-types.js

  function CITEXT(options) {
    if (!(this instanceof CITEXT)) return new CITEXT(options);
    BaseTypes.CITEXT.apply(this, arguments);
  }
  inherits(CITEXT, BaseTypes.CITEXT);

  BaseTypes.CITEXT.types.postgres = {
    oids: [],
    array_oids: []
  };

and have it exported. So you can use dataTypes.postgres.CITEXT here and in code just below

This comment has been minimized.

@justinkalland

justinkalland Oct 14, 2018
Author Contributor

Perhaps it is bit much to redeclare in the Postgres data-types? If you are concerned about how it looks, this would be cleaner:

      // Reset OID mapping for dynamic type
      [
        dataTypes.GEOMETRY,
        dataTypes.HSTORE,
        dataTypes.GEOGRAPHY,
        dataTypes.ENUM,
        dataTypes.CITEXT
      ].forEach(type => {
        type.types.postgres.oids = [];
        type.types.postgres.array_oids = [];
      });

      for (const row of result.rows) {
        let type;

        if (row.typname === 'geometry') {
          type = dataTypes.GEOMETRY;
        } else if (row.typname === 'hstore') {
          type = dataTypes.HSTORE;
        } else if (row.typname === 'geography') {
          type = dataTypes.GEOGRAPHY;
        } else if (row.typname === 'citext') {
          type = dataTypes.CITEXT;
        } else if (row.typtype === 'e') {
          type = dataTypes.ENUM;
        }
@sushantdhiman sushantdhiman merged commit cf6c05e into sequelize:master Oct 15, 2018
2 of 4 checks passed
2 of 4 checks passed
codecov/patch 82.35% of diff hit (target 96.38%)
Details
codecov/project 96.36% (-0.03%) compared to fa587ac
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented Oct 15, 2018

@justinkalland justinkalland deleted the justinkalland:add-postgres-citext branch Oct 15, 2018
@justinkalland justinkalland mentioned this pull request Oct 16, 2018
5 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants