You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Out-of-the-box, without the database tables existing yet, yarn start (after a yarn compile) returns an error.
This specific error could be solved (or actually circumvented) by first commenting out these lines in /src/games/entities.ts:
@Column()
userId: number
Although yarn start will now complete initialisation of the database, it will now result in users not being able to login with their email and password. It will return this TypeError:
TypeError: Cannot read property 'firstName' of undefined
(anonymous function)
src/components/games/GamesList.js:46
43 | This game is played by
44 | {
45 | game.players
> 46 | .map(player => users[player.userId].firstName)
47 | .join(' and ')
48 | }
49 | </Typography>
This TypeError, on its turn, could be fixed by uncommenting the lines mentioned earlier, which after a yarn start will alter the players-table to have the required user_id field:
[...]
executing query: ALTER TABLE "public"."players" DROP CONSTRAINT "fk_22e69d59151c3a12871d09c0862"
executing query: DROP INDEX "public"."ind_53e31f43339d983c41071d2385"
executing query: ALTER TABLE "public"."players" ALTER COLUMN "user_id" TYPE integer
executing query: ALTER TABLE "public"."players" ALTER COLUMN "user_id" SET NOT NULL
executing query: CREATE UNIQUE INDEX "ind_53e31f43339d983c41071d2385" ON "public"."players"("game_id","user_id","symbol")
executing query: ALTER TABLE "public"."players" ADD CONSTRAINT "fk_22e69d59151c3a12871d09c0862" FOREIGN KEY ("user_id") REFERENCES "users"("id")
executing query: COMMIT
[...]
There must be a more elegant way to solve this, right?
Here is the full output of yarn start when issued out-of-the-box:
$ yarn start
yarn run v1.12.3
$ node .
executing query: START TRANSACTION
executing query: SELECT * FROM current_schema()
executing query: SELECT * FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'games' OR table_schema = 'public' AND table_name = 'players' OR table_schema = 'public' AND table_name = 'users'
executing query: SELECT * FROM information_schema.columns WHERE table_schema IN ('public')
executing query: SELECT t.relname AS table_name, i.relname AS index_name, a.attname AS column_name, ix.indisunique AS is_unique, a.attnum, ix.indkey FROM pg_class t, pg_class i, pg_index ix, pg_attribute a, pg_namespace ns
WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid
AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' AND t.relname IN ('games', 'players', 'users') AND t.relnamespace = ns.OID AND ns.nspname IN ('public') ORDER BY t.relname, i.relname
executing query: SELECT table_name, constraint_name FROM information_schema.table_constraints WHERE table_schema IN ('public') AND constraint_type = 'FOREIGN KEY'
executing query: SELECT * FROM information_schema.table_constraints WHERE table_schema IN ('public') AND constraint_type = 'UNIQUE'
executing query: SELECT c.column_name, tc.table_name, tc.constraint_name FROM information_schema.table_constraints tc
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
where constraint_type = 'PRIMARY KEY' AND c.table_schema IN ('public')
executing query: CREATE TABLE "games" ("id" SERIAL NOT NULL, "board" json NOT NULL DEFAULT '[[null,null,null],[null,null,null],[null,null,null]]', "turn" character(1) NOT NULL DEFAULT 'x', "winner" character(1), "status" text NOT NULL DEFAULT 'pending', PRIMARY KEY("id"))
executing query: CREATE TABLE "players" ("id" SERIAL NOT NULL, "user_id" integer NOT NULL, "symbol" character(1) NOT NULL, "user_id" integer, "game_id" integer, PRIMARY KEY("id"))
query failed: CREATE TABLE "players" ("id" SERIAL NOT NULL, "user_id" integer NOT NULL, "symbol" character(1) NOT NULL, "user_id" integer, "game_id" integer, PRIMARY KEY("id"))
error: { error: column "user_id" specified more than once
at Connection.parseE (/Users/sil/repos/game-starter-b15/server/node_modules/pg/lib/connection.js:545:11)
at Connection.parseMessage (/Users/sil/repos/game-starter-b15/server/node_modules/pg/lib/connection.js:370:19)
at Socket.<anonymous> (/Users/sil/repos/game-starter-b15/server/node_modules/pg/lib/connection.js:113:22)
at Socket.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at Socket.Readable.push (_stream_readable.js:218:10)
at TCP.onread (net.js:581:20)
name: 'error',
length: 105,
severity: 'ERROR',
code: '42701',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'tablecmds.c',
line: '1925',
routine: 'MergeAttributes' }
executing query: ROLLBACK
{ QueryFailedError: column "user_id" specified more than once
at new QueryFailedError (/Users/sil/repos/game-starter-b15/server/node_modules/typeorm/error/QueryFailedError.js:27:28)
at Query.callback (/Users/sil/repos/game-starter-b15/server/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:216:38)
at Query.handleError (/Users/sil/repos/game-starter-b15/server/node_modules/pg/lib/query.js:143:17)
at Connection.connectedErrorHandler (/Users/sil/repos/game-starter-b15/server/node_modules/pg/lib/client.js:132:26)
at Connection.emit (events.js:180:13)
at Socket.<anonymous> (/Users/sil/repos/game-starter-b15/server/node_modules/pg/lib/connection.js:117:12)
at Socket.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at Socket.Readable.push (_stream_readable.js:218:10)
message: 'column "user_id" specified more than once',
name: 'QueryFailedError',
length: 105,
severity: 'ERROR',
code: '42701',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'tablecmds.c',
line: '1925',
routine: 'MergeAttributes',
query: 'CREATE TABLE "players" ("id" SERIAL NOT NULL, "user_id" integer NOT NULL, "symbol" character(1) NOT NULL, "user_id" integer, "game_id" integer, PRIMARY KEY("id"))',
parameters: [] }
✨ Done in 1.51s.
The text was updated successfully, but these errors were encountered:
Out-of-the-box, without the database tables existing yet,
yarn start
(after ayarn compile
) returns an error.This specific error could be solved (or actually circumvented) by first commenting out these lines in
/src/games/entities.ts
:Although
yarn start
will now complete initialisation of the database, it will now result in users not being able to login with their email and password. It will return this TypeError:This TypeError, on its turn, could be fixed by uncommenting the lines mentioned earlier, which after a
yarn start
will alter the players-table to have the requireduser_id
field:There must be a more elegant way to solve this, right?
Here is the full output of
yarn start
when issued out-of-the-box:The text was updated successfully, but these errors were encountered: