Why do I have an empty “Searchable attributes” after import with 'algolia/scout-extended'? - algolia

In a Laravel 9 application, I have algolia/scout-extended 2.0.
Running on my local OS command
php artisan scout:optimize
I got several files like config/scout-search-pages.php, and I modified one of them:
'searchableAttributes' => [
'page_title',
'page_slug',
'page_content',
'page_content_shortly',
'page_author_name',
'page_author_email',
'page_price',
'page_categories',
'page_created_at',
],
'customRanking' => ['asc(page_price)', 'desc(page_created_at)'],
And clearing the cache I run an import and after that I see a set of rows/columns I expected: https://prnt.sc/Ew0BdaH3dvON
But on the “Configuration” tab I see an empty “Searchable attributes” list, and I have to add fields manually.
I expected that these fields must be filled automatically from “searchableAttributes” option,
but not.
After I added more columns at “Add a Searchable Attribute” I see “unordered/unordered” option for fields.
How does it work and which option do I have to select?
The source table on MySQL 8 side has this structure:
CREATE TABLE `search_pages` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`page_title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`page_slug` varchar(260) COLLATE utf8mb4_unicode_ci NOT NULL,
`page_content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
`page_content_shortly` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`page_author_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`page_author_email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`page_price` decimal(9,2) NOT NULL DEFAULT '0.00',
`page_categories` json DEFAULT NULL,
`page_created_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `search_pages_page_slug_unique` (`page_slug`),
KEY `search_pages_page_author_name_page_title_index` (`page_author_name`,`page_title`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Related

Mysql FK referenced column not show results

I have problem with creating FK. Am checking and checking and i cant see what is wrong.
I have product, sites and product_site_ref tables.
When i try to add FK to table product_site_ref i cant choose referenced column. Check screenshot.
Relation table
CREATE TABLE `product_site_ref` (
`id` bigint(20) NOT NULL,
`product_id` bigint(20) unsigned NOT NULL,
`site_id` bigint(20) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `product_index` (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Product table
CREATE TABLE `product` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(125) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`name` varchar(225) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Site table
CREATE TABLE `site` (
`id` bigint(20) NOT NULL,
`name` varchar(245) DEFAULT NULL,
`url` varchar(45) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Note: table proizvod on screenshot is product. I just translate for your goys to better understand. All is the some

postgresql cannot insert data to newly added column

In postgresql I have a table which I need to add a new column. the original table ddl is belowing:
CREATE TABLE survey.survey_response (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
survey_id uuid NOT NULL,
survey_question_id uuid NULL,
user_id varchar(256) NULL,
device_id varchar(256) NULL,
user_country varchar(100) NULL,
client_type varchar(100) NULL,
product_version varchar(100) NULL,
answer text NULL,
response_date timestamptz NOT NULL DEFAULT now(),
survey_category varchar(100) NULL,
tags varchar(250) NULL,
tracking_id uuid NULL,
CONSTRAINT survey_response_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
) ;
Then I alter the table to add a new column:
alter table survey.survey_response add column system_tags varchar(30) ;
But after that I found my instert statement cannot make change to this new column, for all the original columns it works fine:
INSERT INTO survey.survey_response
(id, survey_id, user_id, tags, system_tags)
VALUES(uuid_generate_v4(), uuid_generate_v4(),'1123','dsfsd', 'dsfsd');
select * from survey.survey_response where user_id = '1123';
The "tags" columns contains inserted value, however, system_tags keeps null.
I tested the above scenario in my local postgreSQL 9.6, any ideas about this strange behavior? Thanks a lot
-----------------update----------
I found this survey.survey_response table has been partitioning based on month, So my inserted record will also be displayed in survey.survey_response_y2017m12. but the new system_tags column is also NULL
CREATE TABLE survey.survey_response_y2017m12 (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
survey_id uuid NOT NULL,
survey_question_id uuid NULL,
user_id varchar(256) NULL,
device_id varchar(256) NULL,
user_country varchar(100) NULL,
client_type varchar(100) NULL,
product_version varchar(100) NULL,
answer text NULL,
response_date timestamptz NOT NULL DEFAULT now(),
survey_category varchar(100) NULL,
tags varchar(250) NULL,
tracking_id uuid NULL,
system_tags varchar(30) NULL,
CONSTRAINT survey_response_y2017m12_response_date_check CHECK (((response_date >= '2017-12-01'::date) AND (response_date < '2018-01-01'::date)))
)
INHERITS (survey.survey_response)
WITH (
OIDS=FALSE
) ;
If I run the same scenario in a non-partition table then the insert works fine.
So do I need any special settings for alter table for partition table?
Old thread but you need to drop and create again the RULE to fix the issue.

Error while creating table in PostgreSQL while migrating from MySQL

I am Migrating my database from MySQL to PostgreSQL.While creating table I got an error which I can't resolve.My MySQL Query is like this.
MYSQL Query
CREATE TABLE `configuration` (
`Name` varchar(300) NOT NULL,
`Value` varchar(300) default NULL,
`CType` char(1) default NULL,
`Size` int(11) default NULL,
`CGroup` varchar(50) default NULL,
`RestartReq` char(1) NOT NULL default 'Y',
`Display` char(1) NOT NULL default 'Y',
PRIMARY KEY (`Name`),
KEY `CType` (`CType`),
CONSTRAINT `configuration_ibfk_1` FOREIGN KEY (`CType`) REFERENCES `conftype` (`CType`)
)ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin`
PostgreSQL Query
CREATE TABLE configuration (
Name varchar(300) PRIMARY KEY,
Value varchar(300) default NULL,
CType char(1) default NULL,
Size integer default NULL,
CGroup varchar(50) default NULL,
RestartReq char(1) NOT NULL default 'Y',
Display char(1) NOT NULL default 'Y',
KEY CType (CType),
CONSTRAINT `configuration_ibfk_1` FOREIGN KEY (CType) REFERENCES conftype (CType)
)
Running File with
psql -h localhost -p 5432 -U postgres -f ps.sql testdb
Error getting
psql:ps.sql:40: ERROR: syntax error at or near "(" at character 287
psql:ps.sql:40: LINE 9: KEY CType ('CType'),
From the MySQL documentation:
KEY is normally a synonym for INDEX.
In PostgreSQL you have to create the index separately from the table:
CREATE TABLE configuration (
name varchar(300) PRIMARY KEY,
value varchar(300),
ctype char(1),
size integer,
cgroup varchar(50),
restartreq boolean NOT NULL DEFAULT true,
display boolean NOT NULL DEFAULT true,
CONSTRAINT configuration_ibfk_1 FOREIGN KEY (ctype) REFERENCES conftype (ctype)
);
CREATE INDEX conf_key ON configuration(ctype);
A few other points:
PostgreSQL identifiers (mainly table and column names) are case-insensitive except when double-quoted. The standard approach is to put identifiers in lower case and keywords in upper case.
Using a varchar(300) as a PRIMARY KEY is usually not a good idea for performance reasons. Consider adding a serial type.
The default value of a column is NULL when nothing is specified, so no need to specify DEFAULT NULL.
PostgreSQL has a boolean data type.

