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
Hello all, I have this "users" table.
I have this "points" field which determines the users "rank".. rank is selected from a "app_ranks" table lists each rank and the corresponding required points.
What I want is:
When "points" value is updated, the "rank_id" field should be automatically updated to the corresponding rank id from the "app_ranks" table.
Hello all, I have this "users" table.
I have this "points" field which determines the users "rank".. rank is selected from a "app_ranks" table lists each rank and the corresponding required points.
What I want is:
Here is my current code..
[1] users.go
`func GetUsersTable(ctx *context.Context) table.Table {
users := table.NewDefaultTable(ctx, table.DefaultConfigWithDriver("mysql"))
[2] users sql
DROP TABLE IF EXISTS "app_users";
CREATE TABLE "app_users" (
"id" int(10) unsigned NOT NULL AUTO_INCREMENT,
"points" int(10) unsigned DEFAULT 0,
"rank_id" int(10) unsigned DEFAULT 1,
"created_at" timestamp NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ("id"),
KEY "rank_id" ("rank_id"),
KEY "lang_id" ("lang_id"),
CONSTRAINT "app_users_rank_id_foreign" FOREIGN KEY ("rank_id") REFERENCES "app_ranks" ("id"),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
[3] ranks sql
DROP TABLE IF EXISTS 'app_ranks';
CREATE TABLE 'app_ranks' (
'id' int(10) unsigned NOT NULL AUTO_INCREMENT,
'rank' varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
'points_required' int NOT NULL DEFAULT 0,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
LOCK TABLES 'app_ranks' WRITE;
INSERT INTO 'app_ranks' ('id', 'rank', 'points_required') VALUES
(1, 'Newbie', 0),
(2, 'Explorer', 100),
(3, 'Pathfinder', 300),
(4, 'Discoverer', 600),
(5, 'Trailblazer', 1200),
(6, 'Guide', 2000),
(7, 'Adventurer', 3500),
(8, 'Navigator', 5000),
(9, 'Wayfinder', 7500),
(10, 'Voyager', 10000),
UNLOCK TABLES;
The text was updated successfully, but these errors were encountered: