Skip to content

Add support for postgres citext data-type - #10024

Merged
sushantdhiman merged 9 commits into
sequelize:masterfrom
justinkalland:add-postgres-citext
Oct 15, 2018
Merged

sushantdhiman merged 9 commits into
sequelize:masterfrom
justinkalland:add-postgres-citext

Conversation

@justinkalland

Copy link
Copy Markdown
Contributor

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

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have updated docker images for CI

Comment thread lib/dialects/abstract/index.js Outdated
'ORDER NULLS': false,
'UNION': true,
'UNION ALL': true,
'CITEXT': false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Comment thread lib/dialects/postgres/data-types.js Outdated
array_oids: [1009]
};

function CITEXT() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

sushantdhiman commented Oct 12, 2018 •

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Oct 12, 2018 •

Copy link
Copy Markdown

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
Copy Markdown
Contributor

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.

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a standard datatypes test here

Comment thread docs/models-definition.md Outdated
Sequelize.STRING.BINARY // VARCHAR BINARY
Sequelize.TEXT // TEXT
Sequelize.TEXT('tiny') // TINYTEXT
Sequelize.CITEXT() // CITEXT PostgreSQL only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sequelize.CITEXT not Sequelize.CITEXT()

@justinkalland

Copy link
Copy Markdown
Contributor Author

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

dataTypes.postgres.GEOGRAPHY,
dataTypes.postgres.ENUM
dataTypes.postgres.ENUM,
dataTypes.CITEXT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@sushantdhiman

Copy link
Copy Markdown
Contributor

Thanks @justinkalland

@justinkalland
justinkalland deleted the add-postgres-citext branch October 15, 2018 14:51
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.

2 participants