Liang Chen

Software Engineer

0%

最近看中國視頻學到的新詞。


什麼是「內卷」

簡單定義:低級的循環往復

從農場、工廠、互聯網創作,都是產出供給,而供給需要被有效的消費掉

在需求不變的情況下,新生產力(新工人)投入,可能導致以下兩種情況:

  • 削價競爭,也就是「內卷」
  • 淘汰多餘的生產力(工人)

中國內卷化的原因

出口需求飽和,但國內消費又不足夠填補

國內消費需求低的可能原因:

  • 繳了各種貸款(房貸、車貸)沒錢消費
  • 勞工普遍低薪
  • 再分配(稅收)沒分到一般大眾

Reference

工资太低?什么都难做?究竟是什么导致中国这些年的”突然内卷化”?【Eng Sub】What caused China’s Involution/Neijuanhua? Rich Poor Gap?

About burn

When

  • burn as gas fee (BEP-95)
  • burn by quarter
  • burn by price (Auto-Burn)
  • some smart contracts also burn BNB in some conditions

Why

To make deflation

How

Send tokens to an address without a private key, which means no one can access the tokens anymore.

BEP-95

Why

To fasten the burn efficiency.

How

Since the solution is to burn partial of validators’ reward, the more users use BSC (which means more blocks need to be validated by validators), the more BNB would be burned.

Auto-Burn

Rule

The more the price of BNB decreases, the more BNB will be burned.

When the total supply is lower than 1B, the burn process stops (BEP-95 still works).

Formula

1
B = N * 1000 / (P + K)
  • B: how many BNB to burn
  • N: new BNB amount of this quarter
  • P: average price
  • K: constant value, 1000

More detail about Auto-Burn

Intro

I got a mission to clone an existing service, which has its database separately from the original.

Here is my to-do list:

  1. create tables
  2. sync data

This article will focus on how to sync data. To read how to create tables from the old database check out here

Laravel Database Sync

I found this great tool to do this task: https://github.com/waelwalid/laravel-database-sync

Please follow the instructions to install the tool.

Adjustments

I run my app in a php-fpm-alpine docker container so some adjustments need to do or the tool won’t work.

  1. Make the container can run the shell scripts
  2. Install mysql-client
  3. Disable LOCK TABLE if you are NOT a root user in the synced database when executing mysqldump

1. Make the container can run the shell scripts

The sync-tool is implemented by shell scripts, and with the header, #!/bin/bash, so only bash can run it.

And since I used an alpine image, which doesn’t have the Bash installed by default so I had two options:

  1. Change the header to #!/bin/sh
  2. Install Bash or just use an Ubuntu image for convenience
1
2
# add this to the Dockerfile
RUN apk add --no-cache --upgrade bash

2. Install mysql-client

Still, by default, the alpine image doesn’t come with mysql-client, which is used in the shell script so we need to install it.

1
apk add --no-cache mysql-client

3. Disable LOCK TABLE if you are NOT a root user in the synced database

Since I sync the data using a user who ONLY has SELECT privilege, I need to disable LOCK TABLE, and PROCESS when dumping the data.

Open vendor/waelwalid/laravel-database-sync/database-update.sh.

Add --single-transaction=TRUE --no-tablespaces after mysqldump command.

Like this:

1
2
3
4
mysqldump -v --single-transaction=TRUE --no-tablespaces \
-h $REMOTE_DATABASE_HOST -u $REMOTE_DATABASE_USER \
-p $REMOTE_DATABASE_PASS $REMOTE_DATABASE_NAME \
> $CONFIG/dumps/remote-database-$CURRENT_TIME.sql

If you use login as root, or other users with LOCK TABLE, and PROCESS privileges, you can skip this step.

Quote from the document:

mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, LOCK TABLES if the –single-transaction option is not used, and (as of MySQL 8.0.21) PROCESS if the –no-tablespaces option is not used. Certain options might require other privileges as noted in the option descriptions.

Check out for more details about mysqldump

After all

Now you can run composer database-update to sync the data, or just execute .vendor/waelwalid/laravel-database-sync/database-update.sh which is the same, cheers :)

Intro

I got a mission to clone an existing service, which has its database separately from the original.

Here is my to-do list:

  1. create tables
  2. sync data

This article will only record the first step. the next step will be written in the second episode.

How to create tables from the existing database

Since this project is a Laravel app, but without migration files so I came out with 2 solutions:

  1. Create migrations from the existing database, then run php artisan migrate to create the same tables to my new database
  2. Create create-table-SQLs from the existing database, then somehow run these SQLs

Migration Generator

I thought the first one is more ideal since it is easier for other developers to maintain so I googled “laravel create migration …” then google returned me a bunch of packages to do these tasks, nice!

here is a couple of choices:

So I generated all the migrations in seconds, lovely!
Then I run php artisan migrate!

CRASH!

Checked out the migrations, found that the generator didn’t generate the codes properly. It missed some details, like lacking index, so I needed to go through each file to debug… which was not my purpose to use a tool so I tried the second solution, create tables by pure SQL

How to Execute SQL Files in Laravel

It is easier than I thought

1
2
3
use Illuminate\Support\Facades\DB;

DB::unprepared(file_get_contents('path/to/sql.sql'));

I test a table and it worked properly, created exactly same table as the original without error

Implement

So I exported the table structure in SQL from phpMyAdmin manually (the total number of tables is still acceptable for me to do this).

Instead of creating a command to do this task, I still generated migrations matched to the tables since I would like to have the ROLLBACK feature in Laravel migration. Remember? We can create migrations in seconds by using one of the mentioned packages. Don’t forget to edit .env to switch to the original database, And after generating, switch back to the NEW database.

Here is my migration code. I put all the SQL in database/sql_migrations but you can put them anywhere you like.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateNewTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$sqlpath = 'database/sql_migrations/'.basename(__FILE__, ".php").'.sql';
Illuminate\Support\Facades\DB::unprepared(file_get_contents($sqlpath));
}


/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('new');
}

}

After all files are set, we can easily run php artisan migrate to create tables, and php artisan migrate:rollback to rollback.

Laravel | Sync Data From an Existing Database