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

ERROR: relation "metric_points" does not exist at character 90 #2955

Closed
joaocfernandes opened this issue Mar 23, 2018 · 4 comments
Closed

ERROR: relation "metric_points" does not exist at character 90 #2955

joaocfernandes opened this issue Mar 23, 2018 · 4 comments
Labels

Comments

@joaocfernandes
Copy link

Hi all,

Install of Cachet version 2.3.13 , running through docker-compose with Postgres.

On a pageload where a metric (2) is enabled the following Postgres error is logged:

Postgres_1  | ERROR:  relation "metric_points" does not exist at character 90
postgres_1  | STATEMENT:  select avg(metric_points.value * metric_points.counter) as value FROM chq_metrics m JOIN metric_points ON metric_points.metric_id = m.id WHERE metric_points.metric_id = $1 AND to_char(metric_points.created_at, 'YYYYMMDDHH24') = $2 GROUP BY to_char(metric_points.created_at, 'H')

In the cachet the following error is logged:

cachet_1    | [23-Mar-2018 16:17:34] WARNING: [pool www] child 72 said into stderr: "NOTICE: PHP message: [2018-03-23 16:17:34] development.ERROR: PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "metric_points" does not exist"
cachet_1    | [23-Mar-2018 16:17:34] WARNING: [pool www] child 72 said into stderr: "LINE 1: ..._points.counter) as value FROM chq_metrics m JOIN metric_poi..."
cachet_1    | [23-Mar-2018 16:17:34] WARNING: [pool www] child 72 said into stderr: "                                                             ^ in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:335"

I have checked the tables that do exist in postgres:

postgres=# \dt
                 List of relations
 Schema |          Name          | Type  |  Owner   
--------+------------------------+-------+----------
 public | chq_cache              | table | postgres
 public | chq_component_groups   | table | postgres
 public | chq_component_tag      | table | postgres
 public | chq_components         | table | postgres
 public | chq_failed_jobs        | table | postgres
 public | chq_incident_templates | table | postgres
 public | chq_incidents          | table | postgres
 public | chq_invites            | table | postgres
 public | chq_jobs               | table | postgres
 public | chq_metric_points      | table | postgres
 public | chq_metrics            | table | postgres
 public | chq_migrations         | table | postgres
 public | chq_sessions           | table | postgres
 public | chq_settings           | table | postgres
 public | chq_subscribers        | table | postgres
 public | chq_subscriptions      | table | postgres
 public | chq_tags               | table | postgres
 public | chq_users              | table | postgres
(18 rows)

A metric was created , and some data was populated into metric/2 .

Observing the query provided to postgres , mentions table metric_points instead of the chq_metric_points.

I have talked with @anthonybocci , which also evaluated this and is going to evaluate/implement the fix.

Thanks everyone,

@welcome
Copy link

welcome bot commented Mar 23, 2018

👋 Hey, it's good to see you here! Thank you for opening your first issue. Cachet support is not available here, instead we have a Slack community that can you can join at https://cachethq-slack.herokuapp.com

nalysius added a commit to nalysius/Cachet that referenced this issue Mar 23, 2018
In the '.env' file, a 'DB_PREFIX' sets the prefix that should be used
on every table name. When writing an SQL query the 'DB_PREFIX' value
has to be prefixed to the table name.

The repository PgSqlRepository, MySqlRepository and SqliteRepository,
located in 'app/Repositories/Metric/' did not apply this prefix on
the 'metric_points' table. The problem occured only when we set a
'DB_PREFIX' not null, the rest of the application worked correctly but
the part about 'metric_points' couldn't work, saying the table was
inexistant.

A method was added in the repository AbstractMetricRepository to get
the 'metric_points' table name with the prefix if there is one.
This method is used in the three repositories to get the right table
name.

Note: This problem was present in 2.3, but was already fixed in 2.4 so
there is no need to apply this commit on the 2.4 branch.

See: CachetHQ/Cachet/cachethq#2955
@nalysius
Copy link
Contributor

In the repositories (app/Repositories/Metrics) a method gives the 'metrics' table name, but there is no method giving the 'metric_points' table name using the prefix, the table name was hard-written.

I've a branch where I've fixed this problem by adding a method, could you try if everything is good for you before I submit a pull request?

@joaocfernandes
Copy link
Author

joaocfernandes commented Mar 26, 2018

Hi,

I have tested the branch provided against my docker install. The issue is solved.
No errors appear on page load on the logs now.

2018-03-26_10h56_18

Thanks @anthonybocci!!

Best Regards,
João Fernandes

@jbrooksuk
Copy link
Member

Closed by #2960

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

No branches or pull requests

3 participants