MariaDB -> Error: 1062, Duplicate entry '0' for key 'PRIMARY'

So I'm trying to import geoipcity data into my table like so:
mysqlimport --fields-terminated-by="," --fields-optionally-enclosed-by="\"" --lines-terminated-by="\n" --host=localhost --user=user --password=passw database_name /var/www/html/GeoLiteCity_20150804/geoip_city.csv
But I keep getting the error.
Error: 1062, Duplicate entry '0' for key 'PRIMARY'
Now I saw the question relating to this error has been asked before but I simply don't understand the answers. I'm not that much of a guru, I'm a volunteer IT guy and I have no idea how to resolve this. I tried using this instead:
LOAD DATA LOCAL INFILE '/var/www/html/GeoLiteCity_20150804/geoip_city_ips.csv' INTO TABLE geoip_city_ips;
But then it would simply fill the table with "NULL" in all the columns.
My table structure:
--
-- Table structure for table geoip_city
CREATE TABLE IF NOT EXISTS geoip_city (
locID int(10) unsigned NOT NULL,
country char(8) COLLATE utf8_unicode_ci DEFAULT NULL,
region char(8) COLLATE utf8_unicode_ci DEFAULT NULL,
city varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
postalCode char(32) CHARACTER SET latin1 DEFAULT NULL,
latitude double DEFAULT NULL,
longitude double DEFAULT NULL,
dmaCode char(8) CHARACTER SET latin1 DEFAULT NULL,
areaCode char(8) CHARACTER SET latin1 DEFAULT NULL,
PRIMARY KEY (locID),
KEY Index_Country (country)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED;
Some lines from geoip_city:
717543,"MX","32","Zacatecas","98051",22.7833,-102.5833,,
717544,"MX","26","Cananea","84624",30.9500,-110.3000,,
717545,"MX","07","Valles","79040",26.6667,-100.6833,,
717546,"DE","02","Berg","88276",47.9667,11.3500,,
717547,"DE","09","Schwalbach","65824",49.3000,6.8167,,
717548,"RU","48","Moscow","129233",55.7522,37.6156,,
717549,"MX","28","Reynosa","88520",26.0833,-98.2833,,
717550,"PH","40","San Jose","5100",12.4558,121.0459,,
717551,"ES","56","Tarragona","43070",41.1167,1.2500,,
717552,"GB","Z6","","",51.9167,-0.6500,,
Well I'm guessing this is a MariaDB issue then since nobody replied? Would going back to Debian solve the issue?

Multi-table query - get friend updates

SELECT M.msg_id, M.uid_fk, M.message, M.created,
U.fname, U.lname, M.uploads
FROM messages M, users_friends F, users U
WHERE M.uid_fk=F.friendID
and F.userID = '5'
and status='2'
Building a facebook-like wall and want to grab messages(updates) from friends.
The query above returns an empty set, even though I've made sure there are messages from user 5 in the table.
Schema:
CREATE TABLE IF NOT EXISTS `messages` (
`msg_id` int(11) NOT NULL AUTO_INCREMENT,
`message` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
`uid_fk` int(11) DEFAULT NULL,
`ip` varchar(30) DEFAULT NULL,
`created` int(11) DEFAULT '1269249260',
`uploads` varchar(30) DEFAULT NULL,
PRIMARY KEY (`msg_id`),
KEY `uid_fk` (`uid_fk`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=263 ;
CREATE TABLE IF NOT EXISTS `users` (
`fname` varchar(15) NOT NULL,
`lname` varchar(15) NOT NULL,
`userID` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(23) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(32) NOT NULL,
`DOB` date DEFAULT NULL,
`sex` varchar(1) DEFAULT NULL,
`about` text NOT NULL,
`location` varchar(20) DEFAULT NULL,
`last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_level` int(11) NOT NULL DEFAULT '0',
`profile_image` varchar(200) NOT NULL,
`profile_image_small` varchar(200) NOT NULL,
PRIMARY KEY (`userID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
CREATE TABLE IF NOT EXISTS `users_friends` (
`userID` int(11) NOT NULL,
`friendID` int(11) NOT NULL,
`status` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`userID`,`friendID`),
KEY `fk_users_has_friends_users1` (`userID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
You are single quoting your INT values in the WHERE clause → '5' & '2'.
Also, try JOINs.
SELECT M.msg_id,
M.uid_fk,
M.message,
M.created,
U.fname,
U.lname,
M.uploads
FROM messages M
INNER JOIN users_friends F ON F.friendID = M.uid_fk
AND F.userID = 5
AND F.status = 2
INNER JOIN users U ON U.userID = F.friendID;