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

columns filtering #15

Closed
wants to merge 1 commit into from
Closed

columns filtering #15

wants to merge 1 commit into from

Conversation

Neyaz
Copy link

@Neyaz Neyaz commented Dec 3, 2016

Hello,
it's my solution task on cultofmartians.

end
end
end

Choose a reason for hiding this comment

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

Style/TrailingBlankLines: 1 trailing blank lines detected.

.to include("rating" => 22)

expect(post.log_data.versions.first.changes)
.not_to include("title" => "Triggers", "active" => true)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

expect(post.reload.log_version).to eq 6
expect(post.log_size).to eq 4
expect(post.log_data.versions.first.changes)
.to include("rating" => 22)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

.to include("rating" => 10)

expect(post.log_data.versions.first.changes)
.not_to include("title" => "Triggers", "active" => true)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

expect(post.reload.log_version).to eq 5
expect(post.log_size).to eq 4
expect(post.log_data.versions.first.changes)
.to include("rating" => 10)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

.to include("title" => "Triggers", "active" => true)

expect(post.log_data.versions.first.changes)
.not_to include("rating" => 20)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

expect(post.reload.log_version).to eq 6
expect(post.log_size).to eq 4
expect(post.log_data.versions.first.changes)
.to include("title" => "Triggers", "active" => true)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

.to include("title" => "Triggers", "active" => true)

expect(post.log_data.versions.first.changes)
.not_to include("rating" => 10)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

expect(post.reload.log_version).to eq 5
expect(post.log_size).to eq 4
expect(post.log_data.versions.first.changes)
.to include("title" => "Triggers", "active" => true)

Choose a reason for hiding this comment

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

Style/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/MultilineMethodCallIndentation: Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

let(:args) { ["user", "--except='active,age'", "--only='active,age'"] }

it "creates trigger with except and only" do
is_expected.to exist

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

end

context "with except and only" do
let(:args) { ["user", "--except='active,age'", "--only='active,age'"] }

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

let(:args) { ["user", "--limit=5", "--except='active,age'", "--only='active,age'"] }

it "creates trigger with limit and except and only" do
is_expected.to exist

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

end

context "with limit and except and only" do
let(:args) { ["user", "--limit=5", "--except='active,age'", "--only='active,age'"] }

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

let(:args) { ["user", "--limit=5", "--only='active,age'"] }

it "creates trigger with limit and only" do
is_expected.to exist

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

end

context "with limit and only" do
let(:args) { ["user", "--limit=5", "--only='active,age'"] }

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

let(:args) { ["user", "--limit=5", "--except='active,age'"] }

it "creates trigger with limit and except" do
is_expected.to exist

Choose a reason for hiding this comment

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

Style/IndentationWidth: Use 2 (not 4) spaces for indentation.

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

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

Overall, great work! Thanks!

IF blacklist <> 'null' THEN
filtered_array := logidze_exclude_keys(data, array['log_data']::text[] || string_to_array(blacklist, ','));
ELSIF blacklist = 'null' AND whitelist <> 'null' THEN
filtered_array := logidze_include_keys(data, string_to_array(whitelist, ','));
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer to leave the only one function for filtering, logidze_exclude_keys.
Then we have to calculate required keys beforehand, smth like:

keys_to_exclude := select array(select unnest(jsonb_object_keys(data)) except select unnest(whitelist));
filtered_array := logidze_exclude_keys(data, keys_to_exclude);

@@ -16,17 +16,26 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
end

execute <<-SQL
CREATE OR REPLACE FUNCTION logidze_version(v bigint, data jsonb) RETURNS jsonb AS $body$
CREATE OR REPLACE FUNCTION logidze_version(v bigint, data jsonb, blacklist text DEFAULT '', whitelist text DEFAULT '') RETURNS jsonb AS $body$
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we can use here blacklist text[] to avoid string_to_array for every operation?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, i used blacklist text[] , but got problems with how to transform ruby string to pl pgSQL array and decided to use strings

BEGIN
IF blacklist <> 'null' THEN
filtered_array := logidze_exclude_keys(data, array['log_data']::text[] || string_to_array(blacklist, ','));
Copy link
Owner

Choose a reason for hiding this comment

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

Why not {"log_data"}?

Copy link
Author

Choose a reason for hiding this comment

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

When i tried this notation I was getting "PG::SyntaxError: ERROR: syntax error at or near "{"".
But today i found what it should be (data, '{log_data}').


let(:params) { { title: 'Triggers', rating: 10, active: false } }

describe "backfill" do
Copy link
Owner

Choose a reason for hiding this comment

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

Please, do not duplicate existing tests. Only test the feature you're working on.
If you want to check that the new options don't break existing functionality, just add them to the existing migrations.

@temanmd
Copy link

temanmd commented Dec 4, 2016

good job! 👍

@Neyaz
Copy link
Author

Neyaz commented Dec 4, 2016

@palkan Thank you for review.

@palkan
Copy link
Owner

palkan commented Dec 27, 2016

@Neyaz Hi! How is it going?)

@palkan
Copy link
Owner

palkan commented Jan 13, 2017

Closed by #16

@palkan palkan closed this Jan 13, 2017
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.

4 participants