mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add migrations for dev
This commit is contained in:
parent
0ac448a9ba
commit
f67b267933
1
migrations_dev/000001_create_channels_table.down.sql
Normal file
1
migrations_dev/000001_create_channels_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS channels;
|
13
migrations_dev/000001_create_channels_table.up.sql
Normal file
13
migrations_dev/000001_create_channels_table.up.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS channels (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
added_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
|
||||||
|
login text UNIQUE NOT NULL,
|
||||||
|
twitchid text NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO channels (added_at,login,twitchid) VALUES
|
||||||
|
(NOW(),'nouryxd','31437432'),
|
||||||
|
(NOW(),'nourybot','596581605'),
|
||||||
|
(NOW(),'uudelleenkytkeytynyt','465178364'),
|
||||||
|
(NOW(),'xnoury','197780373');
|
||||||
|
|
1
migrations_dev/000002_create_users_table.down.sql
Normal file
1
migrations_dev/000002_create_users_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS users;
|
14
migrations_dev/000002_create_users_table.up.sql
Normal file
14
migrations_dev/000002_create_users_table.up.sql
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
added_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
|
||||||
|
login text UNIQUE NOT NULL,
|
||||||
|
twitchid text NOT NULL,
|
||||||
|
level integer,
|
||||||
|
location text,
|
||||||
|
lastfm_username text
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO users (added_at,login,twitchid,"level",location,lastfm_username) VALUES
|
||||||
|
(NOW(),'nouryxd','31437432',1000,'vilnius','nouryqt'),
|
||||||
|
(NOW(),'nourybot','596581605',1000,'',''),
|
||||||
|
(NOW(),'xnoury','197780373',500,'','');
|
1
migrations_dev/000003_create_commands_table.down.sql
Normal file
1
migrations_dev/000003_create_commands_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS commands;
|
16
migrations_dev/000003_create_commands_table.up.sql
Normal file
16
migrations_dev/000003_create_commands_table.up.sql
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS commands (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
name text UNIQUE NOT NULL,
|
||||||
|
text text NOT NULL,
|
||||||
|
category text NOT NULL,
|
||||||
|
level integer NOT NULL,
|
||||||
|
help text NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO commands (name,"text","category","level","help") VALUES
|
||||||
|
('repeat','xset r rate 175 75','default',0,'Command to set my keyboard repeat rate'),
|
||||||
|
('xset','xset r rate 175 75','default',0,'Command to set my keyboard repeat rate'),
|
||||||
|
('kek','lmao','default',0,'kek'),
|
||||||
|
('lmao','kek','default',0,'lmao'),
|
||||||
|
('dockerclean','docker system prune -a --volumes','default',0,'clean docker');
|
||||||
|
|
1
migrations_dev/000004_create_timers_table.down.sql
Normal file
1
migrations_dev/000004_create_timers_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS timers;
|
13
migrations_dev/000004_create_timers_table.up.sql
Normal file
13
migrations_dev/000004_create_timers_table.up.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS timers (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
name text NOT NULL,
|
||||||
|
identifier text NOT NULL,
|
||||||
|
text text NOT NULL,
|
||||||
|
channel text NOT NULL,
|
||||||
|
repeat text NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO timers (name,identifier,"text",channel,repeat) VALUES
|
||||||
|
('nourybot-5m','2ad01f96-05d3-444e-9dd6-524d397caa96','5m timer','nourybot','5m'),
|
||||||
|
('nourybot-10m','2ad01f96-05d3-444e-9dd6-524d397caa96','10m timer','nourybot','10m');
|
||||||
|
|
1
migrations_dev/000005_create_uploads_table.down.sql
Normal file
1
migrations_dev/000005_create_uploads_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS uploads;
|
17
migrations_dev/000005_create_uploads_table.up.sql
Normal file
17
migrations_dev/000005_create_uploads_table.up.sql
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS uploads (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
added_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
|
||||||
|
twitchlogin text NOT NULL,
|
||||||
|
twitchid text NOT NULL,
|
||||||
|
twitchmessage text NOT NULL,
|
||||||
|
twitchchannel text NOT NULL,
|
||||||
|
filehoster text NOT NULL,
|
||||||
|
downloadurl text,
|
||||||
|
uploadurl text,
|
||||||
|
identifier text
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO uploads (added_at,twitchlogin,twitchid,twitchchannel,twitchmessage,filehoster,downloadurl,uploadurl,identifier) VALUES
|
||||||
|
(NOW(),'nouryxd','31437432','nouryxd','()yaf https://www.youtube.com/watch?v=3rBFkwtaQbU','yaf','https://www.youtube.com/watch?v=3rBFkwtaQbU','https://i.yaf.li/LEFuX.webm','a4af2284-4e13-46fa-9896-393bb1771a9d'),
|
||||||
|
(NOW(),'uudelleenkytkeytynyt','465178364','nouryxd','()gofile https://www.youtube.com/watch?v=st6yupvNkVo','gofile','https://www.youtube.com/watch?v=st6yupvNkVo','https://gofile.io/d/PD1QNr','4ec952cc-42c0-41cd-9b07-637b4ec3c2b3');
|
||||||
|
|
1
migrations_dev/000006_create_command_logs_table.down.sql
Normal file
1
migrations_dev/000006_create_command_logs_table.down.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS commands_logs;
|
16
migrations_dev/000006_create_command_logs_table.up.sql
Normal file
16
migrations_dev/000006_create_command_logs_table.up.sql
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS commands_logs (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
added_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
|
||||||
|
twitch_login text NOT NULL,
|
||||||
|
twitch_id text NOT NULL,
|
||||||
|
twitch_channel text NOT NULL,
|
||||||
|
twitch_message text NOT NULL,
|
||||||
|
command_name text NOT NULL,
|
||||||
|
user_level integer NOT NULL,
|
||||||
|
identifier text NOT NULL,
|
||||||
|
raw_message text NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO commands_logs (added_at,twitch_login,twitch_id,twitch_channel,twitch_message,command_name,user_level,identifier,raw_message) VALUES
|
||||||
|
(NOW(),'nouryxd','31437432','nourybot','()weather Vilnius','weather',1000,'8441e97b-f622-4c42-b9b1-9bf22ba0d0bd','@badge-info=;badges=moderator/1,game-developer/1;color=#00F2FB;display-name=nouryxd;emotes=;first-msg=0;flags=;id=87d40f5c-8c7c-4105-9f57-b1a953bb42d0;mod=1;returning-chatter=0;room-id=596581605;subscriber=0;tmi-sent-ts=1696945359165;turbo=0;user-id=31437432;user-type=mod :nouryxd!nouryxd@nouryxd.tmi.twitch.tv PRIVMSG #nourybot :()weather Vilnius');
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
DROP TABLE IF EXISTS sent_messages_logs;
|
15
migrations_dev/000007_create_sent_messages_logs_table.up.sql
Normal file
15
migrations_dev/000007_create_sent_messages_logs_table.up.sql
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS sent_messages_logs (
|
||||||
|
id bigserial PRIMARY KEY,
|
||||||
|
added_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
|
||||||
|
twitch_channel text NOT NULL,
|
||||||
|
twitch_message text NOT NULL,
|
||||||
|
context_command_name text,
|
||||||
|
context_username text,
|
||||||
|
context_message text,
|
||||||
|
context_user_id text,
|
||||||
|
identifier text,
|
||||||
|
context_raw text
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO sent_messages_logs (added_at,twitch_channel,twitch_message,context_command_name,context_username,context_message,context_user_id,identifier,context_raw) VALUES
|
||||||
|
(NOW(),'nourybot','Weather for Vilnius, LT: Feels like: 8.07°C. Currently 8.65°C with a high of 9.29°C and a low of 8.49°C, humidity: 66%, wind: 1.54m/s.','weather','noury','()weather Vilnius','31437432','654f9761-b2d4-4975-a4fd-84c6ec7f2eb8','@badge-info=;badges=moderator/1,game-developer/1;color=#00F2FB;display-name=noury;emotes=;first-msg=0;flags=;id=357d94a4-024e-49ea-ab3d-d97286cd0492;mod=1;returning-chatter=0;room-id=596581605;subscriber=0;tmi-sent-ts=1696952295788;turbo=0;user-id=31437432;user-type=mod :nouryxd!nouryxd@nouryxd.tmi.twitch.tv PRIVMSG #nourybot :()weather Vilnius');
|
43
migrations_dev/README.md
Normal file
43
migrations_dev/README.md
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
# Migrations
|
||||||
|
|
||||||
|
Tool: [golang-migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)
|
||||||
|
|
||||||
|
## Create Database
|
||||||
|
```sql
|
||||||
|
$ sudo -u postgres psql
|
||||||
|
psql (14.3)
|
||||||
|
Type "help" for help.
|
||||||
|
|
||||||
|
postgres=# CREATE DATABASE nourybot;
|
||||||
|
CREATE DATABASE
|
||||||
|
postgres=# \c nourybot;
|
||||||
|
You are now connected to database "nourybot" as user "postgres".
|
||||||
|
nourybot=# CREATE ROLE username WITH LOGIN PASSWORD 'password';
|
||||||
|
CREATE ROLE
|
||||||
|
nourybot=# CREATE EXTENSION IF NOT EXISTS citext;
|
||||||
|
CREATE EXTENSION
|
||||||
|
nourybot=#
|
||||||
|
```
|
||||||
|
|
||||||
|
## Connect to Database
|
||||||
|
```sh
|
||||||
|
$ psql --host=localhost --dbname=nourybot --username=username
|
||||||
|
psql (14.3)
|
||||||
|
Type "help" for help.
|
||||||
|
|
||||||
|
nourybot=>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Apply migrations
|
||||||
|
```sh
|
||||||
|
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" up
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" down
|
||||||
|
```
|
||||||
|
|
||||||
|
## Fix Dirty database
|
||||||
|
```sh
|
||||||
|
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" force 1
|
||||||
|
```
|
Loading…
Reference in a new issue