45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/core/bin_helpers/scaffolding.rb', line 45
def create_tables
logger.write "Creating tables..", :bright
logger.write " users", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS users (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
psid varchar(50),
platform varchar(50),
psid_from_post_comment varchar(50),
page_id varchar(50),
name varchar(55),
first_name varchar(55),
last_name varchar(55),
timezone varchar(10),
locale varchar(5),
last_usage_at datetime,
created_at datetime,
updated_at datetime,
context varchar(120) DEFAULT NULL,
context_params text,
session_vars text,
last_message_read boolean default false,
PRIMARY KEY (id),
UNIQUE KEY psid (psid),
UNIQUE KEY token (psid_from_post_comment),
KEY(page_id),
KEY(platform)
) ENGINE=MyISAM
})
logger.write " kogno_sequences", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_sequences(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
user_id int unsigned,
stage varchar(60),
context varchar(60),
last_executed int default 0,
last_hit_at datetime,
execution_time datetime default NULL,
created_at datetime,
updated_at datetime,
primary key(id),
unique key user_context(user_id, context)
) ENGINE=MyISAM
})
logger.write " kogno_chat_logs", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_chat_logs (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
user_id int(10) unsigned DEFAULT NULL,
message_type varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
body text COLLATE utf8mb4_general_ci,
context varchar(120) COLLATE utf8mb4_general_ci DEFAULT NULL,
message varchar(1024) COLLATE utf8mb4_general_ci DEFAULT NULL,
payload varchar(120) COLLATE utf8mb4_general_ci DEFAULT NULL,
payload_params varchar(1024) COLLATE utf8mb4_general_ci DEFAULT NULL,
nlp_entities text COLLATE utf8mb4_general_ci,
user_vars text COLLATE utf8mb4_general_ci,
response text,
new_user boolean default false,
processed int(1) unsigned DEFAULT 0,
scheduled boolean default false,
created_at datetime DEFAULT NULL,
updated_at datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY user_id (user_id)
) ENGINE=MyISAM
})
logger.write " kogno_scheduled_messages", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_scheduled_messages(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
user_id int(10) unsigned DEFAULT NULL,
tag varchar(24) default null,
messages text,
send_at datetime,
created_at datetime,
updated_at datetime,
PRIMARY KEY (id),
KEY user_id (user_id),
KEY tag (tag)
) ENGINE=MyISAM
})
logger.write " kogno_matched_messages", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_matched_messages (
id int(11) unsigned primary key auto_increment,
user_id int(11) unsigned not null,
platform_message_id int(11) unsigned default 0,
created_at datetime,
updated_at datetime,
key(user_id),
key(platform_message_id)
) ENGINE=MyISAM
})
logger.write " kogno_telegram_chat_groups", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_telegram_chat_groups (
id int(11) unsigned primary key auto_increment,
chat_id bigint not null,
title varchar(256),
kind enum('group','supergroup','channel'),
membership boolean,
perms varchar(1024),
inviter_user_id int unsigned not null,
created_at datetime,
updated_at datetime,
unique key(chat_id)
) ENGINE=MyISAM
})
logger.write " kogno_long_payloads", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_long_payloads(
id int(11) unsigned primary key auto_increment,
token varchar(32),
payload varchar(64),
params text,
unique key token(token),
created_at datetime,
updated_at datetime
) ENGINE=MyISAM
})
logger.write " kogno_messenger_recurring_notifications", :green
ActiveRecord::Base.connection.execute(%{
CREATE TABLE IF NOT EXISTS kogno_messenger_recurring_notifications(
id int unsigned auto_increment primary key,
user_id int unsigned,
token varchar(64),
frecuency varchar(32),
expires_at datetime,
token_status varchar(32),
timezone varchar(16),
active boolean,
key(user_id),
key(expires_at),
created_at datetime,
updated_at datetime
) ENGINE=MyISAM
})
ActiveRecord::Base.connection.execute("ALTER DATABASE #{ActiveRecord::Base.connection.current_database} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci")
ActiveRecord::Base.connection.execute("ALTER TABLE users CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
ActiveRecord::Base.connection.execute("ALTER TABLE users MODIFY session_vars text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
ActiveRecord::Base.connection.execute("ALTER TABLE kogno_scheduled_messages MODIFY messages text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
end
|