Thus the leftmost group varies the fastest (10 times per microsecond). MySQL’s UUID() uses version 1, which implies, as explained in paragraph 4.1.2 of the RFC, that the three leftmost dash-separated groups are a 8-byte timestamp: leftmost group is the low four bytes of the timestamp second group is the middle two bytes, third group is the high (most significant) two bytes of the timestamp. They exist in several versions, and different sources can generate different versions. To understand that, we need to learn more about UUIDs. A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. However, if we have a choice, as the binary form is shorter, it looks more logical to index it, not the text form – the index will be smaller and thus faster to traverse, faster to backup…įinally, there is the question of how to smartly re-arrange bytes in the binary form. That is a new feature introduced in MySQL 5.7.8. LANGUAGE SQL DETERMINISTIC CONTAINS SQL SQL SECURITY INVOKER 将 UUID_TO_BIN()函数添加到 MySQL 数据库: DELIMITER //ĬREATE FUNCTION UUID_TO_BIN(string_uuid BINARY(36), swap_flag INT) T.binary :id, limit: 16, primary_key: true, null: false 样本迁移 class CreateUserProfiles < ActiveRecord::MigrationĬreate_table :user_profiles, id: false do |t| 应用程序/模型/应用程序_record.rb # ApplicationRecord (new parent of all models in Rails 5)Ĭlass ApplicationRecord < ActiveRecord::Base Raise TypeError, 'Expecting only 36 character UUID strings as primary keys' SimpleUUID::UUID.new( uuid_binary_string ).to_guidĪrray_binary_ids = ids.each_with_object( ) do |id, array| Uuid_string_without_hyphens.rjust(32, '0').gsub(/^(."ĪpplicationRecord.format_uuid_with_hyphens( uuid_string_without_hyphens ) Self || (id.present? ApplicationRecord.format_uuid_with_hyphens( id.unpack('H*').first ).upcase : nil)ĭef format_uuid_with_hyphens( uuid_string_without_hyphens ) Uuid_binary = ApplicationRecord.id_binary( uuid_string ) Uuid_string = ApplicationRecord.rearrange_time_of_uuid( uuid_object.to_guid ) Mysql2::Error: You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'uuid PRIMARY KEY, `name` varchar(255), `username` varchar(255), `password_digest' at line 1 If you already have a rails project, change the adapter in the config/database.yml file to mysql and make sure you specify a valid username and password, and optionally, a socket: development: adapter: mysql2 database: dbnamedev username: koploper password: host: localhost socket: /tmp/mysql. home/zetacu/.rbenv/versions/2.4.0/bin/bundle:22:in `'ĪctiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'uuid PRIMARY KEY, `name` varchar(255), `username` varchar(255), `password_digest' at line 1: CREATE TABLE `users` (`id` uuid PRIMARY KEY, `name` varchar(255), `username` varchar(255), `password_digest` varchar(255), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB Mysql2::Error: You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'uuid PRIMARY KEY, `name` varchar(255), `username` varchar(255), `password_digest' at line 1: CREATE TABLE `users` (`id` uuid PRIMARY KEY, `name` varchar(255), `username` varchar(255), `password_digest` varchar(255), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB StandardError: An error has occurred, all later migrations canceled:
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |