-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blair Anderson
committed
Apr 5, 2015
1 parent
5520445
commit 3fd5afb
Showing
5 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class AddHotScoreFunction < ActiveRecord::Migration | ||
# This is some sql borrowed from reddit: | ||
# https://github.com/reddit/reddit/blob/master/sql/functions.sql | ||
def up | ||
execute <<-SQL | ||
create or replace function | ||
hot_score(ups integer, downs integer, date timestamp with time zone) | ||
returns numeric as $$ | ||
select round(cast(log(greatest(abs($1 - $2), 1)) * sign($1 - $2) + | ||
(date_part('epoch', $3) - 1134028003) / 45000.0 as numeric), 7) | ||
$$ language sql immutable; | ||
SQL | ||
end | ||
|
||
def down | ||
execute "DROP FUNCTION IF EXISTS hot_score(integer, integer, timestamp);" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello and thank you for open sourcing the code base.
I'm having a problem where once the vote is cast, ActiveRecord throws the following error:
ActiveRecord::StatementInvalid in UserItemVotesController#create
PG::UndefinedFunction: ERROR: function hot_score(integer, integer, timestamp with time zone) does not exist LINE 1: SELECT id, hot_score(1, 0, created_at) as hot_score FROM "i... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. : SELECT id, hot_score(1, 0, created_at) as hot_score FROM "items" WHERE "items"."id" = $1 ORDER BY "items"."id" ASC LIMIT 1
What I have tried:
Changed the format of the created_at to accept timestamp without time zone and then run bundle exec rake:db migrate to no avail.
Thank you.
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leonardykris can you run the migration?
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be easier if you start fresh and run these
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @blairanderson, yeah I can run the migration. I followed the instructions you listed above and cloned the repo to a new folder, but it still gives me the same error. Screenshot is attached below.
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is really weird because i just did the exact same thing and its working fine...
The migration creates the function. That error says the function doesn't exist.
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leonardykris can you run
bundle exec rake db:migrate:up VERSION=20150405200823
and restart your server?3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leonardykris
if you make an account on https://www.nitrous.io/ and try it there. I would love to help figure out why its not working for you.
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried running the migration to that version and it still gives me the error. However, I tried deleting the database this time (in the previous test I didn't clear the database so I guess it wasn't a really 'fresh start') and running through the procedures again. I noticed that during migration, the function is added now and if I do recall it correctly, I didn't see those lines during my earlier migrations - which is really weird.
3fd5afb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, the issue is solved now! Thanks for the lightning fast response and help!