Coder Social home page Coder Social logo

db's People

Contributors

1-alex98 avatar ahsanbagwan avatar askaholic avatar blackyps avatar brutus5000 avatar bukajsytlos avatar cheyans avatar chriskitching avatar cleborys avatar duk3luk3 avatar eforgacs avatar eximius avatar hardlysoftly avatar idragonfire avatar micheljung avatar norraxx avatar philipjfryfaf avatar rackover avatar raistlfiren avatar sheeo avatar sheikah45 avatar yaniv-aknin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

db's Issues

Remove CURRENT_TIMESTAMP for game_stats.startTime

game_stats.startTime is currently set implicitly by DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP which, if you think about it for one second, is not a smart thing to do.

This causes any game that have any of its values updated (like validity) when the game ends to have its startTime set to the game end time. Outch!

Dockerfile

Hi,

I have free time and desire to improve Docker related stuff here.
How can I contribute, is it needed anyways?

PS: This will be a practice for me and I want to help the FAF community. If you would like to know who I am and what I do, please send me a private message (I do not know if it's possible in github)

Unify DB Fixtures for Tests

If we could unify all of our database fixtures into the DB repo that'd be nice, no rush on this, of course.

game_player_stats.playerId has no FK constraint on login

game_player_stats.playerId references login but has no constraint set; there are players referenced who do no longer exist in login.

Proposed fix:

ALTER TABLE game_player_stats ADD CONSTRAINT fk_game_player_stats_player FOREIGN KEY (playerId) REFERENCES login(id);

2016-10-10 Database Update v5

  • Make sure Server & API are stopped
  • Back up database:
docker exec -i stable_faf-db_1 mysqldump --login-path=faf_lobby --databases faf_lobby > /opt/stable/db_dumps/faf_lobby-$(date +"%Y-%m-%d-%H-%M-%S").sql
  • Since we never properly upgraded to mysql 5.7, execute:
docker exec -ti stable_faf-db_1 mysql_upgrade -u root -p
  • Since our passwords for root@localhost and [email protected] are different, make them equal:
docker exec -i stable_faf-db_1 mysql --login-path=faf_lobby -e "alter user 'root'@'127.0.0.1' identified by 'ENTERPASSWORDHERE';"
  • Merge origin/develop into origin/master
  • Tag origin/master as v5
  • Create & adjust flyway.conf (change DB and password):
cd /opt/stable/db_repo/
git fetch && git checkout v5
cp example_flyway.conf flyway.conf
vi flyway.conf
  • Install flyway into DB container by either rebuilding it or executing:
docker exec -i stable_faf-db_1 bash -c 'apt-get update \
    && apt-get install wget -y \
    && wget -q http://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/4.0.3/flyway-commandline-4.0.3-linux-x64.tar.gz \
    && tar xzf flyway-commandline-4.0.3-linux-x64.tar.gz \
    && rm flyway-commandline-4.0.3-linux-x64.tar.gz \
    && mv flyway-4.0.3 flyway \
    && chmod +x flyway/flyway \
    && wget -q http://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/6.0.4/mysql-connector-java-6.0.4.jar -O flyway/drivers/mysql-connector-java-6.0.4.jar'
  • Start migration
./migrate.sh

Name of docker container: stable_faf-db_1
Is this the first time Flyway runs on this database? y
Does the database already contain data? y

Migration is expected to run successfully:

Database: jdbc:mysql://127.0.0.1:3306/faf_lobby?useSSL=false (MySQL 5.7)
Creating Metadata table: `faf_lobby`.`schema_version`
Successfully baselined schema with version: 1
Flyway 4.0.3 by Boxfuse

Database: jdbc:mysql://127.0.0.1:3306/faf_lobby?useSSL=false (MySQL 5.7)
Successfully validated 5 migrations (execution time 00:00.023s)
Current version of schema `faf_lobby`: 1
Migrating schema `faf_lobby` to version 2 - add-clan-tag-colors
Migrating schema `faf_lobby` to version 3 - achievement-create-time
Migrating schema `faf_lobby` to version 4 - achievements-foreign-keys
Migrating schema `faf_lobby` to version 5 - mod migration
Successfully applied 4 migrations to schema `faf_lobby` (execution time 00:29.766s).

Fallback

If shit hits the fan, restore the old Database:

docker exec -i stable_faf-db_1 mysql --login-path=faf_lobby -e "drop database faf_lobby;"
docker exec -i stable_faf-db_1 mysql --login-path=faf_lobby < /opt/stable/db_dumps/faf_lobby-DATETIME.sql

Allow 'game_player_stats.score' to be null

score is currently non-null and initialized with -1 by the server which basically means "no score".
Instead, score should be nullable. Since the server sets it explicitly anyway and is the only software that sets it, we don't need to fix anything on the server.

Add player_count to coop_leaderboard

The coop_leaderboard currently doesn't store the number of players that were in the game, requiring an extensive query to get this information.
One might argue that this is redundant data; however, time is stored, being just as redundant as the player count.

While the extensive query isn't very expensive, things are much easier without (especially to understand). So I'm going to add player_count as a field.

Fix game_stats.mapId

We have a lot of game_stats.mapId with value 0. I suspect a casing problem in the respective query on the server (filename upper/lowercase) which needs to be fixed.

After this is sorted out, we should restore as many map IDs as we can by reading the maps from the replay files.

Last step is to decide/change whether mapId should be nullable or not; currently it's not, but players can play maps that aren't in our database (think of map creators). The question is if we want to store such games at all; if yes, then mapId needs to be nullable.

Add Permission System for Mod App

Requirement from the Mod App Specification

Permission System
Not every mod can use every feature

I suggest to introduce a classic permission system:

  • You ask for a special permission, e.g. ban.create, ban.delete
  • Admins can define roles with a set of permissions, e.g.role mod with permission ban.*, avatar.*
  • Admins can assign permissions or roles to a user

Step 1

  • We introduce Permissions

Step 2

  • We introduce Roles

Travis for database

Many components depend on this so this module should also build in travis ...

game_stats.host has no FK constraint on login

game_stats.host references login but has no constraint set; there are players referenced who do no longer exist in login.

Proposed fix:

INSERT INTO login (id, login, email, password) SELECT
                                                 host,
                                                 concat("Unknown_", host),
                                                 concat("user", host, "@example.com"),
                                                 ""
                                               FROM game_stats
                                               WHERE host NOT IN (SELECT id
                                                                  FROM login)
                                               GROUP BY host;

ALTER TABLE game_stats ADD CONSTRAINT fk_game_stats_host FOREIGN KEY (host) REFERENCES login(id);

Reintroduce game_stats.endTime

game_stats.endTime has been removed because, I guess, it was seen as redundant information which can be derived from game_player_stats.scoreTime.

This not only introduces a performance nightmare when querying anything related to endTime - like in the replay vault search - but also isn't even technically correct.

A game does not (have to) end when the last player's score has been reported. In some games, there isn't even a score report because the players just disconnect - so endTime stays empty.

Therefore, the game_stats.endTime need to be brought back and set explicitly by the server.

Foreign keys for clan tables

Sounds easy, but actually isn't:

mysql> select count(*) from clan_members where player_id not in (select id from login);
+----------+
| count(*) |
+----------+
|     1479 |
+----------+

Something is awefully wrong.

Remove obsolete tables

There are a few tables that are no longer used (or have never been used) and should therefore be removed:

  • auth_group (never used)
  • auth_group_permissions (never used)
  • auth_permission (never used)
  • auth_user (never used)
  • avatars_list_copy_812015 (unused, empty)
  • bet (no longer used, data has no value for us. Some people were able to "cheat".)
  • db_version (unused, was part of the old migration script)
  • game_min_rating (unused, redundant)
  • game_replays (only used by non-working, unused command command_list in secondaryServer)
  • game_replays_old (unused, empty)
  • ladder_season_3_safe (unused, empty)
  • ladder_divisions (unused, useless data, superseded by ladder_division)
  • login_with_duplicated_users (unused, empty)
  • replay_vault (unused, superseded by game_stats
  • smurf_table (unused, obsolete)
  • table_map_broken (unused, superseded by "hidden" flag in new table structure)
  • test_game_replays (unused)
  • tmp (unused)
  • updates (obsolete, unused)
  • vault_admin (unused, obsolete data (2 entries))
  • view_global_rating (unused, isn't even a view)

Improve Dockerization

IMO this project needs the following improvements:

  • Initialize the database automatically during container creation if the database does not yet exist instead of having the user execute a setup script manually. Also it should be "production ready", meaning that it assumes to be a productive DB and therefore does not load any test data into the database.
  • In order to integrate well with faf-stack, this project should also create databases and users for other tools like IRC, Mediawiki and so on since it's the only project that should have DB root permissions.
  • Since faf-server (and potentially faf-api or others) doesn't work properly without some standard "featured" mods in the database, such core data should be added during the DB initialization (it could be added by faf-server if it's missing, but that's not smart since other projects may rely on it as well)
  • The Dockerfile should specify a healthcheck (new Docker feature)
  • The migration script should be part of the container and executed within the container, not from outside

Data and Migration Inquiry

Hi,

First question - Should the migrations be ran after importing the initial structure into the database?

Second Question - Is there anyway we can get more data for the database tables? For example, it would be useful to have some of the rankings and 1v1 data. I am sure Python has a Faker library to create data for the database, but that would take more time then a simple export.

MySQL Bug Cannot Insert null timestamps

Expected behaviour
https://bugs.mysql.com/bug.php?id=72628

mysql> create table t1(c1 timestamp not null default '2000-01-01 00:00:00');
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t1 values();
Query OK, 1 row affected (0.00 sec)

mysql> insert into t1 values(null);
Query OK, 1 row affected (0.01 sec)

mysql> insert into t1 values(default);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+---------------------+
| c1                  |
+---------------------+
| 2000-01-01 00:00:00 |
| 2014-08-01 06:11:50 |
| 2000-01-01 00:00:00 |
+---------------------+
3 rows in set (0.00 sec)

Behaviour with 5.7.16

mysql> create table t1(c1 timestamp not null default '2000-01-01 00:00:00');
Query OK, 0 rows affected (0.22 sec)

mysql> insert into t1 values(null);
ERROR 1048 (23000): Column 'c1' cannot be null

2016-08-08 Database migration

  • Make sure Server & API are stopped
  • Back up database:
cd /opt/stable
tar cvpjf db-backup-$(date +"%Y-%m-%d-%H-%M-%S").tar.bz2 db
  • Merge origin/develop into origin/master
  • Update DB on prod (get root password first):
cd /opt/stable/db_repo/
git pull
./migrate.sh

Name of docker container: stable_faf-db_1
Database to migrate: faf_lobby
Current database revision: ab3d56fe949550d2ac113a148582e4c7c690e25c

Migration is expected to run successfully:

<noise>
Database is now at revision 5ab8cba965337aa8ec3dc4b5089514e44f834862

Clean up table_map_features

The table table_map_features, like many other tables, is a mess that should be cleaned up.

Since it is used by the legacy map vault, we can't just fix it. Therefore, I recommend that we keep the current table as-is and create new ones and views next to it, until we can remove it completely.

Restore game bak tables

For some reason unknown to me, parts of game_stats and game_player_stats have been moved to game_stats_bak respective game_player_stats_bak. It's time to merge the table back in and stop having to maintain redundant tables that serve no purpose.
There is no relevant performance impact.

Howto: Update v34

  • Stop everything that writes into the database (server, api)
  • Backup
cd /opt/stable
docker exec -i stable_faf-db_1 mysqldump --login-path=faf_lobby faf_lobby | gzip -c > db-dump-$(date +"%Y-%m-%d-%H-%M-%S").sql.gzip
  • Make sure docker-compose.yml uses build: db_repo for faf-db
  • Configure Flyway (because the DB is still called faf_lobby and not faf). In /opt/stable/db_repo/migrate.sh:
flyway.url=jdbc:mysql://127.0.0.1/faf_lobby?localSocket=/var/run/mysqld/mysqld.sock
  • Rebuild container (because we updated MySQL)
docker-compose up -d --build faf-db
  • Fix the migration version mismatch we have for some reason (doesn't cause harm):
update schema_version set checksum = -427051799 where version = 18;
  • Migrate DB
cd /opt/stable/db_repo
git fetch
git checkout v34
docker exec -i stable_faf-db_1 ./migrate.sh

Add checksum to map version

We have no clean way to map the local map to a map on the server.
because the user can e.g. modify the map locally, the map is not uploaded ...

I suggest to add a checksum column to the map_version table.
Then we can identify local broken maps and also implement a auto update map feature ;)

Please vote with ๐Ÿ‘ or ๐Ÿ‘Ž

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.